opencode-claude-bridge
v1.8.0
Published
OpenCode ↔ Claude bridge — keychain sync + PKCE OAuth + request transformation
Downloads
2,230
Maintainers
Readme
opencode-claude-bridge
Use your Claude Pro/Max subscription in OpenCode. If you're logged into the Claude CLI, it just works — no extra setup.
Install
Add to ~/.config/opencode/opencode.json:
{
"plugin": ["opencode-claude-bridge"]
}OpenCode auto-installs the plugin from npm on next launch.
If you're logged into the Claude CLI (claude login), the plugin auto-syncs your credentials — just select an Anthropic model and start chatting. If not, you'll be prompted to authenticate via browser OAuth or enter an API key.
Upgrade:
OpenCode pins the installed version. To upgrade to the latest:
cd ~/.cache/opencode && npm install opencode-claude-bridge@latestThen restart OpenCode.
git clone https://github.com/dotCipher/opencode-claude-bridge.git ~/opencode-claude-bridge
cd ~/opencode-claude-bridge && npm install && npm run buildThen reference the full path in your config:
{
"plugin": ["/Users/YOU/opencode-claude-bridge/dist/index.js"]
}How the bridge works
The plugin sits between OpenCode and the Anthropic API:
OpenCode → opencode-claude-bridge → Anthropic API
Authentication — Supports both OAuth and API key auth:
- OAuth (Pro/Max) — Auto-reads your Claude CLI's OAuth tokens from macOS Keychain (or
~/.claude/.credentials.jsonon Linux). No browser flow needed. If Claude CLI isn't available, falls back to browser-based OAuth PKCE. - API key — Works alongside a standard
providerentry in your OpenCode config with anapiKey. The plugin only activates its OAuth handling for the built-inanthropicprovider; custom API key providers pass through unchanged.
Token refresh — When tokens expire, three layers are tried: re-read from Keychain, refresh via stored token, refresh via CLI's token.
Request transformation — Every outbound OAuth request is rewritten to match what Claude Code sends: correct headers, ?beta=true URL parameter, thinking body field, mcp_ tool name prefixing, and system prompt sanitization.
Requirements
- OpenCode v1.2+
- For OAuth: Claude CLI installed and logged in (
claude login) - macOS (Keychain) or Linux (
~/.claude/.credentials.jsonfallback) - For API key: just configure a
providerwithapiKeyin your OpenCode config as usual
Environment overrides
All OAuth and header parameters can be overridden via environment variables (ANTHROPIC_CLIENT_ID, ANTHROPIC_TOKEN_URL, ANTHROPIC_AUTHORIZE_URL, ANTHROPIC_CLI_VERSION, ANTHROPIC_BETA_FLAGS). Defaults match Claude Code 2.1.81 — most users won't need to change these.
Updating for new Claude CLI versions
When Claude Code updates, the required headers or body fields may change. To capture exactly what the latest Claude CLI sends:
./scripts/intercept-claude.sh claude-sonnet-4-6This starts a local proxy, runs Claude CLI through it with OAuth, and saves the full request headers and body to /tmp/claude-intercept-*. Compare against the plugin's constants and fetch wrapper to spot differences.
Key things that have changed across versions:
anthropic-betaflags (required set changes)- Body fields (
thinking,metadata,context_management) user-agentversion stringx-stainless-package-version
Credits
Combines approaches from shahidshabbir-se/opencode-anthropic-oauth, ex-machina-co/opencode-anthropic-auth, vinzabe/PERMANENT-opencode-anthropic-oauth-fix, and lehdqlsl/opencode-claude-auth-sync.
License
MIT
