Skip to content

Headless output formats are defined in packages/core/src/output/types.ts and accepted by the CLI as text, json, and stream-json. The default can also be set with the output.format setting.

text ​

Human-readable, sanitized terminal output. This is the default and the safest choice when output will be displayed directly.

json ​

A single pretty-printed JSON object emitted at the end of the run:

FieldTypeMeaning
session_idstring, optionalSession identifier.
responsestringFinal response with ANSI escapes stripped.
statsobjectSession metrics.
errorobject, optional{ type, message, code? }.
warningsarrayWarning strings.
bash
m31a -p "Summarize the failing tests" --output-format json > result.json

stream-json ​

Newline-delimited JSON events. Every event has type and timestamp.

typeFieldsMeaning
initsession_id, modelRun started.
messagerole (user/assistant), content, optional deltaConversation content.
tool_usetool_name, tool_id, parametersA tool call was proposed.
tool_resulttool_id, status (success/error), optional output, errorTool result.
errorseverity (warning/error), messageDiagnostic event.
resultstatus (success/error), optional error, statsFinal result.

Stats fields include total_tokens, input_tokens, output_tokens, cached, input, duration_ms, tool_calls, and models keyed by model name.

bash
m31a -p "Run the test suite" --output-format stream-json > events.jsonl
tail -n 1 events.jsonl | jq '.type, .status'

Raw output ​

--raw-output disables sanitization, allowing ANSI sequences from model output to reach stdout. This can be dangerous with untrusted content; --accept-raw-output-risk suppresses the warning. Prefer sanitized output in automation.

Choosing a format ​

  • Scripts that need a single answer — json.
  • Progress dashboards or long-running jobs — stream-json.
  • Humans reading terminal output — text.

See Headless mode and the CI tutorial for complete examples.

Built with VitePress. Powered by NVIDIA NIM.