Stack overflow crash from corrupted JSONL session files during concurrent writes
Resolved 💬 3 comments Opened Jan 26, 2026 by kokevidaurre Closed Jan 30, 2026
Description
Claude Code crashes with RangeError: Maximum call stack size exceeded when session JSONL files become corrupted due to concurrent write operations. The crash affects all terminal tabs simultaneously since they share the ~/.claude/projects/ directory.
Error
Exception in PromiseRejectCallback:
file:///.../@anthropic-ai/claude-code/cli.js:386
RangeError: Maximum call stack size exceeded
Root Cause Analysis
Investigated the crash and found multiple corrupted JSONL files in ~/.claude/projects/:
Error parsing line in .../7dd62e7b-....jsonl: SyntaxError: Unexpected token 'i', "ing/eng-cr"... is not valid JSON
Error parsing line in .../ad5c2bf3-....jsonl: SyntaxError: Unexpected token 'p', "pbi/gUEKpQ"... is not valid JSON
Corruption Pattern
Examining the corrupted files revealed out-of-order timestamps proving a race condition:
Line 495: "timestamp":"2026-01-07T15:15:13.853Z" ← valid JSON
Line 496: "timestamp":"2026-01-07T15:15:13.309Z" ← CORRUPTED (earlier timestamp, truncated mid-write)
Line 497: "timestamp":"2026-01-07T15:15:31.356Z" ← valid JSON
Line 496 contains a truncated base64 signature (pbi/gUEKpQ...) from the middle of a thinking block - the write was interrupted and the next write started on a new line.
Why It Happens
- Multiple Claude Code processes (main sessions + subagents) append to JSONL files concurrently
- Node.js file append operations are not atomic
- When writes interleave, one gets truncated mid-stream
- On next startup, JSON parser hits invalid data and something causes infinite recursion → stack overflow
Steps to Reproduce
- Run multiple Claude Code sessions on the same project directory
- Use heavy subagent workloads (Task tool spawning many agents)
- Eventually a write collision corrupts a JSONL file
- Restart Claude Code → crash
Environment
- Claude Code version: 2.1.14
- Node.js: v22.20.0
- Platform: macOS (Darwin 25.1.0)
Suggested Fixes
- Use file locking for JSONL appends (e.g.,
proper-lockfileorfs-ext) - Graceful error handling - skip corrupted lines instead of stack overflow
- Atomic writes - write to temp file, then rename
- Per-process session files - avoid shared append patterns
Workaround
Remove corrupted session files:
# Find and remove corrupted JSONL files
find ~/.claude/projects -name "*.jsonl" -type f -exec sh -c '
head -1 "$1" | jq . >/dev/null 2>&1 || echo "$1"
tail -1 "$1" | jq . >/dev/null 2>&1 || echo "$1"
' _ {} \; | sort -u | xargs rm -fThis issue has 3 comments on GitHub. Read the full discussion on GitHub ↗