claude-code-proxy
Note on Anthropic ToS: On Feb 19, 2026, Anthropic updated their Consumer ToS to ban extracting OAuth tokens for use in third-party tools. This proxy does not extract or forward tokens — it spawns
claude --printas a subprocess, which is an officially supported programmatic use pattern (same as scripting, piping, or cron jobs). The CLI manages its own authentication internally. This tool is intended for personal, single-user, localhost automation only.
OpenAI-compatible API proxy for Claude Code CLI. Uses your authenticated Claude Code (Max subscription) for inference — no API keys needed.
Why
Claude Code CLI is powerful but only works in the terminal. This proxy exposes it as an OpenAI-compatible HTTP API, enabling:
- OpenClaw to use Claude as its LLM backend
- Cursor, Continue, and other AI coding tools to connect to Claude Code
- Any OpenAI-compatible client to use your Max subscription
Architecture
Client (OpenClaw/Cursor/etc.)
│
▼ POST /v1/chat/completions or /v1/responses
claude-code-proxy (this binary)
│
▼ claude --print --model opus --output-format stream-json
Claude Code CLI (uses Max subscription)
│
▼
Anthropic API
Endpoints
| Method | Path | Description |
|---|---|---|
GET |
/health |
Health check |
GET |
/v1/models |
List available models |
POST |
/v1/chat/completions |
Chat Completions API (streaming + non-streaming) |
POST |
/v1/responses |
Responses API (streaming + non-streaming) |
All endpoints also available without the /v1 prefix.
Usage
PROXY_API_KEY=your-secret
Then point your client to http://localhost:8080/v1.
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
PROXY_API_KEY |
Yes | — | Bearer token for proxy authentication |
PORT |
No | 8080 |
Listen port |
CLAUDE_MODEL |
No | sonnet |
Default model (haiku, sonnet, opus) |
RUST_LOG |
No | claude_proxy=info |
Log level |
Examples
# Non-streaming
# Streaming (SSE)
# Responses API
OpenClaw Configuration
Features
- Both Chat Completions and Responses API formats
- Full SSE streaming on all endpoints
- Content blocks normalization (handles
[{"type":"text","text":"..."}]and plain strings) - Constant-time auth comparison (
subtlecrate) - 1MB request body limit
kill_on_dropchild process management (no zombies)- Proper UTF-8 validation on CLI output
- Model normalization (
claude-sonnet-4.5→sonnet)
Development
# Enter devenv shell
# Build
# Run
# Test (44 tests including property-based)
NixOS
This proxy is designed to run as a systemd user service via mynixos:
my.ai.claudeProxy = {
enable = true;
model = "opus";
};
License
Creative Commons Attribution-NonCommercial-ShareAlike (CC BY-NC-SA) 4.0 International
See LICENSE for details.