Skip to main content

Module claude_stream_json

Module claude_stream_json 

Source
Expand description

Claude Code -p --output-format stream-json transcript parsing.

Parses the newline-delimited JSON event stream that claude -p --output-format stream-json --verbose writes (captured per task as outputs/claude-events.jsonl). The assistant/user events wrap a full Anthropic Messages object under message, so tool-call extraction is shared with the in-session claude_code_transcript parser. The differences are all in the envelope: there are no per-line timestamps, and a terminal result event carries the authoritative final text, wall-clock duration, and token usage. system, rate_limit_event, and any other non-message events are ignored (they don’t deserialize into an assistant/user record, so the shared extractor skips them).

Functions§

parse_claude_stream_json
Parse the event stream into ordered tool invocations. Reuses the in-session extractor: non-message events deserialize into records the extractor skips.
parse_claude_stream_json_full
Parse the event stream into a full TranscriptSummary. Final text, duration, and token totals come from the terminal result event; on a missing or errored result the final text falls back to the last assistant message’s text, and duration/tokens fall back to None.