.claude.json corrupted by concurrent writes; recovery loop spawns cascading agents producing hundreds of backup files

Resolved 💬 3 comments Opened Feb 26, 2026 by dvdarkin Closed Feb 26, 2026

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

  1. Corruption: .claude.json becomes invalid JSON. Error: JSON Parse error: Unrecognized token ''
  2. 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
  3. 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)

  1. Multiple Claude Code processes (parallel agents, IDE instances, or subagents) read-modify-write ~/.claude.json without file locking
  2. Concurrent writes produce truncated or null-padded JSON
  3. On next read, each process detects corruption, backs up the file, and resets it
  4. The reset triggers other processes to re-read, detect a different (now-reset) state, and re-enter the corruption recovery path
  5. This creates a feedback loop of backup-and-reset operations

Reproduction

  1. Run Claude Code with parallel agents (e.g., Task tool spawning 3+ subagents, or multiple terminal sessions)
  2. Wait for any two agents to update config state at overlapping times
  3. Observe corruption error and cascading backup creation

Expected behavior

  • Writes to ~/.claude.json should 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.json

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗