[BUG] Crashing on error: "Invalid string length"
Resolved 💬 5 comments Opened Jul 9, 2025 by Emasoft Closed Jan 5, 2026
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.44 (Claude Code)
- Operating System: macOS 15.3
- Terminal: iTerm2
Bug Description
While executing various tasks, Claude Code crashes suddenly and print this error message:
file:///Users/Emasoft/.nvm/versions/node/v22.13.1/lib/node_modules/@anthropic-ai/claude-code/cli.js:1567
`,signal:B,enablePromptCaching:!1,isNonInteractiveSession:Q,promptCategory:"command_injection"}),I=typeof D.message.content==="string"?D.message.content:Array.isArray(D.message.content)?D.message.content.find((Z)=>Z.type==="text")?.text??"none":"none";if(I.startsWith(EG))return E1("tengu_bash_prefix",{success:!1,error:"API error"}),null;if(I==="command_injection_detected")return E1("tengu_bash_prefix",{success:!1,commandInjectionDetected:!0}),{commandInjectionDetected:!0};if(I==="git")return E1("tengu_bash_prefix",{success:!1,error:'prefix "git"'}),{commandPrefix:null,commandInjectionDetected:!1};if(I==="none")return E1("tengu_bash_prefix",{success:!1,error:'prefix "none"'}),{commandPrefix:null,commandInjectionDetected:!1};if(!A.startsWith(I))return E1("tengu_bash_prefix",{success:!1,error:"command did not start with prefix"}),{commandPrefix:null,commandInjectionDetected:!1};return E1("tengu_bash_prefix",{success:!0}),{commandPrefix:I,commandInjectionDetected:!1}},(A)=>A),dM2=new Set(["&&","||",";",";;","|"]),Zw6=new Set([...dM2,">&",">"]);function Gw6(A){let B=fAA.parse(A.replaceAll('"',`"${xAA}`).replaceAll("'",`'${kAA}`),(Q)=>`$${Q}`);for(let Q=0;Q<B.length;Q++){let D=B[Q],I=B[Q+1];if(D===void 0)continue;if(typeof D==="string")continue;if("comment"in D)return!1;if("op"in D){if(D.op==="glob")continue;else if(dM2.has(D.op))continue;else if(D.op===">&"){if(I!==void 0&&typeof I==="string"&&Gc.has(I.trim()))continue}else if(D.op===">"){if(I!==void 0&&typeof I==="string"&&I.trim()==="/dev/null")continue;if(I!==void 0&&typeof I==="string"&&I.trim().startsWith("&")&&I.trim().length>1&&Gc.has(I.trim().slice(1)))continue}return!1}}return!0}function cM2(A){return Ik(A).length>1&&!Gw6(A)}class pM2{id;command;startTime;status;result;shellCommand;stdout="";stderr="";constructor(A,B,Q,D){this.id=A;this.command=B;this.status="running",this.startTime=Date.now(),this.shellCommand=Q,lA(`BackgroundShell ${A} created for command: ${B}`);let I=Q.background(A);if(!I)this.status="failed",this.result={code:1,interrupted:!1};else I.stdoutStream.on("data",(Z)=>{this.stdout+=Z.toString()}),I.stderrStream.on("data",(Z)=>{this.stderr+=Z.toString()}),Q.result.then((Z)=>{if(Z.code===0)this.status="completed";else this.status="failed";this.result={code:Z.code,interrupted:Z.interrupted},lA(`BackgroundShell ${A} completed with code ${Z.code} (interrupted: ${Z.interrupted})`),D(Z)})}getOutput(){let A={stdout:this.stdout,stderr:this.stderr};return this.stdout="",this.stderr="",A}hasNewOutput(){return!!this.stdout}kill(){try{return lA(`BackgroundShell ${this.id} kill requested`),this.shellCommand?.kill(),this.status="killed",!0}catch(A){return b1(A instanceof Error?A:new Error(String(A))),!1}}dispose(){this.shellCommand=null}}class Fc{static instance=null;shells=new Map;shellCounter=0;subscribers=new Set;constructor(){}static getInstance(){if(!Fc.instance)Fc.instance=new Fc;return Fc.instance}subscribe(A){return this.subscribers.add(A),()=>{this.subscribers.delete(A)}}notifySubscribers(){this.subscribers.forEach((A)=>{try{A()}catch(B){b1(B)}})}addBackgroundShell(A){return this.shells.set(A.id,A),this.notifySubscribers(),A.id}completeShell(A,B){let Q=this.shells.get(A);if(!Q)return;if(Q.status=B.code===0?"completed":"failed",lA(`Shell ${A} completed: status=${Q.status}, code=${B.code}, interrupted=${B.interrupted}`),B.code===143)lA(`Shell ${A} exited with code 143 (SIGTERM) - likely terminated by timeout or explicit kill`);Q.result={code:B.code,interrupted:B.interrupted},this.notifySubscribers()}getAllShells(){return Array.from(this.shells.values())}getActiveShells(){return Array.from(this.shells.values()).filter((A)=>A.status==="running")}getActiveShellCount(){return this.getActiveShells().length}getShell(A){return this.shells.get(A)}getShellOutput(A){let B=this.shells.get(A);if(!B)return{shellId:A,command:"",status:"failed",exitCode:null,stdout:"",stderr:"Shell not found"};let Q=B.result?B.result.code:null,{stdout:D,stderr:I}=B.getOutput();return{shellId:A,command:B.command,status:B.status,exitCode:Q,stdout:D.trimEnd(),stderr:I.trimEnd()}}getShellsUnreadOutputInfo(){return this.getActiveShells().map((A)=>{let B=A.hasNewOutput();return{id:A.id,command:A.command,hasNewOutput:B}})}removeShell(A){let B=this.shells.get(A);if(B){if(B.status==="running")B.kill(),B.dispose();let Q=this.shells.delete(A);return this.notifySubscribers(),Q}return!1}killShell(A){let B=this.shells.get(A);if(B&&B.status==="running")return lA(`Killing shell ${A} (command: ${B.command})`),B.kill(),setTimeout(()=>{if(this.shells.get(A))B.dispose()},1800000),this.notifySubscribers(),!0;return!1}moveToBackground(A,B){let Q=this.generateShellId();lA(`Moving command to background: ${A} (shellId: ${Q})`);let D=new pM2(Q,A,B,(I)=>{this.completeShell(D.id,I)});return this.addBackgroundShell(D),Q}generateShellId(){return`bash_${++this.shellCounter}`}}var pU=Fc.getInstance();var _T=Y1(U1(),1);function Yc({content:A,verbose:B}){let{stdout:Q,stderr:D,isImage:I,returnCodeInterpretation:Z}=A;if(I)return _T.default.createElement(P0,{height:1},_T.default.createElement(S,{color:"secondaryText"},"[Image data detected and sent to Claude]"));return _T.default.createElement(v,{flexDirection:"column"},Q!==""?_T.default.createElement(xU,{content:Q,verbose:B}):null,D!==""?_T.default.createElement(xU,{content:D,verbose:B,isError:!0}):null,Q===""&&D===""?_T.default.createElement(P0,{height:1},_T.default.createElement(S,{color:"secondaryText"},Z||"(No content)")):null)}import{isAbsolute as Yw6,resolve as Ww6}from"path";async function Fw6(A,B,Q,D){let I=B.join(" ").trim(),Z=await D({...A,command:I}),G=bAA(Q).every((C)=>{return y9.isReadOnly({...A,command:C.trim()})}),F=Q.join(" ").trim(),Y=G?{behavior:"allow",updatedInput:A,decisionReason:{type:"other",reason:"Pipe right-hand command is read-only"}}:{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,decisionReason:{type:"other",reason:"Pipe right-hand command is not read-only"}},W=new Map([[I,Z],[F,Y]]);if(Z.behavior==="deny")return{behavior:"deny",message:Z.message,decisionReason:{type:"subcommandResults",reasons:W},ruleSuggestions:null};if(Z.behavior==="allow"&&Y.behavior==="allow")return{behavior:"allow",updatedInput:A,decisionReason:{type:"subcommandResults",reasons:W}};let J=Y.behavior==="allow"?Z.behavior!=="allow"?Z.ruleSuggestions:void 0:null;return{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,decisionReason:{type:"subcommandResults",reasons:W},ruleSuggestions:J}}async function lM2(A,B){if(cM2(A.command))return{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,decisionReason:{type:"other",reason:"Unsupported shell control operator"},ruleSuggestions:null};let Q=vAA(A.command),D=Q.findIndex((I)=>I==="|");if(D>=0){let I=Q.slice(0,D),Z=Q.slice(D+1);return Fw6(A,I,Z,B)}return null}function gAA(A,B,Q,D){let I=Ik(A.command);for(let Z of I){let[G,...F]=Z.split(" ");if(G==="cd"&&F.length>0){let Y=F.join(" ").replace(/^['"]|['"]$/g,""),W=Yw6(Y)?Y:Ww6(B,Y);if(!CY(W,D))return{behavior:"ask",message:`cd to '${W}' was blocked. For security, ${o0} may only change directories to child directories of the allowed working directories for this session (including '${Q}').`}}}return{behavior:"allow",updatedInput:A}}var Jw6=(A)=>`${A}:*`;function lH1(A){return[{toolName:y9.name,ruleContent:A}]}function Cw6(A){return[{toolName:y9.name,ruleContent:Jw6(A)}]}var hAA=(A)=>{return A.match(/^(.+):\*$/)?.[1]??null};function Xw6(A){let B=hAA(A);if(B!==null)return{type:"prefix",prefix:B};else return{type:"exact",command:A}}function iM2(A,B,Q){let D=A.command.trim();return Array.from(B.entries()).filter(([I])=>{let Z=Xw6(I);switch(Z.type){case"exact":return Z.command===D;case"prefix":switch(Q){case"exact":return Z.prefix===D;case"prefix":return D.startsWith(Z.prefix)}}}).map(([,I])=>I)}function aM2(A,B,Q){let D=ub(B,y9,"deny"),I=iM2(A,D,Q),Z=ub(B,y9,"allow"),G=iM2(A,Z,Q);return{matchingDenyRules:I,matchingAllowRules:G}}var uAA=(A,B)=>{let Q=A.command.trim(),{matchingDenyRules:D,matchingAllowRules:I}=aM2(A,B,"exact");if(D[0]!==void 0)return{behavior:"deny",message:`Permission to use ${y9.name} with command ${Q} has been denied.`,decisionReason:{type:"rule",rule:D[0]},ruleSuggestions:null};if(I[0]!==void 0)return{behavior:"allow",updatedInput:A,decisionReason:{type:"rule",rule:I[0]}};if(y9.isReadOnly(A))return{behavior:"allow",updatedInput:A,decisionReason:{type:"other",reason:"Sandboxed command is allowed"}};return{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,ruleSuggestions:lH1(Q)}},rM2=(A,B)=>{let Q=A.command.trim();if(Q.split(" ")[0]==="cd"){if(gAA(A,uA(),w9(),B).behavior==="allow")return{behavior:"allow",updatedInput:A,decisionReason:{type:"other",reason:"cd command is allowed"}}}let D=uAA(A,B);if(D.behavior==="deny")return D;let{matchingDenyRules:I,matchingAllowRules:Z}=aM2(A,B,"prefix");if(I[0]!==void 0)return{behavior:"deny",message:`Permission to use ${y9.name} with command ${Q} has been denied.`,decisionReason:{type:"rule",rule:I[0]},ruleSuggestions:null};if(D.behavior==="allow")return D;if(Z[0]!==void 0)return{behavior:"allow",updatedInput:A,decisionReason:{type:"rule",rule:Z[0]}};return{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,ruleSuggestions:lH1(Q)}};function nM2(A,B,Q){let D=uAA(A,B);if(D.behavior==="deny")return D;if(D.behavior==="allow")return D;let I=rM2(A,B);if(I.behavior==="deny")return I;if(Q===null||Q===void 0)return{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,decisionReason:{type:"other",reason:"Command prefix query failed"},ruleSuggestions:lH1(A.command)};if(Q.commandInjectionDetected)return{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,decisionReason:{type:"other",reason:"Potential command injection detected"},ruleSuggestions:null};if(I.behavior==="allow")return I;let Z=Q.commandPrefix?Cw6(Q.commandPrefix):lH1(A.command);return{...I,ruleSuggestions:Z}}var mAA=async(A,B,Q=mM2)=>{let D=uAA(A,B.getToolPermissionContext());if(D.behavior==="deny")return D;let I=await lM2(A,(E)=>mAA(E,B,Q));if(I!==null)return I;let Z=Ik(A.command).filter((E)=>{if(E===`cd ${uA()}`)return!1;return!0});if(Z.filter((E)=>E.startsWith("cd ")).length>1)return{behavior:"ask",message:`Claude requested permissions to use ${y9.name}, but you haven't granted it yet.`,decisionReason:{type:"other",reason:"Multiple cd commands detected"},ruleSuggestions:null};let F=Z.map((E)=>rM2({command:E},B.getToolPermissionContext())),Y=['"',"'","`","$(","${","~[","(e:",`
RangeError: Invalid string length
at PassThrough.<anonymous> (file:///Users/Emasoft/.nvm/versions/node/v22.13.1/lib/node_modules/@anthropic-ai/claude-code/cli.js:1567:2149)
at PassThrough.emit (node:events:524:28)
at PassThrough.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 node:internal/streams/transform:178:12
at PassThrough._transform (node:internal/streams/passthrough:46:3)
at Transform._write (node:internal/streams/transform:171:8)
at writeOrBuffer (node:internal/streams/writable:572:12)
Node.js v22.13.1
Steps to Reproduce
- The bug happens just using Claude Code. It gives this error randomly while executing any task. Only one session of Claude Code was running, and in Bypass Permissions mode. It was not in plan mode, but in the default mode.
Expected Behavior
It should not crash.
Actual Behavior
it crashes with the error above.
Additional Context
Only one session of Claude Code was running, and in Bypass Permissions mode. It was not in plan mode, but in the default mode.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗