Skip to content

nmhuei/opencode2claude

Repository files navigation

🌉 OpenCode2Claude

Use Claude Code with any LLM — for free.

Crates.io CI Docker License: MIT GitHub Release

⚡ Quick Install

curl -fsSL https://raw.githubusercontent.com/nmhuei/opencode2claude/main/install.sh | sh

Claude Codeopencode2claudeOpenCode CLIAny LLM

source start.sh   # 5 seconds → ready to use
claude            # works with any model

InstallUsageConfigurationBenchmark


💡 Why?

Claude Code is locked to Anthropic's API. This bridge routes it through OpenCode to access 50+ models — including free tiers like deepseek-v4-flash-free.

Before After
Claude Code → Anthropic only Claude Code → Any LLM
💸 Pay per token 🆓 Free models available

📦 Install

The quick install script is the recommended method — it auto-detects your OS and architecture.

Alternatives:

  • cargo (if you have Rust): cargo install opencode2claude
  • Docker: docker pull ghcr.io/nmhuei/opencode2claude:latest

No dependencies needed. The binary is ~5MB and starts instantly.


👀 Usage

# Use a specific model
export OPENCODE_MODEL="openai/gpt-4o"
source start.sh

# Enable auth
export BRIDGE_AUTH_TOKEN="sk-your-token"
source start.sh

# Rate limiting
export BRIDGE_RATE_LIMIT=10
source start.sh

# CLI flags (override all config)
./target/release/opencode2claude --port 4000 --model "google/gemini-2.5-pro"

Shell commands bypass the LLM entirely — prefix with !:

You: !git status          # → instant local exec (0.01s)
You: !docker ps           # → direct terminal output
You: What is recursion?   # → routed through LLM as normal

⚙️ Configuration

Priority: CLI args > Env vars > TOML file > Defaults

Variable Default Description
BRIDGE_PORT 4000 Bridge listen port
BRIDGE_HOST 127.0.0.1 Bind address
OPENCODE_MODEL deepseek-v4-flash-free Target model
BRIDGE_SHELL_POLICY unrestricted disabled | allowlist | unrestricted
BRIDGE_AUTH_TOKEN (none) Comma-separated Bearer tokens
BRIDGE_RATE_LIMIT (none) Max concurrent requests (unset = unlimited)
BRIDGE_MAX_SEARCH_LOOPS 5 Search interception retries
TAVILY_API_KEY (none) Web search API keys...
BRIDGE_PROXIES (none) Comma-separated list of SOCKS5/HTTP proxies for multi-agent independent IP mapping
PROXY_POOL_SIZE 3 Number of Cloudflare WARP proxy containers to spawn dynamically (when Docker is available)

Full list: see CLAUDE.md or opencode2claude --help


🔄 Multi-Agent & Proxy Routing (Avoid Rate Limits)

When running multiple concurrent Claude Code agents, they can hit the free-tier rate limits quickly if they share a single IP.

To prevent this, opencode2claude supports a pool of SOCKS5 or HTTP proxies.

  1. Independent IP Mapping: The bridge automatically hashes each agent's API key (provided by Claude Code) to route it through a specific proxy in the pool. This ensures that different agents use different proxies/IPs.
  2. Automatic Cooldown & Failover: If a proxy hits a 429 Too Many Requests or network error, the bridge automatically marks it as rate-limited, puts it on cooldown, and routes the request through the next available proxy in the pool.

Automated Setup with Docker

If Docker is running on your host, start.sh will automatically spawn isolated Cloudflare WARP proxy containers for you. You can dynamically scale the pool using PROXY_POOL_SIZE:

# Spawn 5 WARP proxy containers on ports 40001 - 40005
export PROXY_POOL_SIZE=5
source start.sh

To clean up all containers and stop the bridge, simply run:

./stop.sh

Manual Proxy Pool Configuration

If you prefer to configure your own SOCKS5/HTTP proxies (e.g. Tor or private proxies):

export BRIDGE_PROXIES="socks5://127.0.0.1:40001,socks5://127.0.0.1:40002,socks5://127.0.0.1:40003"
source start.sh

📊 Benchmark

Metric Value
Bridge startup <5ms
Request routing <1ms
Shell command (!) ~10ms
Memory ~3MB
Binary ~5MB (static)

The bottleneck is always the LLM provider, never the bridge.


🔧 Tech Stack

Rust + Axum + Tokio + Reqwest — ~4k LOC, single binary, zero runtime deps.

📄 License

MIT — LICENSE

About

Use Claude Code with any LLM (DeepSeek, GPT-4o, Gemini, Llama, etc.) — for free

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors