.claude.json corrupted by concurrent writes; recovery loop spawns cascading agents producing hundreds of backup files
Summary
~/.claude.json is corrupted by concurrent writes when multiple Claude Code agents run in parallel. The corruption-detection/recovery path itself triggers new agent spawns that re-detect corruption, creating a cascading loop that produces hundreds of .corrupted.* backup files and floods the terminal with repeated error messages.
Environment
- Claude Code: 2.1.59
- OS: Windows 11 Pro (10.0.26200)
- Shell: Git Bash
- Platform: win32
Symptoms
- Corruption:
.claude.jsonbecomes invalid JSON. Error:JSON Parse error: Unrecognized token '' - Cascade: 3-4 agents appear to spin up simultaneously, each detecting corruption, each backing up the (already broken) file, producing a stream of dozens to hundreds of pasted error messages with backup paths
- Backup accumulation:
~/.claude/backups/fills with.corrupted.*files
Evidence
279 corrupted backup files accumulated over 7 days:
Day Corrupted files
2026-02-22 135
2026-02-27 67
2026-02-21 56
2026-02-26 20
2026-02-25 10
2026-02-23 2
2026-02-24 1
Burst pattern (multiple corruptions within the same minute):
78 files at 2026-02-22 06:33 (single minute!)
19 files at 2026-02-27 07:40
17 files at 2026-02-26 19:51
13 files at 2026-02-22 06:34
11 files at 2026-02-22 12:48
10 files at 2026-02-27 07:39
Hex dump of a 77-byte corrupted file shows null bytes mid-JSON (truncated concurrent write):
00000000: 7b0a 2020 2263 6c69 656e 7444 6174 6143 {. "clientDataC
00000010: 6163 6865 223a 207b 0a20 2020 2022 6461 ache": {. "da
00000020: 7461 223a 207b 0000 0000 0000 0000 0000 ta": {..........
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 0000 0000 0000 00 .............
Valid JSON truncated at byte 38, followed by 39 null bytes. This is a textbook concurrent-write race condition.
File size distribution of corrupted files shows wide variance (43 bytes to ~7KB), confirming writes are interrupted at arbitrary points:
27 files at 159 bytes
15 files at 256 bytes
11 files at 6995 bytes
10 files at 82 bytes
10 files at 43 bytes
9 files at 123 bytes
...
Root cause (likely)
- Multiple Claude Code processes (parallel agents, IDE instances, or subagents) read-modify-write
~/.claude.jsonwithout file locking - Concurrent writes produce truncated or null-padded JSON
- On next read, each process detects corruption, backs up the file, and resets it
- The reset triggers other processes to re-read, detect a different (now-reset) state, and re-enter the corruption recovery path
- This creates a feedback loop of backup-and-reset operations
Reproduction
- Run Claude Code with parallel agents (e.g.,
Tasktool spawning 3+ subagents, or multiple terminal sessions) - Wait for any two agents to update config state at overlapping times
- Observe corruption error and cascading backup creation
Expected behavior
- Writes to
~/.claude.jsonshould be atomic (write-to-temp + rename, or use file locking) - Corruption recovery should not trigger a cascade -- a single process should own recovery, others should wait or retry
- Backup files should be bounded (e.g., keep last 5, not accumulate hundreds)
Workaround
Manually restore from the most recent valid backup:
cp ~/.claude/backups/.claude.json.backup.<latest_timestamp> ~/.claude.jsonThis issue has 3 comments on GitHub. Read the full discussion on GitHub ↗