Skip to content

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.

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 use Claude Official (Claude Code only))
  • For GPT-5 → use a Key from the OpenAI channel
  • For both → create two Keys and configure both in the config

Installation

Choose any one:

bash
curl -fsSL https://opencode.ai/install | bash
bash
npm install -g opencode-ai
bash
brew install anomalyco/tap/opencode

Configuration

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:

json
{
  "$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 }
        }
      }
    }
  }
}
bash
# 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:

bash
opencode

Once 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:

bash
opencode --model claude-api/claude-sonnet-4-6

Note 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:

json
{
  "$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

bash
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-ai

The provider doesn't appear in the /model list

  • ~/.config/opencode/opencode.json has an error (missing comma, missing quote) → run cat ~/.config/opencode/opencode.json | python -m json.tool to validate that the JSON is well-formed
  • The environment variable isn't exported → run echo $CLAUDE_API_KEY to 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.

This site is an API reverse-proxy service, not affiliated with Anthropic / OpenAI / Google.