[BUG] CLI truncates a >~146 KB user message line on stdin when preceded by another NDJSON line (`--input-format stream-json`)

Resolved 💬 2 comments Opened May 13, 2026 by scottinet Closed Jun 18, 2026

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?

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 bytes | Outcome |
| --------------: | :------------------- |
| 146 174 | OK, result emitted |
| 146 184 | Parse error, exit 1 |
| 200 000 | Fails |
| 500 000 | Fails |

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

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗