Output schema for text, JSON and stream-JSON formats
--output-format
option when combined with --print
. These formats include structured formats for programmatic use (json
, stream-json
) and a simplified text format for human-readable progress tracking.
--output-format
is stream-json
. This option is only valid when printing (--print
) or when print mode is inferred (non-TTY stdout or piped stdin).json
output format emits a single JSON object (followed by a newline) when the run completes successfully. Deltas and tool events are not emitted; text is aggregated into the final result.
On failure, the process exits with a non-zero code and writes an error message to stderr. No well-formed JSON object is emitted in failure cases.
Field | Description |
---|---|
type | Always "result" for terminal results |
subtype | Always "success" for successful completions |
is_error | Always false for successful responses |
duration_ms | Total execution time in milliseconds |
duration_api_ms | API request time in milliseconds (currently equal to duration_ms ) |
result | Complete assistant response text (concatenation of all text deltas) |
session_id | Unique session identifier |
request_id | Optional request identifier (may be omitted) |
stream-json
output format emits newline-delimited JSON (NDJSON). Each line contains a single JSON object representing a real-time event during execution.
The stream ends with a terminal result
event on success. On failure, the process exits with a non-zero code and the stream may end early without a terminal event; an error message is written to stderr.
tools
and mcp_servers
may be added to this event.message.content[].text
values in order to reconstruct the complete assistant response.text
output format provides a simplified, human-readable stream of agent actions. Instead of detailed JSON events, it outputs concise text descriptions of what the agent is doing in real-time.
This format is useful for monitoring agent progress without the overhead of parsing structured data, making it ideal for logging, debugging, or simple progress tracking.
\n
thinking
events are suppressed in print mode and will not appear in either output format