Race condition: concurrent instances corrupt shared .claude.json config file
Description
When running two or more Claude Code instances simultaneously (e.g., in different project directories), the shared user-level config file ~/.claude.json gets corrupted due to a write race condition.
Steps to Reproduce
- Open two terminal windows in different project directories
- Launch Claude Code in both terminals
- Use both instances concurrently (run tools, have conversations)
- After some time, one or both instances show the error:
````
Claude configuration file at C:\Users\<user>\.claude.json is corrupted: JSON Parse error: Unexpected EOF
Expected Behavior
Concurrent Claude Code instances should safely read/write the shared config file without corruption. File locking or atomic writes should prevent race conditions.
Actual Behavior
Both instances write to ~/.claude.json simultaneously (updating toolUsage counters, cachedGrowthBookFeatures, clientDataCache, etc.). One instance truncates the file while the other is mid-write, resulting in a partial/invalid JSON file ("Unexpected EOF").
The corrupted file contents are typically a valid JSON that got cut off mid-write.
Workaround
Claude Code creates automatic backups, so restoring is possible:
cp ~/.claude/backups/.claude.json.backup.<timestamp> ~/.claude.json
Environment
- OS: Windows 11 Pro 10.0.26200
- Shell: Git Bash
- Claude Code version: 2.1.59
Suggested Fix
Consider one of:
- Atomic writes: Write to a temp file, then
rename()(atomic on most filesystems) - File locking: Use
flock/lockfileor OS-level advisory locks before writing - Per-project config separation: Move instance-specific state (like
toolUsage) out of the shared global file
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗