opencode
The opencode worker exposes the OpenCode API as iii functions. One
opencode::run call executes one headless OpenCode turn — the same agent the
user runs in their terminal, with the same tools — in a chosen working
directory, and returns the final result, token usage, and cost. Every JSON
event OpenCode emits (step_start, text, tool_use, step_finish) mirrors
verbatim onto opencode::events; a translated AgentEvent view lands on
agent::events, which the iii console and the acp worker render.
Requires the opencode CLI on the host and an API key for the LLM provider you
use (e.g. ANTHROPIC_API_KEY, or opencode auth). When a turn needs a
capability beyond OpenCode itself, add another iii worker to the bus instead of
bolting anything onto this one.
When to Use
- Delegate a whole coding task ("add an endpoint and run the tests") in one
call:
opencode::run with prompt and cwd.
- Continue a conversation across calls: pass the same
session_id again and
the worker resumes the underlying OpenCode session (--session).
- Run long jobs without holding the call open:
opencode::start returns
{session_id, started} immediately; follow agent::events (group_id =
session_id) for the rendered view or opencode::events for raw JSON;
interrupt with opencode::stop.
- Act on the whole backend: turns carry the iii runtime context by default, so
the agent discovers and calls any registered function through the iii CLI
(engine::functions::list,
iii trigger <fn> --help); disable per turn with
iii_context: false.
- Pick a model or agent per turn:
model as provider/model, agent as an
OpenCode agent name.
Boundaries
- Spawns the host
opencode CLI per turn — needs OpenCode installed and a
provider key; not available in a bare container without it.
opencode::run / opencode::start are not agent-callable without human
approval (they spawn a full agent with the host's shell + filesystem);
read-only introspection is allowed (see iii-permissions.yaml).
- One turn per session at a time: check
opencode::status (live: true) before
another opencode::run for the same session_id.
Functions
opencode::run — run one turn, wait; accepts prompt (or a messages
array), plus model, cwd, agent, iii_context; returns {session_id, opencode_session_id, result, stop_reason, usage, total_cost_usd}.
opencode::start — same payload, returns {session_id, started} immediately.
opencode::stop — interrupt the live run for a session.
opencode::status — point-in-time session view: live flag, status, turns,
usage, cost.
opencode::sessions::list — every session this worker has run.
run::start_and_wait — alias for opencode::run under the entrypoint the
console and acp worker drive.
1---2name: opencode3description: Run headless OpenCode turns over the iii bus — file edits, shell, and search against any host directory — with verbatim JSON event streaming, session resume, and inline token usage and cost.4---56# opencode78The opencode worker exposes the OpenCode API as iii functions. One9`opencode::run` call executes one headless OpenCode turn — the same agent the10user runs in their terminal, with the same tools — in a chosen working11directory, and returns the final result, token usage, and cost. Every JSON12event OpenCode emits (`step_start`, `text`, `tool_use`, `step_finish`) mirrors13verbatim onto `opencode::events`; a translated AgentEvent view lands on14`agent::events`, which the iii console and the acp worker render.1516Requires the `opencode` CLI on the host and an API key for the LLM provider you17use (e.g. `ANTHROPIC_API_KEY`, or `opencode auth`). When a turn needs a18capability beyond OpenCode itself, add another iii worker to the bus instead of19bolting anything onto this one.2021## When to Use2223- Delegate a whole coding task ("add an endpoint and run the tests") in one24 call: `opencode::run` with `prompt` and `cwd`.25- Continue a conversation across calls: pass the same `session_id` again and26 the worker resumes the underlying OpenCode session (`--session`).27- Run long jobs without holding the call open: `opencode::start` returns28 `{session_id, started}` immediately; follow `agent::events` (group_id =29 session_id) for the rendered view or `opencode::events` for raw JSON;30 interrupt with `opencode::stop`.31- Act on the whole backend: turns carry the iii runtime context by default, so32 the agent discovers and calls any registered function through the iii CLI33 (engine::functions::list, `iii trigger <fn> --help`); disable per turn with34 `iii_context: false`.35- Pick a model or agent per turn: `model` as `provider/model`, `agent` as an36 OpenCode agent name.3738## Boundaries3940- Spawns the host `opencode` CLI per turn — needs OpenCode installed and a41 provider key; not available in a bare container without it.42- `opencode::run` / `opencode::start` are not agent-callable without human43 approval (they spawn a full agent with the host's shell + filesystem);44 read-only introspection is allowed (see iii-permissions.yaml).45- One turn per session at a time: check `opencode::status` (`live: true`) before46 another `opencode::run` for the same `session_id`.4748## Functions4950- `opencode::run` — run one turn, wait; accepts `prompt` (or a `messages`51 array), plus `model`, `cwd`, `agent`, `iii_context`; returns `{session_id,52 opencode_session_id, result, stop_reason, usage, total_cost_usd}`.53- `opencode::start` — same payload, returns `{session_id, started}` immediately.54- `opencode::stop` — interrupt the live run for a session.55- `opencode::status` — point-in-time session view: live flag, status, turns,56 usage, cost.57- `opencode::sessions::list` — every session this worker has run.58- `run::start_and_wait` — alias for `opencode::run` under the entrypoint the59 console and acp worker drive.