Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code Zen Proxy

An Anthropic-compatible local proxy server designed to route Claude Code CLI requests to OpenCode Zen or any other OpenAI-compatible chat completions backend (e.g., DeepSeek, OpenRouter, local Ollama).

This proxy allows you to run the feature-rich Claude Code CLI using alternative, affordable, or self-hosted models, fully supporting streaming, tool calling, and DeepSeek thinking/reasoning blocks.


Features

  • Protocol Translation: Seamlessly converts Anthropic messages API payloads (input schemas, messages, system prompts) to OpenAI-compatible Chat Completions requests.
  • Bi-Directional Tool Calling: Automatically translates tool definition schemas, tool invocations, and tool results between Anthropic and OpenAI formats.
  • SSE Stream Relaying: Converts upstream OpenAI chunk streams into Anthropic-compatible Server-Sent Event (SSE) streams in real-time.
  • DeepSeek Reasoning Blocks: Maps reasoning and thinking outputs (reasoning_content) directly to Anthropic's <thinking> format, preserving the internal reasoning steps of reasoning models.
  • Local Logs Dashboard: Provides a lightweight endpoint (/logs) to trace proxy requests and performance.

Prerequisites

  1. Node.js: Version 18 or higher.
  2. Claude Code CLI: Installed globally via npm:
    npm install -g @anthropic-ai/claude-code

Installation & Setup

1. Clone & Install Dependencies

Navigate to the directory and install dependencies:

npm install

2. Configure Environment Variables

Copy the template configuration file:

copy .env.zen.example .env.zen

(On macOS/Linux, run: cp .env.zen.example .env.zen)

Open .env.zen in your editor and configure the keys:

UPSTREAM_API_KEY=your_actual_upstream_api_key_here
UPSTREAM_MODEL=deepseek-v4-flash-free
UPSTREAM_CHAT_COMPLETIONS_URL=https://opencode.ai/zen/v1/chat/completions

3. Start the Proxy Server

Launch the proxy:

npm start

The server will start by default at http://127.0.0.1:4040.


Running Claude Code with the Proxy

To redirect the Claude Code CLI to use your local proxy, you must run it with specific environment variables set.

Windows (CMD)

set ANTHROPIC_BASE_URL=http://127.0.0.1:4040
set ANTHROPIC_API_KEY=claude-zen-local-key
set ANTHROPIC_MODEL=claude-code-proxy
set ENABLE_TOOL_SEARCH=true
claude

Windows (PowerShell)

$env:ANTHROPIC_BASE_URL="http://127.0.0.1:4040"
$env:ANTHROPIC_API_KEY="claude-zen-local-key"
$env:ANTHROPIC_MODEL="claude-code-proxy"
$env:ENABLE_TOOL_SEARCH="true"
claude

macOS & Linux (Bash/Zsh)

export ANTHROPIC_BASE_URL="http://127.0.0.1:4040"
export ANTHROPIC_API_KEY="claude-zen-local-key"
export ANTHROPIC_MODEL="claude-code-proxy"
export ENABLE_TOOL_SEARCH="true"
claude

Resuming a Previous Session

To resume your previous Claude session while pointing to the proxy, add the -r flag:

claude -r

Configuration Reference

The following environment variables can be customized in .env.zen:

Variable Description Default
UPSTREAM_API_KEY The API Key for your upstream provider. Required
UPSTREAM_MODEL The model name passed to the upstream completions API. deepseek-v4-flash-free
UPSTREAM_CHAT_COMPLETIONS_URL Endpoint of the upstream completions API. https://opencode.ai/zen/v1/chat/completions
ANTHROPIC_MODEL_ALIAS The name of the model alias Claude Code will request. claude-code-proxy
PROXY_API_KEY Key needed to authorize requests made to the proxy. claude-zen-local-key
DEEPSEEK_THINKING_TYPE Controls whether DeepSeek thinking is enabled or disabled. enabled
UPSTREAM_REASONING_EFFORT Reasoning effort level (none, low, medium, high, xhigh). xhigh
HOST Network interface to bind the proxy server to. 127.0.0.1
PORT Local port for the proxy server. 4040

Debugging & Diagnostics

You can inspect the API requests forwarded through the proxy by navigating to:

http://127.0.0.1:4040/logs

This endpoint displays a JSON payload listing recent completions traffic, processing metadata, and stream states.

About

Local proxy for using Claude Code CLI with OpenAI-compatible models.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages