Initial commit: OpenCode Anthropic proxy server
Wraps claude -p CLI to provide OpenAI-compatible API for OpenCode. Supports tool calling via --allowedTools and --permission-mode bypassPermissions.
This commit is contained in:
parent
e3437d40e4
commit
a85be6a8bb
35
README.md
35
README.md
@ -1,29 +1,26 @@
|
|||||||
# OpenCode Anthropic Proxy
|
# opencode-anthropic-proxy
|
||||||
|
|
||||||
A local proxy server that wraps `claude -p` (Claude Code CLI) to expose an OpenAI-compatible API for use with OpenCode.
|
A local proxy server that wraps `claude -p` (Claude Code CLI) to expose an OpenAI-compatible API endpoint for use with OpenCode.
|
||||||
|
|
||||||
## Overview
|
## How it works
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
## Files
|
Tool calls (bash, read, write, edit, etc.) are passed through using `--allowedTools` and `--permission-mode bypassPermissions`, allowing Claude to execute tools internally.
|
||||||
|
|
||||||
- `claude-proxy.mjs` — The proxy server (Node.js, no external deps)
|
|
||||||
- `claude-proxy.service` — systemd user service for automatic startup
|
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Copy `claude-proxy.mjs` to `~/.config/opencode/claude-proxy.mjs`
|
### 1. Install the systemd user service
|
||||||
2. Copy `claude-proxy.service` to `~/.config/systemd/user/claude-proxy.service`
|
|
||||||
3. Enable and start the service:
|
|
||||||
```bash
|
```bash
|
||||||
|
cp claude-proxy.service ~/.config/systemd/user/
|
||||||
systemctl --user daemon-reload
|
systemctl --user daemon-reload
|
||||||
systemctl --user enable --now claude-proxy
|
systemctl --user enable --now claude-proxy.service
|
||||||
```
|
```
|
||||||
|
|
||||||
## OpenCode Configuration
|
### 2. Configure OpenCode
|
||||||
|
|
||||||
In your `opencode.json`, add the `claude-code` provider:
|
In your `opencode.json`, add a provider:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"claude-code": {
|
"claude-code": {
|
||||||
@ -40,7 +37,13 @@ In your `opencode.json`, add the `claude-code` provider:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Requirements
|
### 3. Requirements
|
||||||
|
|
||||||
- Claude Code CLI installed at `~/.local/bin/claude`
|
- `claude` CLI installed at `~/.local/bin/claude` (Claude Code)
|
||||||
- Node.js 18+
|
- 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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user