by betri28
A python proxy that lets you use OpenCode Go subscription with Claude Code
# Add to your Claude Code skills
git clone https://github.com/betri28/opencode-proxyGuides for using ai agents skills like opencode-proxy.
A python proxy that lets you use OpenCode Go subscription with Claude Code.
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.
pip install -r requirements.txt
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/.
Copy .env.example to .env and edit:
cp .env.example .env
Edit values in .env:
| Variable | Description | Default |
|----------|-------------|---------|
| OPENCODE_PROXY | Proxy server | | | `OPENCODE_API_KEY` | API key for OpenCode | |
| OPUS_MAP_MODEL | Model for opus route | kimi-k2.6 |
| SONNET_MAP_MODEL | Model for sonnet route | glm-5.1 |
| HAIKU_MAP_MODEL | Model for haiku route | minimax-m2.5 |
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-key
ANTHROPIC_AUTH_TOKEN=fake
ANTHROPIC_BASE_URL=http://localhost:4000
Note: The proxy server must be running (python opencode.py) before using Claude Code.
python opencode.py
Server will start:
The web interface has 2 tabs:
| Method | Path | Description |
|--------|------|-------------|
| POST | /v1/messages | Proxy Anthropic format |
| POST | /anthropic/v1/messages | Proxy Anthropic format |
| POST | /v1/messages/count_tokens | Estimate token count for a request |
| GET | /health | Health check |
| GET | /api/stats | Token usage stats (supports from_date, to_date) |
| GET | /api/logs | Terminal logs |
| GET | /api/history | Request history from DB (supports from_date, to_date) |
| DELETE | /api/history | Delete history (before or all=true) |
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)j/↓: Scroll down logk/↑: Scroll up logg: Go to topG: Go to bottomCtrl+C: Exitopencode.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
No comments yet. Be the first to share your thoughts!