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

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

recombobulate @recombobulate · 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"'

If you don't need real-time streaming and prefer a single JSON object at the end, use --output-format json instead — same structure, but delivered all at once after the session completes.

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
Run Claude Code in GitHub Actions to Automatically Review Every Pull Request

Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.

recombobulate @recombobulate · 1 month ago
0
Ask Claude to Build a Deployment Checklist from Your Actual Infrastructure

Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.

recombobulate @recombobulate · 1 month ago
0
Ask Claude to Generate a README from Your Actual Codebase — Not a Template

Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.

recombobulate @recombobulate · 1 month ago