open-claude-code-proxy
v1.1.5
Published
Local proxy that forwards API requests through the official Claude Code CLI
Maintainers
Readme
Open Claude Code Proxy
Route API requests through the official Claude Code client
What is this?
A local proxy server that forwards Anthropic API requests through the official Claude Code CLI. This allows you to use Claude in any app that supports the Anthropic API (like OpenCode, Cursor, etc.) while leveraging your existing Claude Code authentication.
Features
- Tool Compatibility: Automatic tool name mapping (Read→read, WebSearch→websearch_exa_*, etc.)
- Parameter Translation: Converts parameter names (file_path→filePath, old_string→oldString, etc.)
- Multi-turn Conversations: Full conversation history support including tool_use/tool_result
- Cache Optimization: Handles cache_control to avoid conflicts with Claude Code
- OpenCode Integration: Auto-configures OpenCode with backup support
How it works
Your App (OpenCode/Cursor/etc.)
↓ POST /v1/messages
localhost:12346 (This Proxy)
↓ Spawns `claude --print`
Claude Code CLI (Official Client)
↓ Uses your login session
Anthropic APIQuick Start
Option 1: Let an LLM Agent do it (Recommended)
Paste this into a fresh OpenCode/Cursor/Claude session:
Install and configure by following the instructions here https://raw.githubusercontent.com/lkyxuan/open-claude-code-proxy/main/INSTALL_GUIDE.mdOption 2: Install globally (Manual)
npm install -g open-claude-code-proxy
claude-local-proxyOption 3: Clone and run
git clone https://github.com/lkyxuan/open-claude-code-proxy.git
cd open-claude-code-proxy
node cli.jsPrerequisites
Install Claude Code CLI
npm install -g @anthropic-ai/claude-codeLogin to Claude Code
claude auth loginConfigure Claude Code environment (if using a relay service)
# Add to ~/.zshrc or ~/.bashrc export ANTHROPIC_BASE_URL="https://your-relay-service.com/v1" export ANTHROPIC_API_KEY="your-api-key" source ~/.zshrc
Port Configuration
The proxy supports flexible port configuration:
# Use command line argument
claude-local-proxy --port 8080
claude-local-proxy -p 8080
# Or use environment variable
PORT=8080 claude-local-proxy
# Or let it use saved config (~/.claude-proxy/config.json)
claude-local-proxyPort Priority: CLI argument > Config file > Environment variable > Default (12346)
On first run, you'll be prompted to customize the port. Your choice is saved for future use.
OpenCode Auto-Configuration
The proxy can automatically configure OpenCode for you:
- Detects OpenCode config at
~/.config/opencode/opencode.json - Updates
provider.anthropic.options.baseURLto match your proxy port - Creates automatic backups before modifying (keeps last 3)
- Prompts before making changes (use
--skip-opencodeto skip)
# Auto-configure OpenCode
claude-local-proxy -p 8080
# Skip OpenCode configuration
claude-local-proxy -p 8080 --skip-opencodeConfigure Your Client
Point your app to the local proxy:
{
"baseURL": "http://localhost:12346",
"apiKey": "any-string-works"
}Note: The API key can be any string - authentication is handled by your Claude Code session.
Commands
This package provides two commands:
claude-local-proxy - Interactive Mode
claude-local-proxy [options]
Options:
-p, --port <port> Server port (1024-65535)
--skip-opencode Skip OpenCode auto-configuration
-h, --help Show help
-v, --version Show versionclaude-proxy - Background Mode
| Command | Description |
|---------|-------------|
| claude-proxy start | Start the proxy (background) |
| claude-proxy stop | Stop the proxy |
| claude-proxy restart | Restart the proxy |
| claude-proxy status | Check status |
| claude-proxy logs -f | View logs (live) |
| claude-proxy test | Test connectivity |
API Endpoints
GET /health- Health checkPOST /v1/messages- Messages API (Anthropic-compatible)
FAQ
| Issue | Solution |
|-------|----------|
| Login required | Run claude auth login to re-authenticate |
| Connection failed | Check environment variable: echo $ANTHROPIC_BASE_URL |
| Port in use | Use a different port: claude-local-proxy -p 12347 |
| Tool name mismatch | Proxy auto-maps tool names (e.g., Read→read) |
Contributing
PRs and issues are welcome!
