Claude code exited with RangeError: Invalid string length
file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:712),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 t9A(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=N0(async()=>{let A=cp(EB1),B=h1();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)=>lp(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=CC(vT4(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 id1(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 Rw1(A){let B=pJ2(A);return await CM().insertMessageChain(B),B[B.length-1]?.uuid||null}async function Ow1(A){await CM().insertMessageChain(pJ2(A),!0)}async function r9A(A){await CM().insertCheckpoint(A)}async function uJ2(){let A=CM();A.sessionFile=Mw1()}function hT4(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 gT4(A){return A.map((B)=>{let{isSidechain:Q,parentUuid:I,...D}=B;return D})}function mJ2(A,B=0,Q,I){let D=A[A.length-1],G=A[0],Z=hT4(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:gT4(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 dJ2(){let A=await CM().getAllTranscripts(),B=CM().summaries;return A.map((Q,I)=>{let D=Q[Q.length-1],G=D?B.get(D.uuid):void 0,Z=D?CM().getAllCheckpoints(Q):void 0;return mJ2(Q,I,G,Z)}).sort((Q,I)=>{return I.modified.getTime()-Q.modified.getTime()})}async function cJ2(A,B){await CM().appendEntry({type:"summary",summary:B,leafUuid:A})}async function o9A(A){let B=new Map,Q=new Map,I=new Map;try{let D=await id1(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 t9A(A){let B=lp(cp(cA()),${A}.jsonl);return o9A(B)}var uT4=N0(async(A)=>{let{messages:B,checkpoints:Q}=await t9A(A);return{messageSet:new Set(B.keys()),checkpointSet:new Set(Q.keys())}},(A)=>A);async function lJ2(A){let B=await CM().getLastLog(A);if(B!==null&&B!==void 0){let Q=B[B.length-1],{summaries:I,checkpoints:D}=await t9A(A),G=Q?I.get(Q.uuid):void 0;return mJ2(B,0,G,Array.from(D.values()))}return null}function pJ2(A){return A.filter((B)=>{if(B.type==="progress")return!1;if(B.type==="attachment"&&hJ2()!=="ant")return!1;return!0})}var Tw1=[],dT4=100;function cT4(A){return A.toISOString().replace(/[:.]/g,"-")}var BQA=cT4(new Date);function lT4(){return AQA(jw.errors(),BQA+".txt")}var e9A=!1;function v1(A){if(e9A)return;e9A=!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(_4(!1))console.error(A);let B=A.stack||A.message,Q={error:B,timestamp:new Date().toISOString()};if(Tw1.length>=dT4)Tw1.shift();Tw1.push(Q),pT4(lT4(),{error:B})}catch{}finally{e9A=!1}Lw1(A)}function iJ2(){return[...Tw1]}function QQA(A){if(!h1().existsSync(A))return[];try{return JSON.parse(h1().readFileSync(A,{encoding:"utf8"}))}catch{return[]}}function pT4(A,B){return}async function pp(){let A=await dJ2();return iT4(A.filter((B)=>B.messages.length)).map((B,Q)=>({...B,value:Q}))}async function nJ2(A){return await lJ2(A)}async function aJ2(A){return(await pp())[A]||null}function iT4(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 dD(A,B){if(X9(FA.red(MCP server "${A}" ${B})),(RQ()||{}).cleanupPeriodDays===0)return;try{let I=jw.mcpLogs(A),D=B instanceof Error?B.stack||B.message:String(B),G=new Date().toISOString(),Z=AQA(I,BQA+".txt");if(!h1().existsSync(I))h1().mkdirSync(I);if(!h1().existsSync(Z))h1().writeFileSync(Z,"[]",{encoding:"utf8",flush:!1});let F={error:D,timestamp:G,sessionId:OB(),cwd:h1().cwd()},Y=QQA(Z);Y.push(F),h1().writeFileSync(Z,JSON.stringify(Y,null,2),{encoding:"utf8",flush:!1})}catch{}}function S2(A,B){SA(MCP server "${A}": ${B});try{let Q=jw.mcpLogs(A),I=new Date().toISOString(),D=AQA(Q,BQA+".txt");if(!h1().existsSync(Q))h1().mkdirSync(Q);if(!h1().existsSync(D))h1().writeFileSync(D,"[]",{encoding:"utf8",flush:!1});let G={debug:B,timestamp:I,sessionId:OB(),cwd:h1().cwd()},Z=QQA(D);Z.push(G),h1().writeFileSync(D,JSON.stringify(Z,null,2),{encoding:"utf8",flush:!1})}catch{}}import*as jw1 from"node:os";import{PassThrough as aT4}from"stream";function VM(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 YD(A){let B=A>=1000;return new Intl.NumberFormat("en",{notation:"compact",minimumFractionDigits:B?1:0,maximumFractionDigits:1}).format(A).toLowerCase()}function sJ2(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:X}of F)if(Math.abs(Z)>=J){let C=Math.trunc(Z/J);if(Q==="narrow"&&J<86400)return Z<0?${Math.abs(C)}${X} ago:in ${C}${X};return new Intl.RelativeTimeFormat("en",{style:"long",numeric:I}).format(C,W)}if(Q==="narrow")return Z<=0?"0s ago":"in 0s";return new Intl.RelativeTimeFormat("en",{style:Q,numeric:I}).format(0,"second")}function IQA(A,B={}){let{now:Q=new Date,...I}=B;if(A>Q)return sJ2(A,{...I,now:Q});return sJ2(A,{...I,numeric:"always",now:Q})}function ip(A,B=!1){if(!A)return;let Q=new Date(A*1000),I=Q.getMinutes(),D=Q.toLocaleTimeString("en-US",{hour:"numeric",minute:I===0?void 0:"2-digit",hour12:!0}),G=Intl.DateTimeFormat().resolvedOptions().timeZone;return D.replace(/ ([AP]M)/i,(Z,F)=>F.toLowerCase())+(B? (${G}):"")}var GX2=F1(BX2(),1);class GQA{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 QX2=137,IX2=143;function DX2(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 aT4({highWaterMark:10485760}),B.write(I()),Q="",B}}}function ZX2(A,B,Q,I){let D="running",G,Z=DX2(A.stdout),F=DX2(A.stderr);if(I){let C=new GQA(10),V=0,K=(H)=>{let q=H.toString().split(
RangeError: Invalid string length
at Socket.<anonymous> (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:712:8701)
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)
Node.js v24.2.0
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗