[BUG] Invalid String Length
Resolved 💬 4 comments Opened Jul 2, 2025 by mr-ryan-james Closed Aug 20, 2025
Environment
- Platform (select one):
- [X] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.40 (Claude Code)
- Operating System: macOS node v24
- Terminal: terminal app
Bug Description
file:///Users/ryanpfister/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:626),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 jh1(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}getAllCheckpoints(A){let B=new Map,Q=A[A.length-1]?.sessionId;if(Q){let I=this.checkpoints.get(Q)?.values()||[];for(let G of I)B.set(G.commit,G)}return Array.from(B.values())}loadAllSessions=O0(async()=>{let A=tD1(Th1),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)=>kr(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=CK(pA6(Z,".jsonl"));if(!D)return{sessionId:D,sessionMessages:new Set};let Y=new Map,W=new Map,J=new Map;try{await B.stat(Z);for(let F of await Yj1(Z))if(F.type==="user"||F.type==="assistant"||F.type==="attachment"||F.type==="system")Y.set(F.uuid,F);else if(F.type==="summary"&&F.leafUuid)W.set(F.leafUuid,F.summary);else if(F.type==="checkpoint")J.set(F.commit,F)}catch{}return{sessionId:D,sessionMessages:Y,summaries:W,checkpoints:J}}));for(let{sessionId:Z,sessionMessages:D,summaries:Y,checkpoints:W}of G){if(!Z)continue;for(let[J,F]of D.entries())this.messages.set(J,F);for(let[J,F]of Y.entries())this.summaries.set(J,F);this.checkpoints.set(Z,Array.from(W.values()))}return this.didLoad=!0,this})}async function eD1(A){let B=qw0(A);return await bR().insertMessageChain(B),B[B.length-1]?.uuid||null}async function zw0(A){await bR().insertMessageChain(qw0(A),!0)}async function Sh1(A){await bR().insertCheckpoint(A)}function lA6(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 iA6(A){return A.map((B)=>{let{isSidechain:Q,parentUuid:I,...G}=B;return G})}function ww0(A,B=0,Q,I){let G=A[A.length-1],Z=A[0],D=lA6(A),Y=new Date(Z.timestamp),W=new Date(G.timestamp),J=I?.map((F)=>({commit:F.commit,timestamp:new Date(F.timestamp),label:F.label}));return{date:G.timestamp,messages:iA6(A),fullPath:"n/a",value:B,created:Y,modified:W,firstPrompt:D,messageCount:A.length,isSidechain:Z.isSidechain,leafUuid:G.uuid,summary:Q,checkpoints:J}}async function Ew0(){let A=await bR().getAllTranscripts(),B=bR().summaries;return A.map((Q,I)=>{let G=Q[Q.length-1],Z=G?B.get(G.uuid):void 0,D=G?bR().getAllCheckpoints(Q):void 0;return ww0(Q,I,Z,D)}).sort((Q,I)=>{return I.modified.getTime()-Q.modified.getTime()})}async function Uw0(A,B){await bR().appendEntry({type:"summary",summary:B,leafUuid:A})}async function _h1(A){let B=new Map,Q=new Map,I=new Map;try{let G=await Yj1(A);for(let Z of G)if(Z.type==="user"||Z.type==="assistant"||Z.type==="attachment"||Z.type==="system")B.set(Z.uuid,Z);else if(Z.type==="summary"&&Z.leafUuid)Q.set(Z.leafUuid,Z.summary);else if(Z.type==="checkpoint")I.set(Z.commit,Z)}catch{}return{messages:B,summaries:Q,checkpoints:I}}async function jh1(A){let B=kr(tD1(uA()),${A}.jsonl);return _h1(B)}var nA6=O0(async(A)=>{let{messages:B,checkpoints:Q}=await jh1(A);return{messageSet:new Set(B.keys()),checkpointSet:new Set(Q.keys())}},(A)=>A);async function Nw0(A){let B=await bR().getLastLog(A);if(B!==null&&B!==void 0){let Q=B[B.length-1],{summaries:I,checkpoints:G}=await jh1(A),Z=Q?I.get(Q.uuid):void 0;return ww0(B,0,Z,Array.from(G.values()))}return null}function qw0(A){return A.filter((B)=>{if(B.type==="progress")return!1;if(B.type==="attachment"&&Kw0()!=="ant")return!1;return!0})}var AY1=[],sA6=100;function rA6(A){return A.toISOString().replace(/[:.]/g,"-")}var xh1=rA6(new Date);function oA6(){return kh1(rz.errors(),xh1+".txt")}var yh1=!1;function h1(A){if(yh1)return;yh1=!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(AY1.length>=sA6)AY1.shift();AY1.push(Q),tA6(oA6(),{error:B})}catch{}finally{yh1=!1}oD1(A)}function $w0(){return[...AY1]}function vh1(A){if(!f1().existsSync(A))return[];try{return JSON.parse(f1().readFileSync(A,{encoding:"utf8"}))}catch{return[]}}function tA6(A,B){return}async function ph(){let A=await Ew0();return eA6(A.filter((B)=>B.messages.length)).map((B,Q)=>({...B,value:Q}))}async function Lw0(A){return await Nw0(A)}async function Mw0(A){return(await ph())[A]||null}function eA6(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 CI(A,B){if(F4(VA.red(MCP server "${A}" ${B})),j6().cleanupPeriodDays===0)return;try{let Q=rz.mcpLogs(A),I=B instanceof Error?B.stack||B.message:String(B),G=new Date().toISOString(),Z=kh1(Q,xh1+".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:b9(),cwd:f1().cwd()},Y=vh1(Z);Y.push(D),f1().writeFileSync(Z,JSON.stringify(Y,null,2),{encoding:"utf8",flush:!1})}catch{}}function v2(A,B){rA(MCP server "${A}": ${B});try{let Q=rz.mcpLogs(A),I=new Date().toISOString(),G=kh1(Q,xh1+".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:b9(),cwd:f1().cwd()},D=vh1(G);D.push(Z),f1().writeFileSync(G,JSON.stringify(D,null,2),{encoding:"utf8",flush:!1})}catch{}}import*as mh1 from"os";import{PassThrough as B06}from"stream";function wj(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 rI(A){let B=A>=1000;return new Intl.NumberFormat("en",{notation:"compact",minimumFractionDigits:B?1:0,maximumFractionDigits:1}).format(A).toLowerCase()}function Rw0(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 BY1(A,B={}){let{now:Q=new Date,...I}=B;if(A>Q)return Rw0(A,{...I,now:Q});return Rw0(A,{...I,numeric:"always",now:Q})}function ch(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 vw0=D1(jw0(),1),yw0=137,kw0=143;function xw0(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 B06({highWaterMark:10485760}),B.write(I()),Q="",B}}}function fw0(A,B,Q){let I="running",G,Z=xw0(A.stdout),D=xw0(A.stderr),Y=(X)=>{if(I="killed",A.pid)vw0.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=(H)=>{K(),C(H||yw0)},W=setTimeout(()=>{Y(kw0)},Q),A.on("close",(H,U)=>{C(H!==null&&H!==void 0?H: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===yw0,backgroundTaskId:G};if(C===kw0)K.stderr=[Command timed out after ${wj(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 bw0(A){return{background:()=>null,kill:()=>{},result:Promise.resolve({code:145,stdout:"",stderr:"Command aborted before execution",interrupted:!0,backgroundTaskId:A})}}var QY1=D1(Ql(),1);import{constants as Q06}from"fs";import*as gw0 from"os";import*as hw0 from"path";class mw0{profilePath;defaultProfile=(version 1) RangeError: Invalid string length at Socket.<anonymous> (file:///Users/ryanpfister/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:626:7941) at Socket.emit (node:events:507:28) 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)
Steps to Reproduce
- use claude code
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. -->
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗