Race condition: concurrent instances corrupt shared .claude.json config file

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

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

  1. Open two terminal windows in different project directories
  2. Launch Claude Code in both terminals
  3. Use both instances concurrently (run tools, have conversations)
  4. 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/lockfile or OS-level advisory locks before writing
  • Per-project config separation: Move instance-specific state (like toolUsage) out of the shared global file

View original on GitHub ↗

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