PRODUCTION SCENARIO
A release pipeline has Claude Code inspect a deployment diff and hand the findings to an automated policy checker. The checker reads named fields, fails the build on any violation, and runs with no human watching, so the payload has to arrive with the same field names and types on every run. Nobody needs to see the run progress as it happens.
Which flags produce a result the checker can parse?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: --output-format json with --json-schema, reading the fields back from structured_output
Passing --json-schema alongside --output-format json constrains the result to the schema and puts it in the structured_output field, which is what gives the checker the same named fields on every run. Streaming with verbose output is the right choice when someone is watching and wants tokens as they arrive; it emits the same content as events and leaves reassembly and the shape problem to you. The json format on its own is right when a human or a log is the consumer, because it wraps prose in JSON metadata and the result field is still free text. Asking for JSON in the prompt is the fallback where no schema flag exists, and it makes conformance likely rather than constrained.
Official Source: https://code.claude.com/docs/en/headless ↗