Skip to content

Repository files navigation

OpenCode-Proxy

A python proxy that lets you use OpenCode Go subscription with Claude Code.

image

Key Features

  • Anthropic-compatible Proxy — Acts as a drop-in replacement for the Anthropic API. Claude Code sends requests to the proxy, which translates and forwards them to the OpenCode Go upstream, then converts the response back to Anthropic format seamlessly.

  • Extended Thinking & Effort — Forwards thinking and budget_tokens parameters as-is to the upstream model. Also supports effort (low / medium / high) for models that use effort-based reasoning. Availability depends on the model.

  • Image & Document — Passes image, PDF, DOCX, and XLSX content blocks through to the upstream model. Whether these are actually processed depends on model support.

  • Web Search — Forwards web search tool calls to models that natively support it. Results are translated back to Anthropic's tool_result format for Claude Code compatibility.

Requirements

  • Python 3.11+

Installation

pip install -r requirements.txt

Docker

Build and run with Docker Compose:

docker compose up --build

Or with plain Docker:

docker build -t opencode-proxy .
docker run --rm -p 4000:4000 -p 8082:8082 --env-file .env -v ${PWD}/logs:/app/logs opencode-proxy

The container exposes both the API on 4000 and the dashboard on 8082, and persists the SQLite history database under logs/.

Configuration

Copy .env.example to .env and edit:

cp .env.example .env

Edit values in .env:

VariableDescriptionDefault
OPENCODE_PROXYProxy server``
OPENCODE_API_KEYAPI key for OpenCode``
OPUS_MAP_MODELModel for opus routekimi-k2.6
SONNET_MAP_MODELModel for sonnet routeglm-5.1
HAIKU_MAP_MODELModel for haiku routeminimax-m2.5

Claude Code Configuration

To use this proxy with Claude Code, add these environment variables to your shell configuration:

export ANTHROPIC_API_KEY="fake-key"export ANTHROPIC_AUTH_TOKEN="fake"export ANTHROPIC_BASE_URL="http://localhost:4000"

Or add them to your .env file:

ANTHROPIC_API_KEY=fake-keyANTHROPIC_AUTH_TOKEN=fakeANTHROPIC_BASE_URL=http://localhost:4000

Note: The proxy server must be running (python opencode.py) before using Claude Code.

Running

python opencode.py

Server will start:

Web Dashboard

The web interface has 2 tabs:

Token Stats

  • Overview: Input, Output, Cache, Success, Failed, Avg Duration
  • Charts: Token Distribution, Token % by Model, Requests % by Model
  • Detailed table by model
image

Request History

  • Request logs with full info: time, model, duration, tokens, status
  • Filter by time: Today, 7 Days, 30 Days, Custom
  • Delete history: all or by date
image

Common Features

  • Dark/Light theme (Dark by default)
  • Auto-refresh every 5 seconds
  • Time filter shared across both tabs

API Endpoints

MethodPathDescription
POST/v1/messagesProxy Anthropic format
POST/anthropic/v1/messagesProxy Anthropic format
POST/v1/messages/count_tokensEstimate token count for a request
GET/healthHealth check
GET/api/statsToken usage stats (supports from_date, to_date)
GET/api/logsTerminal logs
GET/api/historyRequest history from DB (supports from_date, to_date)
DELETE/api/historyDelete history (before or all=true)

Advanced Configuration

For other settings, edit config/settings.py:

  • PORT: API port (default 4000)
  • WEB_PORT: Web UI port (default 8082)
  • MODELS: Models and endpoints list, including per-model capability flags (supports_vision, supports_pdf, supports_office, web_search_tool, thinking_style)

Keyboard shortcuts (Terminal)

  • j/: Scroll down log
  • k/: Scroll up log
  • g: Go to top
  • G: Go to bottom
  • Ctrl+C: Exit

Project Structure

opencode.py # Main FastAPI server
config/
__init__.py # Package exports
settings.py # Configuration (PROXY, API_KEY, MODELS, ROUTES)
dashboard/
__init__.py # Package exports
api.py # Dashboard API endpoints (stats, logs, history)
display.py # Rich terminal display (token table, log panel)
static/
index.html # Dashboard UI
styles.css # Styling (dark/light theme)
app.js # JavaScript
requirements.txt # Python dependencies
.env.example # Template environment configuration
.env # Environment configuration (gitignored)
.gitignore # Git ignore rules
logs/ # Runtime directory (auto-created)
requests.db # SQLite - request history

License

MIT

About

A python proxy that lets you use OpenCode Go subscription with Claude Code

Resources

Stars

56 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages