English
Documentation
Claude Agent

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 login

Then 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.
/models

You 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/claude

How 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.md files, skills, and MCP instructions.
  • Claude uses OpenCode's tools and permissions instead of Claude Code's built-in tools.
  • Your Claude Code settings, CLAUDE.md files, 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.

LoginCost shown
Claude subscriptionNone, your plan covers it
Anthropic API key, or Claude Platform on AWS or Google CloudAnthropic prices
Amazon BedrockBedrock prices, or Anthropic prices on Bedrock Mantle
Google VertexVertex prices
Microsoft FoundryAzure prices
Custom base URLNone

Configure

Connection settings on the claude-agent provider are passed to Claude Code. They override the same variables set in your shell.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "claude-agent": {
      "settings": {
        "baseURL": "https://llm-proxy.example.com/anthropic",
      },
      "headers": {
        "X-Gateway-Tenant": "engineering",
      },
    },
  },
}
ConfigClaude Code variable
settings.baseURLANTHROPIC_BASE_URL
settings.apiKeyANTHROPIC_API_KEY
settings.authTokenANTHROPIC_AUTH_TOKEN
settings.headerTimeoutAPI_TIMEOUT_MS
settings.chunkTimeoutCLAUDE_STREAM_IDLE_TIMEOUT_MS
settings.configDirCLAUDE_CONFIG_DIR
headersANTHROPIC_CUSTOM_HEADERS
bodyCLAUDE_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 login

In PowerShell:

$env:CLAUDE_CONFIG_DIR = "$HOME\.claude-2"; claude auth login

Then add models that use that folder:

opencode.jsonc
{
  "$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 login

Then list the folders:

opencode.jsonc
{
  "$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:

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.request and http.response hooks 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 symptomCheck
Claude Code is not installedInstall Claude Code, or set OPENCODE_CLAUDE_PATH to its path.
Claude Code is not logged inRun claude auth login, then connect Claude Agent again. With configDir, run the command the error shows for that folder.
Claude Code ... is too oldRun claude update.