Files
anthropic-proxy/README.md
T
2026-04-09 23:06:17 +02:00

59 lines
1.5 KiB
Markdown

# 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](https://nixos.org/) 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
- `auth_dir` — optional, directory with additional OAuth credential JSON files
- `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
```