[Bug] RangeError: Invalid String Length in Stream Processing
Bug Description
claude is terminating at: file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1772
RangeError: Invalid string length
at PassThrough.
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 1.0.95
- Feedback ID: 3d9d8896-9d5f-4ee0-a5d3-1d36489981cc
Errors
[]
+1
.nvm/versions/node/v24.0.2/lib/node_modules/@anthropic-ai/claude-code/cli.js:1452
- View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments`}var rr2=Q1(TK(),1);import{constants as XN6,readFileSync as FN6,existsSync as VN6}from"node:fs";var dK0=Q1(TK(),1);function cK0(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 mq6(A){let B=/'(?:[^'\\]|\\.)*\n(?:[^'\\]|\\.)*'/,Q=/"(?:[^"\\]|\\.)*\n(?:[^"\\]|\\.)*"/;return B.test(A)||Q.test(A)}function bj1(A,B=!0){if(cK0(A)||mq6(A)){let Z=`'${A.replace(/'/g,`'"'"'`)}'`;if(cK0(A))return Z;return B?`${Z} < /dev/null`:Z}if(B)return dK0.default.quote([A,"<","/dev/null"]);return dK0.default.quote([A])}function lK0(A){if(cK0(A))return!1;return!0}import{execSync as or2,spawn as KN6}from"node:child_process";import{isAbsolute as HN6,resolve as zN6}from"node:path";import*as tr2 from"node:os";import{PassThrough as cq6}from"stream";var yr2=Q1(Tr2(),1);class c31{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 Pr2=137,Sr2=143;function jr2(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 cq6({highWaterMark:10485760}),B.write(Z()),Q="",B}}}function kr2(A,B,Q,Z){let G="running",Y,I=jr2(A.stdout),W=jr2(A.stderr);if(Z){let K=new c31(10),H=0,z=(D)=>{let w=D.toString().split(`
RangeError: Invalid string length
at Socket.<anonymous> (file:///Users/damienking/.nvm/versions/node/v24.0.2/lib/node_modules/@anthropic-ai/claude-code/cli.js:1452:1678)
at Socket.emit (node:events:519:35)
at Socket.emit (node:domain:489:12)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)
+1
⏵⏵ bypass permissions on (shift+tab to cycle) · 1 background task ·? for shortcuts ◯
file:///Users/macbook/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:825
`);if(G!==-1){if(Z=A.substring(0,G),Z.length+1>B)return`${Z.substring(0,B-1)}…`;return`${Z}…`}}if(Z.length<=B)return Z;return`${Z.substring(0,B-1)}…`}function jg(A){if(A<60000){let G=(A/1000).toFixed(1);return`${G.endsWith(".0")?G.slice(0,-2):G}s`}let B=Math.floor(A/3600000),Q=Math.floor(A%3600000/60000),Z=(A%60000/1000).toFixed(1);if(B>0)return`${B}h ${Q}m ${Z}s`;if(Q>0)return`${Q}m ${Z}s`;return`${Z}s`}function rZ(A){let B=A>=1000;return new Intl.NumberFormat("en",{notation:"compact",minimumFractionDigits:B?1:0,maximumFractionDigits:1}).format(A).toLowerCase()}function oU1(A,B={}){let{style:Q="narrow",numeric:Z="always",now:G=new Date}=B,Y=A.getTime()-G.getTime(),I=Math.trunc(Y/1000),W=[{unit:"year",seconds:31536000,shortUnit:"y"},{unit:"month",seconds:2592000,shortUnit:"mo"},{unit:"week",seconds:604800,shortUnit:"w"},{unit:"day",seconds:86400,shortUnit:"d"},{unit:"hour",seconds:3600,shortUnit:"h"},{unit:"minute",seconds:60,shortUnit:"m"},{unit:"second",seconds:1,shortUnit:"s"}];for(let{unit:X,seconds:F,shortUnit:V}of W)if(Math.abs(I)>=F){let K=Math.trunc(I/F);if(Q==="narrow"&&F<86400)return I<0?`${Math.abs(K)}${V} ago`:`in ${K}${V}`;return new Intl.RelativeTimeFormat("en",{style:"long",numeric:Z}).format(K,X)}if(Q==="narrow")return I<=0?"0s ago":"in 0s";return new Intl.RelativeTimeFormat("en",{style:Q,numeric:Z}).format(0,"second")}function yg(A,B={}){let{now:Q=new Date,...Z}=B;if(A>Q)return oU1(A,{...Z,now:Q});return oU1(A,{...Z,numeric:"always",now:Q})}function _C(A,B=!1){if(!A)return;let Q=new Date(A*1000),Z=new Date,G=Q.getMinutes();if((Q.getTime()-Z.getTime())/3600000>24){let J={month:"short",day:"numeric",hour:"numeric",minute:G===0?void 0:"2-digit",hour12:!0};if(Q.getFullYear()!==Z.getFullYear())J.year="numeric";return Q.toLocaleString("en-US",J).replace(/ ([AP]M)/i,(F,V)=>V.toLowerCase())+(B?` (${Intl.DateTimeFormat().resolvedOptions().timeZone})`:"")}let I=Q.toLocaleTimeString("en-US",{hour:"numeric",minute:G===0?void 0:"2-digit",hour12:!0}),W=Intl.DateTimeFormat().resolvedOptions().timeZone;return I.replace(/ ([AP]M)/i,(J,X)=>X.toLowerCase())+(B?` (${W})`:"")}var X$A=A1(Y$A(),1);class r41{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 I$A=137,W$A=143;function J$A(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 KU9({highWaterMark:10485760}),B.write(Z()),Q="",B}}}function tU1(A,B,Q,Z){let G="running",Y,I=J$A(A.stdout),W=J$A(A.stderr);if(Z){let K=new r41(10),H=0,z=(D)=>{let E=D.toString().split(`
RangeError: Invalid string length
at Socket.<anonymous> (file:///Users/macbook/.nvm/versions/node/v20.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:825:2870)
at Socket.emit (node:events:531:35)
at Socket.emit (node:domain:488:12)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:191:23)
Node.js v20.16.0
This error still exists in 1.0.109
having the same issue, its almost unusable at this point. My version installed is 1.0.111
I was heavily handicapped by this issue, solved it for my case (thank god). Hopefully this works in your cases as well. GPT explained to me that it's because of a huge repository size and huge file sizes in the repository. I changed my node version to v18 (recommended on anthropic site and by GPT) and prompted claude with the crash error, explained my understanding of file size issue and had it check for safe cleanup options. Claude discovered a 37gb django backend server log and a bunch of other extra stuff. Brought my repo size from 58gb to 7ish. Sheeeeeesh! I updated claude.md to do a weekly cleanup too. Haven't had the crash error since.
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.