Skip to main content
Glama

OpenCode

opencode
Destructive

Delegate a coding task to an AI coding agent, run its first turn, and return a session ID for follow-up replies, status polling, and output retrieval.

Instructions

Use this to delegate a new coding task to OpenCode and run its first turn. Blocks until the turn finishes (or wait-seconds elapses, up to the turn timeout). The final answer and status are in structuredContent.content / structuredContent.status; the text response mirrors the same content. Returns a session id (also usable as threadId/conversationId) to continue with opencode-reply. sandbox selects a cooperative permission profile for OpenCode's own tools (read-only / workspace-write / danger-full-access) — it is not OS-level isolation, OpenCode can still run arbitrary shell commands unless a rule denies it. approval-policy controls permission prompts raised by OpenCode: never (default) auto-denies them, on-request asks interactively when the client supports it. Cancelling or stopping the call that OWNS this turn (Esc, TaskStop, a client timeout) cancels the OpenCode turn; a call that only joined an existing turn as an observer (e.g. a duplicate request-id) detaches without cancelling anything. To stop waiting but keep the turn running, pass wait-seconds and poll opencode-status. Use detail/max-output-chars to keep this response small (the full answer stays readable with opencode-output); request-id makes a retried call safe to repeat; output-schema asks the final message to be one JSON value matching a schema. To run several tasks in parallel, start each with wait-seconds:0 and check them together with opencode-status ids/wait-for.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdNoWorking directory for this session. Relative paths resolve against the server default cwd; must be inside an allowed root. Omit to use the server default cwd.
agentNoOpenCode's primary agent for this session (e.g. 'build', 'plan', or a custom agent). Omit to use the server-configured default, or OpenCode's own default agent.
modelNoModel to use, in the form 'provider/model' (e.g. 'my-gateway/coder-large'), not a bare model name. Omit to use the server-configured default, or OpenCode's own resolution if none is set.
titleNoSession title shown by opencode-status. Defaults to the first line of prompt (up to 80 chars).
detailNo'compact' (default 'standard') drops toolCalls and filesChanged from this response (keeping toolCallCount, filesChangedCount, pendingApprovalCount, and pendingApprovals itself) to save context; the full answer and tool-call log stay retrievable with opencode-output regardless of this setting.
promptYesThe task or instructions to send to OpenCode for this turn.
sandboxNoCooperative permission profile for OpenCode's own tools (default 'workspace-write'). Not OS-level isolation: OpenCode can still run arbitrary shell commands unless a rule denies it. Fixed for the life of the session once chosen. 'read-only' also denies file edits, bash, paths outside cwd and web fetch/search.
request-idNoIdempotency key for this exact call (pattern: starts with a letter/digit, then up to 127 more letters/digits/'.'/'_'/':'/'-'). Retrying the same request-id after a network drop or client retry joins the original operation instead of sending a second prompt to OpenCode; a different request-id (or omitting it) always starts a new one. Shared between opencode and opencode-reply.
wait-secondsNoBounds only how long THIS call waits for a result, in seconds; it does not limit the turn itself. On expiry this call returns a 'running' (or 'waiting_for_approval') snapshot while the turn keeps executing on the server — continue observing it with opencode-status. Omit to block until the turn reaches a terminal state (subject to timeout-seconds); 0 returns immediately after admission — combine with opencode-status ids/wait-for to fan a batch of turns out in parallel and then observe them together.
output-schemaNoAsk OpenCode's final message for THIS turn to be one JSON value matching this JSON Schema (subset: object/array/string/number/integer/boolean/null; no $ref or unions; see README for the full list of supported keywords). Reported back as structuredOutput / structuredOutputStatus ('valid'/'missing'/'invalid'); still untrusted model output, and never changes status, error or retry behaviour. Turn-local: never inherited by a later reply.
approval-policyNoHow OpenCode permission prompts are handled (default 'never'): 'never' auto-denies them; 'on-request' asks interactively when the client supports it, otherwise also denies. Fixed for the life of the session once chosen.
timeout-secondsNoThis turn's hard run-time limit, in seconds. When it expires, the OpenCode run is stopped and the result comes back with status 'timeout' — the work already done is not lost, but the turn itself ends. This is not a call timeout: to stop waiting for a response while letting the turn keep running, use wait-seconds instead.
max-output-charsNoCaps how many characters of the answer come back in THIS response only (0..44000; 0 returns no answer text at all). Never truncates the retained turn — read the rest with opencode-output. Omit to use the default for the chosen detail level (44000 standard, 2000 compact).
base-instructionsNoExtra system text sent before developer-instructions. OpenCode can't replace its own base prompt per request, so this is added text, not a full override.
developer-instructionsNoSystem-prompt text for this session; stored and re-sent on every turn, including replies.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
costNo
diffNo
hintNo
kindYes
turnNo
agentNo
errorNo
modelNo
rootsNo
totalNo
actionNo
agentsNo
finishNo
modelsNo
offsetNo
outputNo
reasonNo
serverNo
statusYes
tokensNo
turnIdNo
cleanupNo
contentYes
hasMoreNo
partialNo
requestNo
resultsNo
sectionNo
waitForNo
readyIdsNo
sessionsNo
threadIdNo
warningsNo
directoryNo
elapsedMsNo
sessionIdNo
toolCallsNo
truncatedNo
nextOffsetNo
observedAtNo
pendingIdsNo
snapshotIdNo
availabilityNo
filesChangedNo
resendSafetyNo
responseLoopNo
upstreamReadNo
omittedFieldsNo
toolCallCountNo
upstreamRetryNo
executionStateNo
opencodeVersionNo
pendingApprovalsNo
structuredOutputNo
filesChangedCountNo
abortedRunningTurnNo
pendingApprovalCountNo
structuredOutputErrorNo
structuredOutputStatusNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.3.0

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already flag destructiveHint and openWorldHint, but the description adds substantial behavioral detail: blocking and timeout semantics, cancellation ownership, idempotent request-id behavior, sandbox being cooperative rather than OS-level isolation, approval-policy defaults, and output-schema being turn-local. No contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with purpose, blocking behavior, and session continuation before moving into options. It is necessarily long for a 15-parameter tool, but a few details are repeated, such as structuredContent.content/status and the text response mirroring it, which adds minor redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity, the description is remarkably complete. It covers purpose, interaction model, cancellation, sandbox limitations, approval behavior, idempotency, polling alternatives, and parallel execution, leaving no critical calling context missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already carries baseline parameter documentation. The description still adds cross-parameter meaning: wait-seconds versus timeout-seconds, request-id being shared between opencode and opencode-reply, output-schema being turn-local, and detail/max-output-chars affecting only this response.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: 'delegate a new coding task to OpenCode and run its first turn.' The word 'new' and the session-id continuation sentence distinguish it from opencode-reply without requiring the sibling schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly routes to alternatives: continue with opencode-reply, poll opencode-status, start parallel tasks with wait-seconds:0, and use opencode-output for the full answer. It also defines when cancellation affects the turn versus when an observer call detaches.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.