[BUG] Unexpected crash with 'RangeError: Invalid string length'

Resolved 💬 3 comments Opened Jun 23, 2025 by monkey-w1n5t0n Closed Aug 21, 2025

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 1.0.31 <!-- output of claude --version -->
  • Operating System: Ubuntu 22.04 <!-- e.g. macOS 14.3, Windows 11, Ubuntu 22.04 -->
  • Terminal: Alacritty <!-- e.g. iTerm2, Terminal App -->

Bug Description

<!-- A clear and concise description of the bug -->

Claude code crashed randomly with the following output:

● Good! The build is now successful and most tests are passing. There are only 2 failing test cases with 3 failing assertions. Let's examine these specific
  failures:

  1. result == Value::atom(String("nil")) in test_atoms.cpp:23
  2. !(result1.is_error()) in test_atoms.cpp:28 - "evaluated empty list"
  3. !(result.is_error()) in test_evaluation.cpp:79

  Let me check these specific test failures:

● Read(test/interpreter/basic/test_atoms.cpp)
  ⎿  Read 15 lines (ctrl+r to expand)

● Read(test/interpreter/basic/test_evaluation.cpp)
  ⎿  Read 10 lines (ctrl+r to expand)

● The issues seem to be:

  1. Line 23: The test expects nil to evaluate to an atom, but it's probably evaluating to a proper nil value type
  2. Line 28: :keyword evaluation is failing (it's returning an error)
  3. Line 79: Empty list () evaluation is failing (it's returning an error)

  These are likely actual interpreter behavior issues rather than test conversion problems. The tests are revealing that some core functionality isn't working as
  expected in the interpreter. Let me check what nil actually evaluates to:

  Bash(cd builddir && echo "nil" | ./repl)
  ⎿  Running…

* Soaring… (21s · ⚒ 9.0k tokens · esc to interrupt)

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ >                                                                                                                                                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  ⏵⏵ auto-accept edits on (shift+tab to cycle)


file:///home/w1n5t0n/.claude/local/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 vf1(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=O0(async()=>{let A=$G1(xf1),B=f1();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)=>aa(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=fC(nx4(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 c81(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 qG1(A){let B=VZ0(A);return await Fg().insertMessageChain(B),B[B.length-1]?.uuid||null}async function YZ0(A){await Fg().insertMessageChain(VZ0(A),!0)}function sx4(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 rx4(A){return A.map((B)=>{let{isSidechain:Q,parentUuid:I,...G}=B;return G})}function WZ0(A,B=0,Q){let I=A[A.length-1],G=A[0],Z=sx4(A),D=new Date(G.timestamp),Y=new Date(I.timestamp);return{date:I.timestamp,messages:rx4(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 JZ0(){let A=await Fg().getAllTranscripts(),B=Fg().summaries;return A.map((Q,I)=>{let G=Q[Q.length-1],Z=G?B.get(G.uuid):void 0;return WZ0(Q,I,Z)}).sort((Q,I)=>{return I.modified.getTime()-Q.modified.getTime()})}async function FZ0(A,B){await Fg().appendEntry({type:"summary",summary:B,leafUuid:A})}async function ff1(A){let B=new Map,Q=new Map;try{let I=await c81(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 vf1(A){let B=aa($G1(dA()),`${A}.jsonl`);return ff1(B)}var ox4=O0(async(A)=>{let{messages:B}=await vf1(A);return new Set(B.keys())},(A)=>A);async function XZ0(A){let B=await Fg().getLastLog(A);if(B!==null&&B!==void 0){let Q=B[B.length-1],{summaries:I}=await vf1(A),G=Q?I.get(Q.uuid):void 0;return WZ0(B,0,G)}return null}function VZ0(A){return A.filter((B)=>{if(B.type==="progress")return!1;if(B.type==="attachment"&&ZZ0()!=="ant")return!1;return!0})}var MG1=[],ex4=100;function Af4(A){return A.toISOString().replace(/[:.]/g,"-")}var hf1=Af4(new Date);function Bf4(){return gf1(qz.errors(),hf1+".txt")}var bf1=!1;function b1(A){if(bf1)return;bf1=!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(MG1.length>=ex4)MG1.shift();MG1.push(Q),Qf4(Bf4(),{error:B})}catch{}finally{bf1=!1}NG1(A)}function CZ0(){return[...MG1]}function mf1(A){if(!f1().existsSync(A))return[];try{return JSON.parse(f1().readFileSync(A,{encoding:"utf8"}))}catch{return[]}}function Qf4(A,B){return}async function Xg(){let A=await JZ0();return If4(A.filter((B)=>B.messages.length)).map((B,Q)=>({...B,value:Q}))}async function KZ0(A){return await XZ0(A)}async function HZ0(A){return(await Xg())[A]||null}function If4(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 m7(A,B){if(q6(UA.red(`MCP server "${A}" ${B}`)),v5().cleanupPeriodDays===0)return;try{let Q=qz.mcpLogs(A),I=B instanceof Error?B.stack||B.message:String(B),G=new Date().toISOString(),Z=gf1(Q,hf1+".txt");if(!f1().existsSync(Q))f1().mkdirSync(Q);if(!f1().existsSync(Z))f1().writeFileSync(Z,"[]",{encoding:"utf8",flush:!1});let D={error:I,timestamp:G,sessionId:v9(),cwd:f1().cwd()},Y=mf1(Z);Y.push(D),f1().writeFileSync(Z,JSON.stringify(Y,null,2),{encoding:"utf8",flush:!1})}catch{}}function c2(A,B){L9(`MCP server "${A}": ${B}`);try{let Q=qz.mcpLogs(A),I=new Date().toISOString(),G=gf1(Q,hf1+".txt");if(!f1().existsSync(Q))f1().mkdirSync(Q);if(!f1().existsSync(G))f1().writeFileSync(G,"[]",{encoding:"utf8",flush:!1});let Z={debug:B,timestamp:I,sessionId:v9(),cwd:f1().cwd()},D=mf1(G);D.push(Z),f1().writeFileSync(G,JSON.stringify(D,null,2),{encoding:"utf8",flush:!1})}catch{}}import*as if1 from"os";import{PassThrough as Zf4}from"stream";function wZ0(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 K_(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 _G(A){let B=A>=1000;return new Intl.NumberFormat("en",{notation:"compact",minimumFractionDigits:B?1:0,maximumFractionDigits:1}).format(A).toLowerCase()}function zZ0(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 df1(A,B={}){let{now:Q=new Date,...I}=B;if(A>Q)return zZ0(A,{...I,now:Q});return zZ0(A,{...I,numeric:"always",now:Q})}function Vg(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 TZ0=I1(MZ0(),1),LZ0=137,RZ0=143;function OZ0(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 Zf4({highWaterMark:10485760}),B.write(I()),Q="",B}}}function PZ0(A,B,Q){let I="running",G,Z=OZ0(A.stdout),D=OZ0(A.stderr),Y=(X)=>{if(I="killed",A.pid)TZ0.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=(E)=>{K(),C(E||LZ0)},W=setTimeout(()=>{Y(RZ0)},Q),A.on("close",(E,N)=>{C(E!==null&&E!==void 0?E:N==="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===LZ0,backgroundTaskId:G};if(C===RZ0)K.stderr=[`Command timed out after ${K_(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 SZ0(A){return{background:()=>null,kill:()=>{},result:Promise.resolve({code:145,stdout:"",stderr:"Command aborted before execution",interrupted:!0,backgroundTaskId:A})}}var LG1=I1(Uc(),1);import{constants as Df4}from"fs";import*as _Z0 from"os";import*as jZ0 from"path";class yZ0{profilePath;defaultProfile=`(version 1)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

RangeError: Invalid string length
    at Socket.<anonymous> (file:///home/w1n5t0n/.claude/local/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:368:12)
    at readableAddChunk (node:internal/streams/readable:341:9)
    at Readable.push (node:internal/streams/readable:278:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Node.js v18.19.1

Steps to Reproduce

  1. <!-- First step -->
  2. <!-- Second step -->
  3. <!-- And so on... -->

Expected Behavior

<!-- What you expected to happen -->

Actual Behavior

<!-- What actually happened -->

Additional Context

<!-- Add any other context about the problem here, such as screenshots, logs, etc. -->

View original on GitHub ↗

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