Skip to content

Events

OpenCode emits its activity as EventFormat::Opencode. It runs with opencode run --format json, which writes a line-delimited JSON stream on standard output. The harness layer parses that stream and maps it onto the normalized harness events.

Each non-empty line is one complete JSON object carrying a top-level type. The stream is step-oriented: step boundaries bracket the model’s turns, and reasoning, text, tool use, and errors carry the activity within them.

The session id is captured from the first sessionID, session_id, or sessionId field seen.

A tool_use record is self-contained. It carries the tool name, its input, and a terminal status in one record, so no request/response correlation is needed. A status of completed, success, done, or ok marks the call successful; error, failed, failure, cancelled, or canceled marks it failed. Any other status leaves success undetermined.

Raw recordNormalized event
step_startconsumed
step_finishconsumed; carries this step’s token usage, emitted as a per-turn usage event and summed into the run’s metrics
reasoningreasoning when it carries text, otherwise consumed
textagent message when it carries text, otherwise consumed
tool_usethe events its tool classifies to (see Tool mapping)
errorerror
any other typeunknown

A tool_use whose tool name is unrecognized also becomes an unknown event, and a line that fails to parse as JSON becomes a warning, so the stream stays lossless.

Tool names are matched case-insensitively:

OpenCode toolEvent
readread
write, editwrite
apply_patchone write per file named by the patch markers
grep, globsearch
bashcommand, or a recognized file operation
background_processcommand when the input carries a command line, otherwise consumed
task, agent_managerorchestration when the spawned agent or session is identified, otherwise unknown
skillskill
lspsearch when it carries a query or symbol, otherwise unknown
todo, todowrite, todoreadconsumed; the agent’s internal task list
any other toolunknown