AnyAgent

opencode

Use opencode through AnyAgent: what you can ask for, how it behaves, and the flags underneath.

The opencode adapter drives the opencode CLI through opencode run --format json, detected as the opencode binary on PATH; import opencode from anyagent/opencode. opencode is bring-your-own-key (BYOK): it reads standard provider keys (OPENROUTER_API_KEY, ANTHROPIC_API_KEY, …) from the environment.

What you can ask for

readOnly, model (as "provider/model"), effort (a provider-defined variant name, passed verbatim), resume, forkSession, and attachments all work on the CLI’s own switches; systemPrompt and schema are provided by AnyAgent. MCP is a config-file concern, reachable via extraArgs. models() runs opencode models, every printed provider/model id valid verbatim as model; authStatus() reads ~/.local/share/opencode/auth.json plus the provider key env vars, a hint rather than a guarantee. The full grid is on the support matrix.

Good to know

  • The session id is surfaced once, on first sight, and lands on result.sessionId.
  • Usage arrives per step: each step_finish yields a usage event with that step’s share, including cache, reasoning, and cost, and result.usage carries the summed totals.

Under the hood

Every run executes opencode run --format json --auto with the prompt piped over stdin. Run options append flags:

OptionFlag or env
readOnly: trueenv OPENCODE_PERMISSION={"bash":"deny","edit":"deny"}
model--model <provider/model>
effort--variant <name>
resume--session <sessionId>
forkSession: true--fork, alongside --session, branching before continuing
attachments-f <file>, repeated once per attachment

On this page