Expand description
Claude CLI JSON parser.
Parses NDJSON output from Claude CLI and formats it for display.
§Streaming Output Behavior
This parser implements real-time streaming output for text deltas. When content
arrives in multiple chunks (via content_block_delta events), the parser:
- Accumulates text deltas from each chunk into a buffer
- Displays the accumulated text after each chunk
- Uses carriage return (
\r) and line clearing (\x1b[2K) to rewrite the entire line, creating an updating effect that shows the content building up in real-time - Shows prefix on every delta, rewriting the entire line each time (industry standard)
Example output sequence for streaming “Hello World” in two chunks:
[Claude] Hello\r (first chunk with prefix, no newline)
\x1b[2K\r[Claude] Hello World\r (second chunk clears line, rewrites with accumulated)
[Claude] Hello World\n (message_stop adds final newline)§Single-Line Pattern
The renderer uses a single-line pattern with carriage return for in-place updates. This is the industry standard for streaming CLIs (used by Rich, Ink, Bubble Tea).
Each delta rewrites the entire line with prefix, ensuring that:
- The user always sees the prefix
- Content updates in-place without visual artifacts
- Terminal state is clean and predictable
This pattern is consistent across all parsers (Claude, Codex, Gemini, OpenCode)
with variations in when the prefix is shown based on each format’s event structure.
Structs§
- Claude
Parser - Claude event parser