[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

  1. Create or use an existing prompt file (claude_prompt.txt)
  2. Run the Claude CLI command with output redirection:

``
claude -p --verbose --output-format stream-json --dangerously-skip-permissions @claude_prompt.txt >> "transcript.log"
``

  1. 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.

Additional Context

View original on GitHub ↗

12 Comments

slhck · 1 year ago

As mentioned in #887, in my case, this was caused by a CLI call to a shell command that never exited.

slhck · 1 year ago

Simple repro:

➜ claude -p "Run an infinitely looping shell command like 'yes' and capture its output. Do not use 'timeout' or 'head' or anything. Just call it." --dangerously-skip-permissions
deksden · 1 year ago

same error for me on macos.

playwright tests running crashes claude

pseudotensor · 1 year ago

Same crash.

file:///home/jon/.nvm/versions/node/v18.18.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:624
`),I.add(A.uuid)}}async getAllTranscripts(){await this.loadAllSessions();let A=[...this.messages.values()],B=new Set(A.map((Q)=>Q.parentUuid));return A.filter((Q)=>!B.has(Q.uuid)).map((Q)=>this.getTranscript(Q)).filter((Q)=>Q.length)}getTranscript(A){let B=[],Q=A;while(Q)B.unshift(Q),Q=Q.parentUuid?this.messages.get(Q.parentUuid):void 0;return B}async getLastLog(A){let{messages:B}=await Hf1(A);if(B.size===0)return null;let I=Array.from(B.values()).sort((D,Y)=>new Date(Y.timestamp).getTime()-new Date(D.timestamp).getTime())[0];if(!I)return null;let G=[],Z=I;while(Z)G.unshift(Z),Z=Z.parentUuid?B.get(Z.parentUuid):void 0;return G}loadAllSessions=_0(async()=>{let A=bG1(Cf1),B=b1();if(this.didLoad)return this;try{B.statSync(A)}catch{return this}let I=B.readdirSync(A).filter((Z)=>Z.isFile()&&Z.name.endsWith(".jsonl")).map((Z)=>Is(A,Z.name)),G=await Promise.all(I.sort((Z,D)=>{let Y=B.statSync(Z),W=B.statSync(D);return Y.mtime.getTime()-W.mtime.getTime()}).map(async(Z)=>{let D=lC(Og4(Z,".jsonl"));if(!D)return{sessionId:D,sessionMessages:new Set};let Y=new Map,W=new Map;try{await B.stat(Z);for(let J of await DB1(Z))if(J.type==="user"||J.type==="assistant"||J.type==="attachment"||J.type==="system")Y.set(J.uuid,J);else if(J.type==="summary"&&J.leafUuid)W.set(J.leafUuid,J.summary)}catch{}return{sessionId:D,sessionMessages:Y,summaries:W}}));for(let{sessionId:Z,sessionMessages:D,summaries:Y}of G){if(!Z)continue;this.sessionMessages.set(Z,new Set(D.keys()));for(let[W,J]of D.entries())this.messages.set(W,J);for(let[W,J]of Y.entries())this.summaries.set(W,J)}return this.didLoad=!0,this})}async function gG1(A){let B=yD0(A);return await $g().insertMessageChain(B),B[B.length-1]?.uuid||null}async function TD0(A){await $g().insertMessageChain(yD0(A),!0)}function Pg4(A){let B=A.find((G)=>G.type==="user");if(!B||B.type!=="user")return"No prompt";let Q=B.message?.content,I="";if(typeof Q==="string")I=Q;else if(Array.isArray(Q))I=Q.find((Z)=>Z.type==="text")?.text||"No prompt";else I="No prompt";if(I=I.replace(/\n/g," ").trim(),I.length>45)I=I.slice(0,45)+"...";return I}function Sg4(A){return A.map((B)=>{let{isSidechain:Q,parentUuid:I,...G}=B;return G})}function PD0(A,B=0,Q){let I=A[A.length-1],G=A[0],Z=Pg4(A),D=new Date(G.timestamp),Y=new Date(I.timestamp);return{date:I.timestamp,messages:Sg4(A),fullPath:"n/a",value:B,created:D,modified:Y,firstPrompt:Z,messageCount:A.length,isSidechain:G.isSidechain,leafUuid:I.uuid,summary:Q}}async function SD0(){let A=await $g().getAllTranscripts(),B=$g().summaries;return A.map((Q,I)=>{let G=Q[Q.length-1],Z=G?B.get(G.uuid):void 0;return PD0(Q,I,Z)}).sort((Q,I)=>{return I.modified.getTime()-Q.modified.getTime()})}async function _D0(A,B){await $g().appendEntry({type:"summary",summary:B,leafUuid:A})}async function Kf1(A){let B=new Map,Q=new Map;try{let I=await DB1(A);for(let G of I)if(G.type==="user"||G.type==="assistant"||G.type==="attachment"||G.type==="system")B.set(G.uuid,G);else if(G.type==="summary"&&G.leafUuid)Q.set(G.leafUuid,G.summary)}catch{}return{messages:B,summaries:Q}}async function Hf1(A){let B=Is(bG1(iA()),`${A}.jsonl`);return Kf1(B)}var _g4=_0(async(A)=>{let{messages:B}=await Hf1(A);return new Set(B.keys())},(A)=>A);async function jD0(A){let B=await $g().getLastLog(A);if(B!==null&&B!==void 0){let Q=B[B.length-1],{summaries:I}=await Hf1(A),G=Q?I.get(Q.uuid):void 0;return PD0(B,0,G)}return null}function yD0(A){return A.filter((B)=>{if(B.type==="progress")return!1;if(B.type==="attachment"&&RD0()!=="ant")return!1;return!0})}var hG1=[],yg4=100;function kg4(A){return A.toISOString().replace(/[:.]/g,"-")}var Ef1=kg4(new Date);function xg4(){return wf1(Sz.errors(),Ef1+".txt")}var zf1=!1;function d1(A){if(zf1)return;zf1=!0;try{if(process.env.CLAUDE_CODE_USE_BEDROCK||process.env.CLAUDE_CODE_USE_VERTEX||process.env.DISABLE_ERROR_REPORTING||process.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC)return;let B=A.stack||A.message,Q={error:B,timestamp:new Date().toISOString()};if(hG1.length>=yg4)hG1.shift();hG1.push(Q),vg4(xg4(),{error:B})}catch{}finally{zf1=!1}fG1(A)}function kD0(){return[...hG1]}function Uf1(A){if(!b1().existsSync(A))return[];try{return JSON.parse(b1().readFileSync(A,{encoding:"utf8"}))}catch{return[]}}function vg4(A,B){return}async function Mg(){let A=await SD0();return fg4(A.filter((B)=>B.messages.length)).map((B,Q)=>({...B,value:Q}))}async function xD0(A){return await jD0(A)}async function vD0(A){return(await Mg())[A]||null}function fg4(A){return A.sort((B,Q)=>{let I=Q.modified.getTime()-B.modified.getTime();if(I!==0)return I;let G=Q.created.getTime()-B.created.getTime();if(G!==0)return G;return B.created.getTime()-Q.created.getTime()})}function t7(A,B){if(m6(LA.red(`MCP server "${A}" ${B}`)),Q5().cleanupPeriodDays===0)return;try{let Q=Sz.mcpLogs(A),I=B instanceof Error?B.stack||B.message:String(B),G=new Date().toISOString(),Z=wf1(Q,Ef1+".txt");if(!b1().existsSync(Q))b1().mkdirSync(Q);if(!b1().existsSync(Z))b1().writeFileSync(Z,"[]",{encoding:"utf8",flush:!1});let D={error:I,timestamp:G,sessionId:h9(),cwd:b1().cwd()},Y=Uf1(Z);Y.push(D),b1().writeFileSync(Z,JSON.stringify(Y,null,2),{encoding:"utf8",flush:!1})}catch{}}function r2(A,B){v9(`MCP server "${A}": ${B}`);try{let Q=Sz.mcpLogs(A),I=new Date().toISOString(),G=wf1(Q,Ef1+".txt");if(!b1().existsSync(Q))b1().mkdirSync(Q);if(!b1().existsSync(G))b1().writeFileSync(G,"[]",{encoding:"utf8",flush:!1});let Z={debug:B,timestamp:I,sessionId:h9(),cwd:b1().cwd()},D=Uf1(G);D.push(Z),b1().writeFileSync(G,JSON.stringify(D,null,2),{encoding:"utf8",flush:!1})}catch{}}import*as Rf1 from"os";import{PassThrough as gg4}from"stream";function bD0(A,B){let Q=[],I="";for(let G of A)if([...I].length<B)I+=G;else Q.push(I),I=G;if(I)Q.push(I);return Q}function O_(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),I=(A%60000/1000).toFixed(1);if(B>0)return`${B}h ${Q}m ${I}s`;if(Q>0)return`${Q}m ${I}s`;return`${I}s`}function hG(A){let B=A>=1000;return new Intl.NumberFormat("en",{notation:"compact",minimumFractionDigits:B?1:0,maximumFractionDigits:1}).format(A).toLowerCase()}function fD0(A,B={}){let{style:Q="narrow",numeric:I="always",now:G=new Date}=B,Z=A.getTime()-G.getTime(),D=Math.trunc(Z/1000),Y=[{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:J,seconds:F,shortUnit:X}of Y)if(Math.abs(D)>=F){let V=Math.trunc(D/F);if(Q==="narrow"&&F<86400)return D<0?`${Math.abs(V)}${X} ago`:`in ${V}${X}`;return new Intl.RelativeTimeFormat("en",{style:"long",numeric:I}).format(V,J)}if(Q==="narrow")return D<=0?"0s ago":"in 0s";return new Intl.RelativeTimeFormat("en",{style:Q,numeric:I}).format(0,"second")}function Nf1(A,B={}){let{now:Q=new Date,...I}=B;if(A>Q)return fD0(A,{...I,now:Q});return fD0(A,{...I,numeric:"always",now:Q})}function Lg(A,B=!1){if(!A)return;let Q=new Date(A*1000),I=Q.getMinutes(),G=Q.toLocaleTimeString("en-US",{hour:"numeric",minute:I===0?void 0:"2-digit",hour12:!0}),Z=Intl.DateTimeFormat().resolvedOptions().timeZone;return G.replace(/ ([AP]M)/i,(D,Y)=>Y.toLowerCase())+(B?` (${Z})`:"")}var nD0=Y1(pD0(),1),cD0=137,lD0=143;function iD0(A){let B=null,Q="";A.on("data",(G)=>{if(B)B.write(G);else Q+=G});let I=()=>Q;return{get:I,asStream(){return B=new gg4({highWaterMark:10485760}),B.write(I()),Q="",B}}}function aD0(A,B,Q){let I="running",G,Z=iD0(A.stdout),D=iD0(A.stderr),Y=(X)=>{if(I="killed",A.pid)nD0.default(A.pid,"SIGKILL")},W=null,J,F=new Promise((X)=>{let V=()=>Y();J=()=>{if(W)clearTimeout(W),W=null;B.removeEventListener("abort",V)},B.addEventListener("abort",V,{once:!0}),new Promise((C)=>{let K=Y;Y=(z)=>{K(),C(z||cD0)},W=setTimeout(()=>{Y(lD0)},Q),A.on("close",(z,U)=>{C(z!==null&&z!==void 0?z:U==="SIGTERM"?144:1)}),A.on("error",()=>C(1))}).then((C)=>{if(J(),I==="running")I="completed";let K={code:C,stdout:Z.get(),stderr:D.get(),interrupted:C===cD0,backgroundTaskId:G};if(C===lD0)K.stderr=[`Command timed out after ${O_(Q)}`,K.stderr].filter(Boolean).join(" ");X(K)})});return{background:(X)=>{if(I==="running")return G=X,I="backgrounded",J(),{stdoutStream:Z.asStream(),stderrStream:D.asStream()};else return null},kill:()=>Y(),result:F}}function sD0(A){return{background:()=>null,kill:()=>{},result:Promise.resolve({code:145,stdout:"",stderr:"Command aborted before execution",interrupted:!0,backgroundTaskId:A})}}var mG1=Y1(Tc(),1);import{constants as hg4}from"fs";import*as rD0 from"os";import*as oD0 from"path";class tD0{profilePath;defaultProfile=`(version 1)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

RangeError: Invalid string length
    at Socket.<anonymous> (file:///home/jon/.nvm/versions/node/v18.18.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:624:7437)
    at Socket.emit (node:events:517:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Node.js v18.18.0
IvanBohannon · 1 year ago

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.

heiningair · 1 year ago

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..

file:///home/heiningair/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:643
`),I.add(A.uuid)}}async getAllTranscripts(){await this.loadAllSessions();let A=[...this.messages.values()],B=new Set(A.map((Q)=>Q.parentUuid));return A.filter((Q)=>!B.has(Q.uuid)).map((Q)=>this.getTranscript(Q)).filter((Q)=>Q.length)}getTranscript(A){let B=[],Q=A;while(Q)B.unshift(Q),Q=Q.parentUuid?this.messages.get(Q.parentUuid):void 0;return B}async getLastLog(A){let{messages:B}=await ca1(A);if(B.size===0)return null;let I=Array.from(B.values()).sort((Z,F)=>new Date(F.timestamp).getTime()-new Date(Z.timestamp).getTime())[0];if(!I)return null;let D=[],G=I;while(G)D.unshift(G),G=G.parentUuid?B.get(G.parentUuid):void 0;return D}getAllCheckpoints(A){let B=new Map,Q=A[A.length-1]?.sessionId;if(Q){let I=this.checkpoints.get(Q)?.values()||[];for(let D of I)B.set(D.commit,D)}return Array.from(B.values())}loadAllSessions=U0(async()=>{let A=Fd(ie),B=b1();if(this.didLoad)return this;try{B.statSync(A)}catch{return this}let I=B.readdirSync(A).filter((G)=>G.isFile()&&G.name.endsWith(".jsonl")).map((G)=>Yd(A,G.name)),D=await Promise.all(I.sort((G,Z)=>{let F=B.statSync(G),Y=B.statSync(Z);return F.mtime.getTime()-Y.mtime.getTime()}).map(async(G)=>{let Z=iJ(_gQ(G,".jsonl"));if(!Z)return{sessionId:Z,sessionMessages:new Set};let F=new Map,Y=new Map,W=new Map;try{await B.stat(G);for(let J of await Pv1(G))if(J.type==="user"||J.type==="assistant"||J.type==="attachment"||J.type==="system")F.set(J.uuid,J);else if(J.type==="summary"&&J.leafUuid)Y.set(J.leafUuid,J.summary);else if(J.type==="checkpoint")W.set(J.commit,J)}catch{}return{sessionId:Z,sessionMessages:F,summaries:Y,checkpoints:W}}));for(let{sessionId:G,sessionMessages:Z,summaries:F,checkpoints:Y}of D){if(!G)continue;for(let[W,J]of Z.entries())this.messages.set(W,J);for(let[W,J]of F.entries())this.summaries.set(W,J);this.checkpoints.set(G,Array.from(Y.values()))}return this.didLoad=!0,this})}async function uX1(A){let B=Vl0(A);return await E$().insertMessageChain(B),B[B.length-1]?.uuid||null}async function mX1(A){await E$().insertMessageChain(Vl0(A),!0)}async function ma1(A){await E$().insertCheckpoint(A)}async function Yl0(){let A=E$();A.sessionFile=hX1()}function ygQ(A){let B=A.find((D)=>D.type==="user");if(!B||B.type!=="user")return"No prompt";let Q=B.message?.content,I="";if(typeof Q==="string")I=Q;else if(Array.isArray(Q))I=Q.find((G)=>G.type==="text")?.text||"No prompt";else I="No prompt";if(I=I.replace(/\n/g," ").trim(),I.length>45)I=I.slice(0,45)+"...";return I}function kgQ(A){return A.map((B)=>{let{isSidechain:Q,parentUuid:I,...D}=B;return D})}function Wl0(A,B=0,Q,I){let D=A[A.length-1],G=A[0],Z=ygQ(A),F=new Date(G.timestamp),Y=new Date(D.timestamp),W=I?.map((J)=>({commit:J.commit,timestamp:new Date(J.timestamp),label:J.label}));return{date:D.timestamp,messages:kgQ(A),fullPath:"n/a",value:B,created:F,modified:Y,firstPrompt:Z,messageCount:A.length,isSidechain:G.isSidechain,leafUuid:D.uuid,summary:Q,checkpoints:W,gitBranch:D.gitBranch}}async function Jl0(){let A=await E$().getAllTranscripts(),B=E$().summaries;return A.map((Q,I)=>{let D=Q[Q.length-1],G=D?B.get(D.uuid):void 0,Z=D?E$().getAllCheckpoints(Q):void 0;return Wl0(Q,I,G,Z)}).sort((Q,I)=>{return I.modified.getTime()-Q.modified.getTime()})}async function Cl0(A,B){await E$().appendEntry({type:"summary",summary:B,leafUuid:A})}async function da1(A){let B=new Map,Q=new Map,I=new Map;try{let D=await Pv1(A);for(let G of D)if(G.type==="user"||G.type==="assistant"||G.type==="attachment"||G.type==="system")B.set(G.uuid,G);else if(G.type==="summary"&&G.leafUuid)Q.set(G.leafUuid,G.summary);else if(G.type==="checkpoint")I.set(G.commit,G)}catch{}return{messages:B,summaries:Q,checkpoints:I}}async function ca1(A){let B=Yd(Fd(lA()),`${A}.jsonl`);return da1(B)}var fgQ=U0(async(A)=>{let{messages:B,checkpoints:Q}=await ca1(A);return{messageSet:new Set(B.keys()),checkpointSet:new Set(Q.keys())}},(A)=>A);async function Xl0(A){let B=await E$().getLastLog(A);if(B!==null&&B!==void 0){let Q=B[B.length-1],{summaries:I,checkpoints:D}=await ca1(A),G=Q?I.get(Q.uuid):void 0;return Wl0(B,0,G,Array.from(D.values()))}return null}function Vl0(A){return A.filter((B)=>{if(B.type==="progress")return!1;if(B.type==="attachment"&&Zl0()!=="ant")return!1;return!0})}var dX1=[],vgQ=100;function bgQ(A){return A.toISOString().replace(/[:.]/g,"-")}var ia1=bgQ(new Date);function ggQ(){return pa1(AU.errors(),ia1+".txt")}var la1=!1;function v1(A){if(la1)return;la1=!0;try{if(process.env.CLAUDE_CODE_USE_BEDROCK||process.env.CLAUDE_CODE_USE_VERTEX||process.env.DISABLE_ERROR_REPORTING||process.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC)return;if(z6(!1))console.error(A);let B=A.stack||A.message,Q={error:B,timestamp:new Date().toISOString()};if(dX1.length>=vgQ)dX1.shift();dX1.push(Q),hgQ(ggQ(),{error:B})}catch{}finally{la1=!1}gX1(A)}function Kl0(){return[...dX1]}function na1(A){if(!b1().existsSync(A))return[];try{return JSON.parse(b1().readFileSync(A,{encoding:"utf8"}))}catch{return[]}}function hgQ(A,B){return}async function Wd(){let A=await Jl0();return ugQ(A.filter((B)=>B.messages.length)).map((B,Q)=>({...B,value:Q}))}async function El0(A){return await Xl0(A)}async function Hl0(A){return(await Wd())[A]||null}function ugQ(A){return A.sort((B,Q)=>{let I=Q.modified.getTime()-B.modified.getTime();if(I!==0)return I;let D=Q.created.getTime()-B.created.getTime();if(D!==0)return D;return B.created.getTime()-Q.created.getTime()})}function sI(A,B){if(G9(FA.red(`MCP server "${A}" ${B}`)),(NQ()||{}).cleanupPeriodDays===0)return;try{let I=AU.mcpLogs(A),D=B instanceof Error?B.stack||B.message:String(B),G=new Date().toISOString(),Z=pa1(I,ia1+".txt");if(!b1().existsSync(I))b1().mkdirSync(I);if(!b1().existsSync(Z))b1().writeFileSync(Z,"[]",{encoding:"utf8",flush:!1});let F={error:D,timestamp:G,sessionId:$B(),cwd:b1().cwd()},Y=na1(Z);Y.push(F),b1().writeFileSync(Z,JSON.stringify(Y,null,2),{encoding:"utf8",flush:!1})}catch{}}function j2(A,B){fA(`MCP server "${A}": ${B}`);try{let Q=AU.mcpLogs(A),I=new Date().toISOString(),D=pa1(Q,ia1+".txt");if(!b1().existsSync(Q))b1().mkdirSync(Q);if(!b1().existsSync(D))b1().writeFileSync(D,"[]",{encoding:"utf8",flush:!1});let G={debug:B,timestamp:I,sessionId:$B(),cwd:b1().cwd()},Z=na1(D);Z.push(G),b1().writeFileSync(D,JSON.stringify(Z,null,2),{encoding:"utf8",flush:!1})}catch{}}import*as pX1 from"node:os";import{PassThrough as dgQ}from"stream";function H$(A){if(A<60000){let D=(A/1000).toFixed(1);return`${D.endsWith(".0")?D.slice(0,-2):D}s`}let B=Math.floor(A/3600000),Q=Math.floor(A%3600000/60000),I=(A%60000/1000).toFixed(1);if(B>0)return`${B}h ${Q}m ${I}s`;if(Q>0)return`${Q}m ${I}s`;return`${I}s`}function HI(A){let B=A>=1000;return new Intl.NumberFormat("en",{notation:"compact",minimumFractionDigits:B?1:0,maximumFractionDigits:1}).format(A).toLowerCase()}function zl0(A,B={}){let{style:Q="narrow",numeric:I="always",now:D=new Date}=B,G=A.getTime()-D.getTime(),Z=Math.trunc(G/1000),F=[{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:W,seconds:J,shortUnit:C}of F)if(Math.abs(Z)>=J){let X=Math.trunc(Z/J);if(Q==="narrow"&&J<86400)return Z<0?`${Math.abs(X)}${C} ago`:`in ${X}${C}`;return new Intl.RelativeTimeFormat("en",{style:"long",numeric:I}).format(X,W)}if(Q==="narrow")return Z<=0?"0s ago":"in 0s";return new Intl.RelativeTimeFormat("en",{style:Q,numeric:I}).format(0,"second")}function aa1(A,B={}){let{now:Q=new Date,...I}=B;if(A>Q)return zl0(A,{...I,now:Q});return zl0(A,{...I,numeric:"always",now:Q})}function Jd(A,B=!1){if(!A)return;let Q=new Date(A*1000),I=new Date;if((Q.getTime()-I.getTime())/3600000>24){let W=Q.toLocaleDateString("en-US",{weekday:"short"}),J=Intl.DateTimeFormat().resolvedOptions().timeZone;return{resetTimeDisplay:"on "+W+(B?` (${J})`:""),isWeeklyLimit:!0}}let Z=Q.getMinutes(),F=Q.toLocaleTimeString("en-US",{hour:"numeric",minute:Z===0?void 0:"2-digit",hour12:!0}),Y=Intl.DateTimeFormat().resolvedOptions().timeZone;return{resetTimeDisplay:"at "+F.replace(/ ([AP]M)/i,(W,J)=>J.toLowerCase())+(B?` (${Y})`:""),isWeeklyLimit:!1}}var Tl0=F1(Ll0(),1);class ra1{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,I=Math.min(A,this.size);for(let D=0;D<I;D++){let G=(Q+this.size-I+D)%this.capacity;B.push(this.buffer[G])}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 I=(B+Q)%this.capacity;A.push(this.buffer[I])}return A}clear(){this.head=0,this.size=0}length(){return this.size}}var Ml0=137,Rl0=143;function Ol0(A){let B=null,Q="";A.on("data",(D)=>{if(B)B.write(D);else Q+=D});let I=()=>Q;return{get:I,asStream(){return B=new dgQ({highWaterMark:10485760}),B.write(I()),Q="",B}}}function Pl0(A,B,Q,I){let D="running",G,Z=Ol0(A.stdout),F=Ol0(A.stderr);if(I){let X=new ra1(10),V=0,K=(H)=>{let q=H.toString().split(`
RangeError: Invalid string length
    at Socket.<anonymous> (file:///home/heiningair/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:643:8969)
    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)
silouone · 1 year ago

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)


`The CLI tried to buffer unlimited data in memory, injected by mistake through a path in the prompt`. So ... size limit implementation & error handling is wrong ?


------- 

// looking into it , just foudn the second part related to https://github.com/anthropics/claude-code/issues/1103
Weird stuff start here, it happened to me 4 times already, claude-cli break. then I can't restart it , Can't install it back without cleaning the existing one, location issue. THis is a scneario like Corrupted installation: 

The crash left the Claude Code installation in a broken state, with the yoga.wasm file missing or inaccessible.

the link trace: 

node:internal/modules/cjs/loader:1401
const err = new Error(message);
^

Error: Cannot find module './yoga.wasm'
Require stack:

  • /Users/silouane/.nvm/versions/node/v22.15.1/lib/node_modules/@anthropic-ai/claude-code/cli.js

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'
]
}


Claude Code CLI 
    ↓
Ink (React for terminals)
    ↓
yoga-layout-prebuilt (npm package)
    ↓
yoga.wasm (WebAssembly binary)



if anyone reproduced smth like that 🤷‍♂️  the package corruption. Don't really understand how the 2 are links, or even if they are at all, but 4 times begin to not sound like a coincidence. 
gabewillen · 1 year ago

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.

waleedzeb · 11 months ago

Also getting this error again and again:

/.nvm/versions/node/v22.14.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1436

  • View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments}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

github-actions[bot] · 8 months ago

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.

github-actions[bot] · 7 months ago

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.

github-actions[bot] · 7 months ago

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.