[BUG] --print --input-format stream-json --output-format stream-json: CLI stops writing to stdout while still recording assistant turns in the session JSONL
Claude Code version: 2.1.283 · OS: Linux 6.8 (Ubuntu, x86_64) · Runtime of the host app: Bun
Related
Looks like the same class of problem as #17248 (closed as duplicate of #8126, both closed in January 2026) — it still reproduces on 2.1.283.
What happens
We drive long-lived Claude Code sessions through claude --print --input-format stream-json --output-format stream-json --include-partial-messages --verbose with stdin/stdout as pipes (a web UI host relays frames). Occasionally a session goes silent on stdout: the host keeps reading the pipe, but no further stream-json frames arrive. Meanwhile the CLI keeps appending assistant records to its own transcript (~/.claude/projects/<slug>/<session>.jsonl) — i.e. the model turn completes, but the output is never emitted on stdout.
- Seen ~10–15 times per day across several concurrent sessions on one host (29 occurrences in the last 3 days).
- At detection time the transcript holds 3–9
assistantrecords newer than the last frame the host received. - The CLI process is alive;
/proc/<pid>/task/*/wchanshows threads infutex_wait_queue, none inpipe_write— so it is not blocked on a full stdout pipe; the host is still draining the pipe (other sessions' pipes keep flowing in the same event loop at the same moment). - Typical trigger: a session that sat idle (≈ 2 min – 3 h) receives a new user message on stdin; the turn runs and is persisted, but nothing is written to stdout.
- Recovery: killing the process and relaunching with
--resume <session>restores normal behaviour (the persisted turn is visible after resume).
Expected
Every turn persisted to the session transcript is also emitted on stdout as stream-json frames (or the CLI exits with an error).
Notes
- Transport is stdio (not
--sdk-url). - Happy to provide a sanitized sequence of frames / transcript excerpt for one occurrence if useful.