claude-code - 💡(How to fix) Fix [BUG] CLI truncates a >~146 KB user message line on stdin when preceded by another NDJSON line (`--input-format stream-json`) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#58648Fetched 2026-05-14 03:42:54
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
1
Author
Participants
Timeline (top)
labeled ×5

Error Message

When claude is invoked with --input-format stream-json and receives two or more NDJSON lines back-to-back on a single stdin pipe where one of them exceeds ~146 KB, that long line is silently truncated before parsing. The CLI logs Error parsing streaming input line: … on stderr and exits with code 1 without ever processing the message.

Error Messages/Logs

Error parsing streaming input line: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa…aaaa Error parsing streaming input line: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa… (truncated) 3. Observe Error parsing streaming input line: … on stderr and exit code 1. | 146 184 | Parse error, exit 1 |

Root Cause

The bug is fully reproducible with node:child_process alone — no SDK required — but it affects 100% of @anthropic-ai/claude-agent-sdk consumers in practice, because the SDK always writes a control_request:initialize line before the first user message. As soon as a SDK consumer's first user prompt exceeds ~146 KB, the CLI errors out before the model is ever called.

Code Example

Error parsing streaming input line: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa…aaaa
aaaa…aaaa
aaaa…aaaa
exit: 1

# SDK debug log (with DEBUG_CLAUDE_AGENT_SDK=1) shows the same:
[ProcessTransport] Writing to stdin: {"request_id":"…","type":"control_request","request":{"subtype":"initialize",[ProcessTransport] Writing to stdin: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa…
[ProcessTransport] Write buffer full, data queued
Error parsing streaming input line: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa… (truncated)

---

import { spawn } from "node:child_process";

const SIZE = 146_050; // 146_040 passes, 146_050 fails — threshold reproducible to ±10 bytes
const text = "a".repeat(SIZE) + "\n\nReply OK";

const initMsg = JSON.stringify({
  request_id: "r1",
  type: "control_request",
  request: { subtype: "initialize" },
}) + "\n";

const userMsg = JSON.stringify({
  type: "user",
  message: { role: "user", content: [{ type: "text", text }] },
  parent_tool_use_id: null,
  session_id: "",
}) + "\n";

const child = spawn("claude", [
  "--output-format", "stream-json",
  "--verbose",
  "--input-format", "stream-json",
  "--setting-sources=user,project,local",
  "--permission-mode", "acceptEdits",
], { stdio: ["pipe", "pipe", "pipe"] });

child.stderr.on("data", d => process.stderr.write(d));
child.stdout.on("data", d => process.stdout.write(d));
child.on("exit", code => console.log("\nexit:", code));

child.stdin.write(initMsg);
child.stdin.write(userMsg);
child.stdin.end();

---

child.stdin.write(userMsg);   // userMsg.length = 2_000_000+
child.stdin.end();

---

{ printf '%s' "$initLine"; printf '%s' "$userLine"; } | claude --input-format stream-json …
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

When claude is invoked with --input-format stream-json and receives two or more NDJSON lines back-to-back on a single stdin pipe where one of them exceeds ~146 KB, that long line is silently truncated before parsing. The CLI logs Error parsing streaming input line: … on stderr and exits with code 1 without ever processing the message.

The bug is fully reproducible with node:child_process alone — no SDK required — but it affects 100% of @anthropic-ai/claude-agent-sdk consumers in practice, because the SDK always writes a control_request:initialize line before the first user message. As soon as a SDK consumer's first user prompt exceeds ~146 KB, the CLI errors out before the model is ever called.

Counter-experiments below show the trigger is specifically two writes through the Node stdin pipe, not the line size on its own — the same long line passes when written alone, or when piped via the shell.

What Should Happen?

The CLI should parse a NDJSON line of arbitrary size on stdin regardless of what other lines preceded it on the same pipe. The user message should be parsed correctly, the turn should run, and a result event should be emitted on stdout.

Error Messages/Logs

Error parsing streaming input line: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa…aaaa
aaaa…aaaa
aaaa…aaaa
exit: 1

# SDK debug log (with DEBUG_CLAUDE_AGENT_SDK=1) shows the same:
[ProcessTransport] Writing to stdin: {"request_id":"","type":"control_request","request":{"subtype":"initialize", …
[ProcessTransport] Writing to stdin: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa…
[ProcessTransport] Write buffer full, data queued
Error parsing streaming input line: {"type":"user","message":{"role":"user","content":[{"type":"text","text":"aaaa… (truncated)

Steps to Reproduce

  1. Save the script below as repro.mjs.
  2. Run DEBUG_CLAUDE_AGENT_SDK=1 node repro.mjs.
  3. Observe Error parsing streaming input line: … on stderr and exit code 1.
  4. Lower SIZE to 146_040 and re-run — it succeeds and a result event is printed.
import { spawn } from "node:child_process";

const SIZE = 146_050; // 146_040 passes, 146_050 fails — threshold reproducible to ±10 bytes
const text = "a".repeat(SIZE) + "\n\nReply OK";

const initMsg = JSON.stringify({
  request_id: "r1",
  type: "control_request",
  request: { subtype: "initialize" },
}) + "\n";

const userMsg = JSON.stringify({
  type: "user",
  message: { role: "user", content: [{ type: "text", text }] },
  parent_tool_use_id: null,
  session_id: "",
}) + "\n";

const child = spawn("claude", [
  "--output-format", "stream-json",
  "--verbose",
  "--input-format", "stream-json",
  "--setting-sources=user,project,local",
  "--permission-mode", "acceptEdits",
], { stdio: ["pipe", "pipe", "pipe"] });

child.stderr.on("data", d => process.stderr.write(d));
child.stdout.on("data", d => process.stdout.write(d));
child.on("exit", code => console.log("\nexit:", code));

child.stdin.write(initMsg);
child.stdin.write(userMsg);
child.stdin.end();

Threshold sweep (userMsg.length = total bytes of the line, with initMsg ~80 bytes preceding it):

userMsg bytesOutcome
146 174OK, result emitted
146 184Parse error, exit 1
200 000Fails
500 000Fails

With a larger preceding line, the threshold shifts down by roughly the same amount — consistent with a fixed-size internal line buffer.

Counter-experiments showing the trigger is the preceding line, not the line size itself:

a) Drop the initMsg write and write only userMsg → the same payload works up to multiple MB:

child.stdin.write(userMsg);   // userMsg.length = 2_000_000+
child.stdin.end();

b) Pipe both lines via the shell instead of via Node's child.stdin:

{ printf '%s' "$initLine"; printf '%s' "$userLine"; } | claude --input-format stream-json …

→ The same 147 KB user line is parsed correctly.

So the trigger is specifically: two writes through a single Node child_process stdin pipe, where the second write exceeds ~146 KB.

Claude Model

Not sure / Multiple models

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

Tested on 2.1.92, 2.1.126 and 2.1.128

Platform

Anthropic API

Operating System

Other Linux

Terminal/Shell

Non-interactive/CI environment

Additional Information

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] CLI truncates a >~146 KB user message line on stdin when preceded by another NDJSON line (`--input-format stream-json`) [1 participants]