opencode
opencode is an open-source AI coding terminal agent from the sst team. It is positioned similarly to Claude Code, but is fully open-source and not tied to any provider. You can wire in any service compatible with the OpenAI / Anthropic protocols through its config file.
Key differences:
- Free switching between multiple providers: native support for Claude / OpenAI / Google / Cloudflare / local models, all configurable together in a single config
- TUI first: the terminal interface is closer to a Neovim style than Claude Code's
- Client/server architecture: the underlying service can run independently, making it easy to share across multiple frontends
Who it's for: tinkerer-type developers; anyone who wants to escape vendor lock-in to Anthropic / OpenAI; those who prefer a terminal plus side-by-side comparison of multiple models.
Recommended Channels
Pick a Key based on the model you want to use:
- For Claude → use a Key from the
Claude Official (any client)channel (opencode is not the Claude Code CLI, so it cannot useClaude Official (Claude Code only)) - For GPT-5 → use a Key from the
OpenAIchannel - For both → create two Keys and configure both in the config
Installation
Choose any one:
curl -fsSL https://opencode.ai/install | bashnpm install -g opencode-aibrew install anomalyco/tap/opencodeConfiguration
opencode's config file lives at ~/.config/opencode/opencode.json (or .jsonc). We use @ai-sdk/openai-compatible to add claude-api.org as a custom provider:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"claude-api": {
"npm": "@ai-sdk/openai-compatible",
"name": "Claude API (claude-api.org)",
"options": {
"baseURL": "https://claude-api.org/v1",
"apiKey": "{env:CLAUDE_API_KEY}"
},
"models": {
"claude-opus-4-7": {
"name": "Claude Opus 4.7",
"limit": { "context": 200000, "output": 65536 }
},
"claude-sonnet-4-6": {
"name": "Claude Sonnet 4.6",
"limit": { "context": 200000, "output": 65536 }
},
"claude-haiku-4-5-20251001": {
"name": "Claude Haiku 4.5",
"limit": { "context": 200000, "output": 65536 }
},
"gpt-5.4": {
"name": "GPT-5.4",
"limit": { "context": 128000, "output": 16384 }
},
"gpt-5.5": {
"name": "GPT-5.5",
"limit": { "context": 128000, "output": 16384 }
},
"gpt-5.3-codex": {
"name": "GPT-5.3 Codex",
"limit": { "context": 128000, "output": 16384 }
}
}
}
}
}# Add to ~/.zshrc or ~/.bashrc
export CLAUDE_API_KEY="sk-your-key"Multiple channels in one config
If you want to use different Keys for Claude and GPT (for fine-grained billing), copy the claude-api provider above and rename the copy to claude-api-gpt, bind each to its own environment variable (CLAUDE_API_KEY_CLAUDE / CLAUDE_API_KEY_GPT), and attach the respective models to each.
Verification
Start opencode:
opencodeOnce inside the TUI, type /model. You should see all the models you just configured (Claude Opus 4.7 / GPT-5.4, etc.). Pick one and send "hello"; if you get a reply, the setup succeeded.
You can also specify a model directly at startup:
opencode --model claude-api/claude-sonnet-4-6Note that the model is written as <provider-name>/<model-id>.
Advanced
Using the native Anthropic protocol (optional)
If you want to connect directly through opencode's built-in anthropic provider (via /v1/messages instead of /v1/chat/completions), try:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"options": {
"baseURL": "https://claude-api.org",
"apiKey": "{env:CLAUDE_API_KEY}"
}
}
}
}Experimental
The compatibility of opencode's built-in anthropic provider with a custom baseURL varies by version. If the OpenAI-compatible approach above already works, prefer it.
Coexisting with Claude Code
opencode's config file is independent from Claude Code's (~/.claude/settings.json), so you can install both at the same time. The same sub2api Key works for both.
FAQ
npm reports an EACCES permission error
sudo npm install -g opencode-ai
# Or set a user-level prefix with npm:
mkdir -p ~/.npm-global && npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
npm install -g opencode-aiThe provider doesn't appear in the /model list
~/.config/opencode/opencode.jsonhas an error (missing comma, missing quote) → runcat ~/.config/opencode/opencode.json | python -m json.toolto validate that the JSON is well-formed- The environment variable isn't exported → run
echo $CLAUDE_API_KEYto check that it has a value - opencode cached the old config → restart opencode
A model reports 404 Not Found
- Make sure the channel bound to your sub2api Key supports that model
- The model name is wrong (missing version number) → check the exact names on Channels & Pricing
Streaming output stutters
opencode uses standard SSE. If your domestic ISP times out on long-lived SSE connections, see the workarounds in the FAQ.
For more, see the FAQ.
