opencode_run
Delegate a coding task to an OpenCode agent and block until it finishes or needs input. Resume the same session with your answer or permission decision.
Instructions
Delegate a coding task to OpenCode and block until it completes, errors, or needs input (a question or a permission).
New task: pass
directory+task+agent(a new session is created).agentis REQUIRED for a new session.Continuation / resume: pass
session_id(+taskfor a NEW turn on that session, ortaskis ignored when the turn is still in flight).agentis not needed to resume an in-flight turn (it is taken from the turn's durable state); pass it only when starting a fresh turn on an existing session.agent: the OpenCode agent to run as root. Free string, validated dynamically against the project's live agent list (GET /agent). It MUST be a primary agent of that directory (project-specific primary agents are preferred when they fit the task;buildis the generic implementation agent;planis read-only). Subagents are rejected as root. Do not rely on the server's default_agent: always choose explicitly for a new session.model: optional 'provider/model' override.
RESUME: if session_id is given and that session still has a turn in
flight (busy/retry) — e.g. the controller restarted mid-turn — the prompt
is NOT resubmitted: the wait loop simply resumes on the SAME turn
(task and agent are ignored in that case).
The call blocks until the turn ends. While OpenCode works, NOTHING is polled — the controller watches SSE + REST internally. If OpenCode asks a question or requests a permission, the call returns state='needs_agent_input' (kind='question' or 'permission') with everything needed to decide; answer with opencode_answer / opencode_permission, which resume the SAME turn. Returns the final assistant text + diff on completion.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task | Yes | ||
| agent | No | ||
| model | No | ||
| timeout | No | ||
| directory | Yes | ||
| session_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||