$ recombobulate _
home / tips / use-output-format-stream-json-for-real-time-processing
0

Use --output-format stream-json for Real-Time Processing

bagwaa @bagwaa · Mar 25, 2026 · Workflows
use-output-format-stream-json-for-real-time-processing

If you're building tools that wrap Claude Code, you need structured output you can process line-by-line as it arrives. --output-format stream-json gives you exactly that — a stream of newline-delimited JSON events.

claude -p --output-format stream-json "Analyse the API routes in src/routes/"

Each line is a self-contained JSON object representing one event in the session:

{"type":"system","subtype":"init","session_id":"abc123","tools":["bash","read","write"]}
{"type":"assistant","message":{"content":[{"type":"text","text":"Looking at the routes..."}]}}
{"type":"assistant","message":{"content":[{"type":"tool_use","name":"read","input":{"file_path":"src/routes/api.ts"}}]}}
{"type":"result","subtype":"success","cost_usd":0.004,"duration_ms":3241}

Process the stream with jq to extract exactly what you need:

# Stream just the text content as it arrives
claude -p --output-format stream-json "Review the routes" | \
  jq -r 'select(.type=="assistant") | .message.content[] | select(.type=="text") | .text'

# Log cost after every automated run
claude -p --output-format stream-json "Run the audit" | \
  jq -r 'select(.type=="result") | "Cost: $\(.cost_usd) | Duration: \(.duration_ms)ms"'

No waiting for the full response before you can start processing. This makes it ideal for progress UIs, cost dashboards, audit logs, and building real-time tooling around Claude Code.

stream-json turns Claude Code from a black box into a live event stream you can build on.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago