47 lines
1.3 KiB
Markdown

# OpenCode Anthropic Proxy
A local proxy server that wraps `claude -p` (Claude Code CLI) to expose an OpenAI-compatible API for use with OpenCode.
## Overview
This proxy allows OpenCode to use Anthropic models by bridging OpenCode's OpenAI-compatible API calls to the `claude -p` CLI, which is the officially supported method for third-party integrations per Anthropic's terms of use.
## Files
- `claude-proxy.mjs` — The proxy server (Node.js, no external deps)
- `claude-proxy.service` — systemd user service for automatic startup
## Setup
1. Copy `claude-proxy.mjs` to `~/.config/opencode/claude-proxy.mjs`
2. Copy `claude-proxy.service` to `~/.config/systemd/user/claude-proxy.service`
3. Enable and start the service:
```bash
systemctl --user daemon-reload
systemctl --user enable --now claude-proxy
```
## OpenCode Configuration
In your `opencode.json`, add the `claude-code` 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" }
}
}
```
## Requirements
- Claude Code CLI installed at `~/.local/bin/claude`
- Node.js 18+