Skip to content

Events

OpenCode emits its activity as EventFormat::Opencode. It is run with opencode run --format json, which writes a line-delimited JSON stream on standard output: each non-empty line is one complete JSON object carrying a top-level type. The harness layer parses that step stream and maps it onto the normalized harness events. The session id is captured from the first sessionID, session_id, or sessionId field seen.

The stream is a sequence of step-oriented records. Step boundaries are consumed; reasoning, text, tool use, and errors carry activity.

OpenCode eventHandling
step_start, step_finishStep boundaries, consumed. They carry the usage totals used for metrics. No event.
reasoningModel thinking. Becomes a reasoning event when it carries text, otherwise consumed.
textBecomes an agent message (empty text emits nothing).
tool_useA self-contained tool record, classified in place (see Tool mapping).
errorBecomes an error event.
any other typeBecomes an unknown event.

A tool_use record is self-contained — it carries the tool name, input, and a terminal status in one record, so no request/response correlation is needed. Its status (completed/success/done/ok versus error/failed/failure/ cancelled) sets the success field on the resulting event.

Each line is mapped by its top-level type. The agent text comes from a text record, and each tool_use record is classified into one or more file-operation events by its tool name. Any line that fails to parse as JSON, any type not listed above, and any tool_use whose tool name is unrecognized all become unknown events so the stream stays lossless.

Tool names are matched case-insensitively and classified self-contained:

OpenCode toolEvent
readread
write, editwrite
apply_patchone write per file named by the patch markers
grep, globsearch
bashcommand, or a recognized file operation
skillskill
lspsearch when it carries a query/symbol, otherwise unknown
todowrite, todoreadconsumed — internal task list, no event
any other tool (webfetch, websearch, question, …)unknown

lsp is treated as a search only when it carries a query or symbol; a navigation operation with none falls through to an unknown event. OpenCode does not expose orchestration activity in this version.


For the normalized event types these map onto, see Harness Events.