[Bug] Unhandled Exception Causing Full Application Crash
Resolved 💬 8 comments Opened Sep 9, 2025 by ariccio Closed Jan 7, 2026
Bug Description
I encountered a full crash of claude code (dumping stack to stdout!) and now have isolated the failing case. The log of this conversation includes a minimal reproduction for you to use to make it easy to fix.
I ran this with opus 4.1.
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 1.0.109
- Feedback ID: 9689ae3e-92b7-4e87-bf37-1e32b98cc41e
Errors
[{"error":"Error: Request was aborted.\n at RT.makeRequest (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:980:3864)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","timestamp":"2025-09-09T01:01:29.661Z"},{"error":"SyntaxError: Unexpected token 'I', \"I apologiz\"... is not valid JSON\n at JSON.parse (<anonymous>)\n at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:733:9932\n at Q (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:713:13288)\n at at2 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1095:1982)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","timestamp":"2025-09-09T01:01:32.649Z"},{"error":"SyntaxError: Unexpected token 'I', \"I apologiz\"... is not valid JSON\n at JSON.parse (<anonymous>)\n at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:733:9932\n at Q (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:713:13288)\n at at2 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1095:1982)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","timestamp":"2025-09-09T01:01:53.772Z"},{"error":"Error: Request was aborted.\n at i61._createMessage (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:971:7955)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","timestamp":"2025-09-09T01:01:54.361Z"},{"error":"SyntaxError: Unexpected token 'I', \"I apologiz\"... is not valid JSON\n at JSON.parse (<anonymous>)\n at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:733:9932\n at Q (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:713:13288)\n at at2 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1095:1982)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","timestamp":"2025-09-09T01:02:32.591Z"}]
The original crash occurred at this toolcall:
⏺ Bash(cat > /tmp/debug-detect.ts << 'EOF'
const text = "This has an emoji in text 📝";
console.log("Text length:", text.length);
console.log("Checking each character:");
let index = 0;
for (const char of text) {
const codePoint = char.codePointAt(0);
console.log(`Index ${index}: '${char}' codepoint: ${codePoint?.toString(16) || 'undefined'}`);
index++;
}
EOF
npx ts-node /tmp/debug-detect.ts)
⎿ Waiting…
· Testing the implementation… (esc to interrupt · ctrl+t to show todos · 8s · ⚒ 3.1k tokens)
⎿ Next: Document the emoji checker implementation
Which dumped this stack:
Error: Bad substitution: codePoint?.toString
at D (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:79195)
at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:79854
at Array.map (<anonymous>)
at VX9 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:78933)
at Object.A (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:80018)
at nv6 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:31727)
at ov6 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:35696)
at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:36245
at Array.every (<anonymous>)
at $2B (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:36183)
Node.js v20.19.4
Exit status: 1
To reproduce, create a file like claude-crash-trigger-prompt.txt with the following content:
I'm trying to debug an issue with claude code itself. Claude code ran a specific toolcall and then dumped stack. I'm going to try to have you recreate it so I can file a bug report. For context, the stacktrace that it dumped was:
```
Error: Bad substitution: codePoint?.toString
at D (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:79195)
at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:79854
at Array.map (<anonymous>)
at VX9 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:78933)
at Object.A (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:80:80018)
at nv6 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:31727)
at ov6 (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:35696)
at file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:36245
at Array.every (<anonymous>)
at $2B (file:///Users/alexanderriccio/.nvm/versions/node/v20.19.4/lib/node_modules/@anthropic-ai/claude-code/cli.js:1741:36183)
```
Try and recreate the toolcall that I will paste after I submit this message.
Think very hard to CAREFULLY AND VERBOSELY explain, output, and document EVERY step you take. Since claude code WILL crash, I will need as much information as possible to collect later.
Please execute this exact Bash command using the Bash tool:
cat > /tmp/debug-detect.ts << 'EOF'
const text = "This has an emoji in text 📝";
console.log("Text length:", text.length);
console.log("Checking each character:");
let index = 0;
for (const char of text) {
const codePoint = char.codePointAt(0);
console.log(`Index ${index}: '${char}' codepoint: ${codePoint?.toString(16) || 'undefined'}`);
index++;
}
EOF
npx ts-node /tmp/debug-detect.ts
and invoke:
claude --verbose --debug --output-format stream-json --include-partial-messages --print < claude-crash-trigger-prompt.txt 2>&1
or
claude --verbose --debug --output-format stream-json --include-partial-messages --print < claude-crash-trigger-prompt.txt 2>&1 | tee claude-crash-output.log
The first results in the following output for me (the final few messages):
{"type":"stream_event","event":{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"}"}},"session_id":"d31c0e9e-2f01-49cc-8d98-b288f4c43e6b","parent_tool_use_id":"toolu_01JEB67jPtRQZ5jxyMz2pU2z","uuid":"09c8a557-2cfc-42ab-b6b6-8d4bd72d85a2"}
{"type":"assistant","message":{"id":"msg_01GZPWZmS7pvrC2Ef35ECn2K","type":"message","role":"assistant","model":"claude-opus-4-1-20250805","content":[{"type":"tool_use","id":"toolu_01JEB67jPtRQZ5jxyMz2pU2z","name":"Bash","input":{"command":"cat > /tmp/debug-detect.ts << 'EOF'\nconst text = \"This has an emoji in text 📝\";\n\nconsole.log(\"Text length:\", text.length);\nconsole.log(\"Checking each character:\");\n\nlet index = 0;\nfor (const char of text) {\n const codePoint = char.codePointAt(0);\n console.log(`Index ${index}: '${char}' codepoint: ${codePoint?.toString(16) || 'undefined'}`);\n index++;\n}\nEOF\n\nnpx ts-node /tmp/debug-detect.ts","description":"Create TypeScript file with emoji detection and run it"}}],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":4,"cache_creation_input_tokens":29957,"cache_read_input_tokens":4735,"cache_creation":{"ephemeral_5m_input_tokens":29957,"ephemeral_1h_input_tokens":0},"output_tokens":454,"service_tier":"standard"}},"parent_tool_use_id":null,"session_id":"d31c0e9e-2f01-49cc-8d98-b288f4c43e6b","uuid":"071b5fa0-d2a6-498a-a027-5863b64ee331"}
{"type":"stream_event","event":{"type":"content_block_stop","index":1},"session_id":"d31c0e9e-2f01-49cc-8d98-b288f4c43e6b","parent_tool_use_id":null,"uuid":"e772acc0-7917-4a06-a46f-bb5701d55115"}
{"type":"stream_event","event":{"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null},"usage":{"input_tokens":4,"cache_creation_input_tokens":29957,"cache_read_input_tokens":4735,"output_tokens":454}},"session_id":"d31c0e9e-2f01-49cc-8d98-b288f4c43e6b","parent_tool_use_id":null,"uuid":"b0b6b18e-61bd-4066-b986-695deba633e9"}
{"type":"stream_event","event":{"type":"message_stop"},"session_id":"d31c0e9e-2f01-49cc-8d98-b288f4c43e6b","parent_tool_use_id":null,"uuid":"f32e9c83-cac9-468d-b868-2cd24c3ec3e8"}
[DEBUG] Getting matching hook commands for SessionEnd with query: undefined
[DEBUG] Found 0 hook matchers in settings
[DEBUG] Matched 0 unique hooks for query "no match query" (0 before deduplication)
[DEBUG] Cleaned up session snapshot: /Users/alexanderriccio/.claude/shell-snapshots/snapshot-zsh-1757382610596-cha9xk.sh
[DEBUG] MCP server "railsMcpServer": UNKNOWN connection closed after 13s (cleanly)
Exit status: 1This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗