Skip to content
BENIBIX Learn

--output-format Flag

Also known as claude --output-format, --output-format json, stream-json

It picks the shape of what claude -p prints.

Think of it like

It is like you ask for a note, a form or a call. It is the same news each way.

Example

Jack's script needs the session ID so it can resume later. It runs claude -p with --output-format json and reads session_id from the result.

Why it matters

A program can read JSON safely. Plain text has to be guessed at.

Definition

--output-format picks the shape of what claude -p prints. text, the default, prints just the answer. json prints one JSON object at the end, with the answer, the session ID and the cost. stream-json prints one JSON line for each event as it happens, so a program can follow the run live.

Example code

bash
claude -p "Summarize this project" --output-format json
Get the answer as one JSON object.
The same answer in each of the three shapes.

Common mistake

Using stream-json in print mode without --verbose. Claude Code stops with an error until you add it.

Key takeaways

  1. 1
    text. Just the answer.
  2. 2
    json. One object at the end.
  3. 3
    stream-json. A line per event.

Learn it properly