OpenCode (Provider)
Run NanoClaw agents on OpenCode instead of the Claude Agent SDK. OpenRouter, Anthropic, DeepSeek, Google, and any OpenAI-compatible provider.
What it does
- Replace Claude Agent SDK with OpenCode as the agent provider
- Works with OpenRouter, Anthropic, DeepSeek, Google, OpenCode Zen, and others
- Per-group selection via container.json — mix providers freely
- OneCLI credential proxy supported — keys never live in .env
- MCP tools shared across providers (same merged config)
What you'll need
- NanoClaw installed and running
- OneCLI Agent Vault for credential injection (recommended)
- An API key from at least one supported provider
Install
/add-opencode How it works
NanoClaw runs each agent group in a long-lived poll loop inside its container. The backend is selected with AGENT_PROVIDER — claude (default), opencode, codex, or mock.
The /add-opencode skill copies the OpenCode provider from the providers branch and wires it in. OpenCode keeps a local opencode serve process and SSE subscription. Each turn opens a new stream; teardown is stream.return() plus a SIGKILL on the server process to avoid zombie / MCP hangs.
OpenCode is multi-provider. You set a provider id (anthropic, openrouter, deepseek, opencode/Zen, etc.) and a model id, and OpenCode handles the dispatch.
Setup
The skill walks you through:
- Fetch the
providersbranch. - Copy
opencode.tsandmcp-to-opencode.tsinto the host and container provider trees. - Add the self-registration import to both barrels.
bun add @opencode-ai/sdk@1.4.17incontainer/agent-runner/(must match the CLI version pinned in step 5).- Pin
OPENCODE_VERSIONincontainer/Dockerfileand addopencode-ai@${OPENCODE_VERSION}to the global pnpm install. - Rebuild host and container.
If you have existing agent groups, the skill also propagates the new files into each group’s data/v2-sessions/<id>/agent-runner-src/providers/ overlay — the runtime overlay overrides the image, so it has to be updated separately.
Provider configurations
A few common shapes:
OpenRouter:
OPENCODE_PROVIDER=openrouter
OPENCODE_MODEL=openrouter/anthropic/claude-sonnet-4
ANTHROPIC_BASE_URL=https://openrouter.ai/api/v1
DeepSeek:
OPENCODE_PROVIDER=deepseek
OPENCODE_MODEL=deepseek/deepseek-chat
ANTHROPIC_BASE_URL=https://api.deepseek.com/v1
Anthropic (no ANTHROPIC_BASE_URL needed):
OPENCODE_PROVIDER=anthropic
OPENCODE_MODEL=anthropic/claude-sonnet-4-20250514
OpenCode Zen uses x-api-key headers, not Bearer — register the OneCLI secret with --header-name "x-api-key" and --value-format "{value}".
For each provider, register the API key with OneCLI using a matching --host-pattern so the credential proxy injects it for the right outbound calls.
Per-group config
Set the provider in two places that must agree:
groups/<folder>/container.json→"provider": "opencode"agent_groups.agent_provider→'opencode'(or per-session override viasessions.agent_provider)
The container reads container.json directly. The DB columns drive host-side env passthrough (per-session XDG mount, OPENCODE_* env).
Tips
- Pin both the SDK and the CLI to 1.4.x. The 1.14.x SDK has a completely different API and breaks the provider code.
latestwill silently upgrade to a broken version. - Build cache gotcha: if you see “Unknown provider: opencode” after a rebuild, the buildkit cached an older COPY. Run
docker builder prune -f && ./container/build.sh. NO_PROXYmatters when the OpenCode client talks to127.0.0.1inside the container while OneCLI’s HTTPS_PROXY is set.- Naming overlap:
AGENT_PROVIDER=opencode(NanoClaw setting) means “use the OpenCode runner.”OPENCODE_PROVIDER=opencode(OpenCode’s setting) means “use Zen as the upstream provider.” Yes, that’s confusing. - Codex vs. OpenCode: Codex is OpenAI-only with a simpler config. OpenCode is multi-provider but has more knobs. Pick based on which model selection style fits.