[BUG] RangeError: Invalid string length
Status Closed — not planned
Maintainer reply None cached
Activity 12 comments · opened May 5, 2025 · closed Jan 8, 2026
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Claude Code CLI
- Claude CLI version: <!-- output of
claude --version--> - Operating System: Ubuntu (likely Ubuntu server)
- Terminal: Standard Ubuntu terminal
Bug Description
The Claude Code CLI is repeatedly throwing "RangeError: Invalid string length" errors when attempting to process output from a command.
Steps to Reproduce
- Create or use an existing prompt file (claude_prompt.txt)
- Run the Claude CLI command with output redirection:
````
claude -p --verbose --output-format stream-json --dangerously-skip-permissions @claude_prompt.txt >> "transcript.log"
- Observe multiple "RangeError: Invalid string length" errors in stderr
Expected Behavior
The command should execute successfully, processing the prompt file and writing output to the specified log file without errors.
Actual Behavior
The CLI repeatedly throws the same error approximately 30+ times:
RangeError: Invalid string length
at Socket.<anonymous> (file:///home/ubuntu/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:550:2864)
at Socket.emit (node:events:524:28)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:191:23)
The error consistently occurs at the same line in the code, suggesting a systematic issue with string length handling in the CLI application.
12 Comments
As mentioned in #887, in my case, this was caused by a CLI call to a shell command that never exited.
Simple repro:
same error for me on macos.
playwright tests running crashes claude
Same crash.
crashes for me as well, WSL Ubuntu, running a unit test. My test was causing a tight loop, thats probably the cause.. ;) should be caught tho instead of crashing claude.
same thing here, multiple times in a row.. after starting it up again with --continue it crashes with exactly the same issue again after 2-3 commands. only using fresh session helps..
reproducing here also :
```
RangeError: Invalid string length
at Socket.<anonymous> (file:///Users/silouane/.nvm/versions/node/v22.15.1/lib/node_modules/@anthropic-ai/claude-code/cli.js:1431:1678)
at Socket.emit (node:events:530:35)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
node:internal/modules/cjs/loader:1401
const err = new Error(message);
^
Error: Cannot find module './yoga.wasm'
Require stack:
at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15)
at Function.resolve (node:internal/modules/helpers:145:19)
at file:///Users/silouane/.nvm/versions/node/v22.15.1/lib/node_modules/@anthropic-ai/claude-code/cli.js:772:22853
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/silouane/.nvm/versions/node/v22.15.1/lib/node_modules/@anthropic-ai/claude-code/cli.js'
]
}
This looks like an issue with the pipes used for handling output from invoked processes. When the CLI spawns a tool, its stdout/stderr streams are buffered into memory. If the process writes a large amount of data, those buffers can grow beyond safe limits, leading to the
RangeError: Invalid string length. So it’s not the model output itself, but how the CLI accumulates data from child process pipes.I’ve specifically seen this happen with the GetDiagnostics tool when connected to the IDE and there are a large number of diagnostic issues (linter, compiler, formatting errors, etc.). I’ve also reproduced it when running large test suites that produce very verbose output.
Also getting this error again and again:
/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1436
}var je2=A1(Lz(),1);import{constants as VP6,readFileSync as KP6,existsSync as HP6}from"node:fs";var gz0=A1(Lz(),1);function uz0(A){if(/\d\s*<<\s*\d/.test(A)||/\[\[\s*\d+\s*<<\s*\d+\s*\]\]/.test(A)||/\$\(\(.*<<.*\)\)/.test(A))return!1;return/<<-?\s*(?:(['"]?)(\w+)\1|\\(\w+))/.test(A)}function cT6(A){let B=/'(?:[^'\\]|\\.)*\n(?:[^'\\]|\\.)*'/,Q=/"(?:[^"\\]|\\.)*\n(?:[^"\\]|\\.)*"/;return B.test(A)||Q.test(A)}function Ik1(A,B=!0){if(uz0(A)||cT6(A)){let Z='${A.replace(/'/g,'"'"')}';if(uz0(A))return Z;return B?${Z} < /dev/null:Z}if(B)return gz0.default.quote([A,"<","/dev/null"]);return gz0.default.quote([A])}function mz0(A){if(uz0(A))return!1;return!0}import{execSync as ye2,spawn as zP6}from"node:child_process";import{isAbsolute as DP6,resolve as CP6}from"node:path";import*as ke2 from"node:os";import{PassThrough as pT6}from"stream";var Ke2=A1(Je2(),1);class rZ1{capacity;buffer;head=0;size=0;constructor(A){this.capacity=A;this.buffer=new Array(A)}add(A){if(this.buffer[this.head]=A,this.head=(this.head+1)%this.capacity,this.size<this.capacity)this.size++}addAll(A){for(let B of A)this.add(B)}getRecent(A){let B=[],Q=this.size<this.capacity?0:this.head,Z=Math.min(A,this.size);for(let G=0;G<Z;G++){let Y=(Q+this.size-Z+G)%this.capacity;B.push(this.buffer[Y])}return B}toArray(){if(this.size===0)return[];let A=[],B=this.size<this.capacity?0:this.head;for(let Q=0;Q<this.size;Q++){let Z=(B+Q)%this.capacity;A.push(this.buffer[Z])}return A}clear(){this.head=0,this.size=0}length(){return this.size}}var Xe2=137,Fe2=143;function Ve2(A){let B=null,Q="";A.on("data",(G)=>{if(B)B.write(G);else Q+=G});let Z=()=>Q;return{get:Z,asStream(){return B=new pT6({highWaterMark:10485760}),B.write(Z()),Q="",B}}}function He2(A,B,Q,Z){let G="running",Y,I=Ve2(A.stdout),W=Ve2(A.stderr);if(Z){let K=new rZ1(10),H=0,z=(D)=>{let w=D.toString().split(RangeError: Invalid string length
at Socket.<anonymous> (file:///Users/waleedzebkhan/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1436:1678)
at Socket.emit (node:events:530:35)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
Node.js v22.14.0
1.0.108 (Claude Code)
OS: MacOS 15.6.1
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.