.claude.json write race condition with multiple concurrent sessions (v2.1.59)
Bug Description
Running multiple Claude Code sessions simultaneously causes repeated .claude.json corruption with JSON Parse error: Unexpected EOF. This started with version 2.1.59 — the same multi-session setup (5 terminal windows) worked without issue on the prior version for over a week.
Environment
- Version: 2.1.59 (Claude Code)
- Platform: Windows 11 Pro (10.0.26200)
- Shell: Git Bash
- Install method: Native
- Sessions: 5-6 concurrent terminal sessions
Reproduction Steps
- Open Claude Code in a terminal
- While that session is running, open Claude Code in a second (or third, fourth, fifth) terminal
- The already-running sessions receive:
Claude configuration file at .claude.json is corrupted: JSON Parse error: Unexpected EOF
This happens reliably on every new session startup. The new session's startup write to .claude.json collides with background reads/writes from existing sessions.
Evidence
- 44+ corrupted backup files generated in a single ~45 minute window (10:52 AM – 11:46 AM)
- Corrupted files range from 77 bytes (nearly empty — file truncated immediately) to ~6,400 bytes (full content cut off mid-write)
- Corruption timestamps align precisely with new session start times:
- PID 33992 started at 11:33:03 → corruption burst at 11:33
- PID 41684 started at 11:34:15 → corruption burst at 11:34
- PID 37316 started at 11:35:29 → corruption burst at 11:35
- PID 39956 started at 11:45:56 → corruption burst at 11:46
- Some corrupted files show different
userIDvalues, confirming different sessions were writing concurrently - Zero corrupted backups exist from any date before today. The binary was updated on Feb 25 at 5:59 PM (to 2.1.59). The corruption started Feb 26 at 10:52 AM — first multi-session usage after the update.
Root Cause
Multiple claude.exe processes writing to the shared .claude.json file without file locking. The write pattern appears to truncate-then-write (standard file overwrite), which creates a window where other processes see an incomplete file. Each session writes on startup (feature flags, timestamps, client data cache) and periodically during operation (tool usage tracking, changelog fetch timestamps).
Impact
- Error messages appear in all running terminal sessions on each new session startup
- Auto-recovery works (Claude Code backs up the corrupted file and restores from a previous good copy), so no data loss occurs
- However, the repeated error messages are disruptive and the backup directory accumulates rapidly (44 files in 45 minutes)
Suggested Fix
Implement file locking (e.g., advisory lock or lockfile) around .claude.json reads and writes, or use an atomic write pattern (write to temp file, then rename).
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗