Claude Agent
Use a Claude plan or Claude Code login in OpenCode through Claude Agent, which runs Claude Code on your machine.
Use your Claude plan or another Claude Code login. Claude Agent runs Claude Code on your machine, so install Claude Code 2.1.248 or later and sign in first.
claude auth loginThen connect Claude Agent and choose a model. The model list comes from Claude Code. Effort levels are variants, such
as claude-agent/opus#high.
/connect
# Select Claude Agent.
/modelsYou can also connect from the CLI with auth login claude-agent.
OpenCode finds claude on your PATH. To use another copy, set OPENCODE_CLAUDE_PATH on the server.
opencode service set env OPENCODE_CLAUDE_PATH /opt/claude/bin/claudeHow it works
Claude Code calls the model, and OpenCode does everything else.
- Claude gets Claude Code's system prompt, plus your agent's prompt,
AGENTS.mdfiles, skills, and MCP instructions. - Claude uses OpenCode's tools and permissions instead of Claude Code's built-in tools.
- Your Claude Code settings,
CLAUDE.mdfiles, hooks, MCP servers, skills, and memory are not loaded. - OpenCode runs compaction and subagents.
- You can switch between Claude Agent and other models in the same session.
Cost
Cost depends on how Claude Code is signed in.
| Login | Cost shown |
|---|---|
| Claude subscription | None, your plan covers it |
| Anthropic API key, or Claude Platform on AWS or Google Cloud | Anthropic prices |
| Amazon Bedrock | Bedrock prices, or Anthropic prices on Bedrock Mantle |
| Google Vertex | Vertex prices |
| Microsoft Foundry | Azure prices |
| Custom base URL | None |
Configure
Connection settings on the claude-agent provider are passed to Claude Code. They override the same variables set in
your shell.
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"claude-agent": {
"settings": {
"baseURL": "https://llm-proxy.example.com/anthropic",
},
"headers": {
"X-Gateway-Tenant": "engineering",
},
},
},
}| Config | Claude Code variable |
|---|---|
settings.baseURL | ANTHROPIC_BASE_URL |
settings.apiKey | ANTHROPIC_API_KEY |
settings.authToken | ANTHROPIC_AUTH_TOKEN |
settings.headerTimeout | API_TIMEOUT_MS |
settings.chunkTimeout | CLAUDE_STREAM_IDLE_TIMEOUT_MS |
settings.configDir | CLAUDE_CONFIG_DIR |
headers | ANTHROPIC_CUSTOM_HEADERS |
body | CLAUDE_CODE_EXTRA_BODY |
Set them on a model to override the provider's values for that model.
Use a second Claude account
Sign in to the second account in its own folder. Your usual login stays unchanged.
CLAUDE_CONFIG_DIR="$HOME/.claude-2" claude auth loginIn PowerShell:
$env:CLAUDE_CONFIG_DIR = "$HOME\.claude-2"; claude auth loginThen add models that use that folder:
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"claude-agent": {
"models": {
"sonnet-2": {
"modelID": "sonnet",
"name": "Sonnet (Claude 2)",
"settings": { "configDir": "~/.claude-2" },
},
},
},
},
}To use one account for every model in a project, set settings.configDir on the provider in that project's config
instead.
Rotate between accounts
If you have several interchangeable accounts, OpenCode can move to the next one when an account hits its usage limit.
Sign in to each extra account in its own folder. Your existing login in ~/.claude can stay as it is:
CLAUDE_CONFIG_DIR="$HOME/.claude-1" claude auth loginThen list the folders:
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"claude-agent": {
"settings": { "configDir": ["~/.claude", "~/.claude-1"] },
},
},
}A chat stays on the account that last answered it, and new chats start on the account that worked last. Rotation only
applies to Claude subscription logins, not to apiKey or authToken.
Web search
Claude Agent can also serve OpenCode's web search with Claude Code's WebSearch, so searches count toward your Claude
plan instead of needing a search API key. Every model can use it. Select it in opencode.jsonc:
{
"$schema": "https://opencode.ai/config.json",
"websearch": {
"provider": "claude-agent",
},
}See Web search for details.
Limitations
- Claude Code must be installed on the same machine as the OpenCode server. Claude Agent is not available in remote workspaces.
- Claude Code's system prompt replaces OpenCode's built-in prompt. Custom agent prompts still apply.
- Temperature, top-p, top-k, seed, and stop sequences are not supported.
- Plugin
http.requestandhttp.responsehooks do not run, because Claude Code makes the API calls. - Claude Code features such as
/usage,/loop, auto mode, and agent teams are not available.
Errors
| Error or symptom | Check |
|---|---|
Claude Code is not installed | Install Claude Code, or set OPENCODE_CLAUDE_PATH to its path. |
Claude Code is not logged in | Run claude auth login, then connect Claude Agent again. With configDir, run the command the error shows for that folder. |
Claude Code ... is too old | Run claude update. |