anthropic-proxy

Reverse proxy that lets OpenCode (and similar tools) use a Claude subscription instead of an API key.

Prerequisites

  • Go 1.26+
  • Claude Code CLI — installed and logged in (claude auth login). The proxy reads the OAuth token from ~/.claude/.credentials.json.

Optional: Nix flake for dev shell (nix develop).

Setup

cp config.example.yaml config.yaml

Edit config.yaml:

  • api_keys — key(s) your clients use to authenticate with the proxy
  • claude_credentials — path to your Claude credentials file
  • claude_binary — path to claude binary (used on startup to capture request fingerprint)

Build and run

go build -o anthropic-proxy .
./anthropic-proxy

Usage with OpenCode

export ANTHROPIC_API_KEY=your-proxy-api-key
export ANTHROPIC_BASE_URL=http://localhost:8082
opencode

Endpoints

Method Path Description
POST /v1/messages Anthropic messages API (proxied)
POST /messages Same, without /v1 prefix
GET /healthz Health check
POST /reload Hot-reload config.yaml

Request sanitization

The sanitize section in config renames tool names and replaces strings in system prompts before forwarding to Anthropic. Responses are de-sanitized before returning to the client.

See config.example.yaml for the default rules.

Reload after editing config:

curl -X POST localhost:8082/reload
S
Description
No description provided
Readme 7.7 MiB
Languages
Go 99.3%
Nix 0.7%