~/.claude.json corrupted by concurrent writes (race condition)
Bug Description
~/.claude.json is repeatedly corrupted with JSON Parse error: Unexpected EOF when multiple Claude Code sessions or agent subprocesses run concurrently. The file gets truncated mid-write due to a race condition — one process reads while another truncates to write, resulting in partial JSON.
Reproduction
- Run Claude Code with agent teams that spawn multiple subagents (e.g., using the Task tool with several parallel agents)
- The config file at
~/.claude.jsongets corrupted within minutes - Error on next session start:
````
Claude configuration file at C:\Users\Daddy\.claude.json is corrupted: JSON Parse error: Unexpected EOF
The corrupted file has been backed up to: C:\Users\Daddy\.claude\backups\.claude.json.corrupted.<timestamp>
Evidence
20 corruption events within a 10-minute window during a single session with parallel agents:
-rw-r--r-- 1 user 4955 Feb 26 06:16 .claude.json.corrupted.1772108193354
-rw-r--r-- 1 user 4955 Feb 26 06:16 .claude.json.corrupted.1772108196466
-rw-r--r-- 1 user 157 Feb 26 06:16 .claude.json.corrupted.1772108196481
-rw-r--r-- 1 user 469 Feb 26 06:16 .claude.json.corrupted.1772108219332
-rw-r--r-- 1 user 469 Feb 26 06:16 .claude.json.corrupted.1772108219351
-rw-r--r-- 1 user 469 Feb 26 06:16 .claude.json.corrupted.1772108219388
-rw-r--r-- 1 user 469 Feb 26 06:16 .claude.json.corrupted.1772108219409
-rw-r--r-- 1 user 193 Feb 26 06:16 .claude.json.corrupted.1772108219478
-rw-r--r-- 1 user 193 Feb 26 06:16 .claude.json.corrupted.1772108219507
-rw-r--r-- 1 user 846 Feb 26 06:19 .claude.json.corrupted.1772108353077
-rw-r--r-- 1 user 77 Feb 26 06:19 .claude.json.corrupted.1772108353092
-rw-r--r-- 1 user 1207 Feb 26 06:25 .claude.json.corrupted.1772108707057
-rw-r--r-- 1 user 1207 Feb 26 06:25 .claude.json.corrupted.1772108707077
-rw-r--r-- 1 user 1207 Feb 26 06:25 .claude.json.corrupted.1772108707095
-rw-r--r-- 1 user 1208 Feb 26 06:25 .claude.json.corrupted.1772108726572
-rw-r--r-- 1 user 77 Feb 26 06:25 .claude.json.corrupted.1772108726591
-rw-r--r-- 1 user 157 Feb 26 06:25 .claude.json.corrupted.1772108726607
-rw-r--r-- 1 user 3759 Feb 26 06:25 .claude.json.corrupted.1772108740654
-rw-r--r-- 1 user 157 Feb 26 06:25 .claude.json.corrupted.1772108740683
-rw-r--r-- 1 user 1895 Feb 26 06:26 .claude.json.corrupted.1772108803586
Note the varying file sizes (77–4955 bytes) — classic sign of truncation at different points during concurrent writes.
Expected Behavior
Concurrent Claude Code processes should be able to safely read/write ~/.claude.json without corrupting it.
Suggested Fix
Use atomic writes: write to a temporary file in the same directory, then rename() (which is atomic on both POSIX and Windows NTFS). This is the standard pattern for safe concurrent config file updates.
Alternatively, use OS-level file locking (flock on Linux/macOS, LockFileEx on Windows) to serialize access.
Environment
- OS: Windows 11 Enterprise 10.0.26200
- Shell: Git Bash
- Claude Code model: claude-opus-4-6
- Trigger: Spawning parallel agent teams via the Task tool (TeamCreate + multiple subagents)
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗