Wraps claude -p CLI to provide OpenAI-compatible API for OpenCode. Supports tool calling via --allowedTools and --permission-mode bypassPermissions.
50 lines
1.5 KiB
Markdown
50 lines
1.5 KiB
Markdown
# opencode-anthropic-proxy
|
|
|
|
A local proxy server that wraps `claude -p` (Claude Code CLI) to expose an OpenAI-compatible API endpoint for use with OpenCode.
|
|
|
|
## How it works
|
|
|
|
OpenCode communicates with AI providers using the OpenAI API format. This proxy listens on `localhost:3000`, receives OpenAI-format requests, translates them into `claude -p` CLI invocations, and returns the responses.
|
|
|
|
Tool calls (bash, read, write, edit, etc.) are passed through using `--allowedTools` and `--permission-mode bypassPermissions`, allowing Claude to execute tools internally.
|
|
|
|
## Setup
|
|
|
|
### 1. Install the systemd user service
|
|
|
|
```bash
|
|
cp claude-proxy.service ~/.config/systemd/user/
|
|
systemctl --user daemon-reload
|
|
systemctl --user enable --now claude-proxy.service
|
|
```
|
|
|
|
### 2. Configure OpenCode
|
|
|
|
In your `opencode.json`, add a provider:
|
|
|
|
```json
|
|
"claude-code": {
|
|
"npm": "@ai-sdk/openai-compatible",
|
|
"name": "Claude Code (proxy)",
|
|
"options": {
|
|
"baseURL": "http://localhost:3000/v1"
|
|
},
|
|
"models": {
|
|
"claude-opus-4-7": { "name": "Claude Opus 4.7" },
|
|
"claude-sonnet-4-6": { "name": "Claude Sonnet 4.6" },
|
|
"claude-haiku-4-5": { "name": "Claude Haiku 4.5" }
|
|
}
|
|
}
|
|
```
|
|
|
|
### 3. Requirements
|
|
|
|
- `claude` CLI installed at `~/.local/bin/claude` (Claude Code)
|
|
- Node.js 18+
|
|
|
|
## Notes
|
|
|
|
- The proxy uses `--permission-mode bypassPermissions` — tools execute without approval prompts
|
|
- Model names with provider prefix (e.g., `claude-code/claude-sonnet-4-6`) are handled automatically
|
|
- Supports both streaming and non-streaming responses
|