[BUG] stdout under --output-format stream-json stops while session continues
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Summary
When using claude --output-format stream-json --print, the stdout stream can stop outputting events mid-session while Claude continues working internally. This makes headless/automated Claude Code usage unreliable.
Environment
- Claude Code version: 2.1.3
- OS: Ubuntu Linux 6.8.0-90-generic
- Date observed: 2026-01-10
Command used
claude --dangerously-skip-permissions --output-format stream-json --verbose --print "<prompt>"
Issue description
During automated execution, Claude Code's stream-json stdout output stopped at 02:59:19 while Claude continued working internally for another 2 minutes until 03:01:19.
Timeline
| Time | What happened |
|------|---------------|
| 02:55:55 | Session started, stream-json output working |
| 02:59:19 | Last event captured from stdout (a Read tool call) |
| 02:59:23 - 03:01:13 | Claude continued working (visible in internal JSONL log) |
| 03:01:19 | Claude output SESSION_CLOSE and exited with code 0 |
Key observations
- Internal JSONL logging continued: Claude's internal log at
~/.claude/projects/.../session.jsonlshows all events from 02:59:19 to 03:01:19, including the final SESSION_CLOSE - stdout stopped: No events were output to stdout after 02:59:19
- Claude completed successfully: Exit code 0, work committed, SESSION_CLOSE properly formed
- No errors: No error messages on stderr, no crash, clean exit
Evidence
Claude's internal JSONL shows the final output:
[SESSION_CLOSE]
{
"state": "done",
"summary": "Implemented live transcript streaming with auto-scroll...",
"git": {"branch": "main", "commit": "0018a0d", "pushed": false}
}
[/SESSION_CLOSE]
This was logged internally at 03:01:19 but never appeared on stdout.
What was happening when output stopped
- Last captured event:
Readtool call for a 658-line TypeScript file - The tool result (51KB) was processed internally
- Claude continued with 15+ more events (text, tool_use) that were never output to stdout
Impact
This issue breaks automated/headless Claude Code usage where external systems rely on stream-json output to:
- Track session progress
- Detect session completion
- Capture SESSION_CLOSE for state management
- Stream transcripts to users
When stream-json stops outputting:
- External systems can't detect completion
- Sessions appear "stalled" even though Claude finished
- Manual intervention required to check Claude's internal state
Expected behavior
All events that are logged to Claude's internal JSONL file should also be output to stdout when using --output-format stream-json.
Workaround
Currently monitoring Claude's internal JSONL files directly, but this:
- Requires parsing Claude's internal format
- May break with Claude Code updates
- Is not the intended integration method
Reproducibility
This has occurred multiple times during flow testing. It appears intermittent - some sessions complete with full stream-json output, others stop mid-session.
Request
Please investigate the stream-json output path to ensure stdout is flushed consistently and all events that are logged internally are also output to the stream.
What Should Happen?
Stream should continue until the SESSION_CLOSE is emitted.
Error Messages/Logs
Steps to Reproduce
Run
Command used
claude --dangerously-skip-permissions --output-format stream-json --verbose --print "<prompt>"
with a long-running prompt.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.3 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
iTerm2
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗