Windows: .claude.json repeatedly corrupted by concurrent non-atomic writes
Description
On Windows, ~/.claude.json gets corrupted on nearly every restart. Multiple claude.exe processes write to the same config file concurrently without file locking or atomic writes, causing a race condition that truncates/empties the file.
Steps to Reproduce
- Install Claude Code on Windows 11 (native install, version 2.1.59)
- Run
claudeand use it normally for a session - Exit the session (
/exitor close terminal) - Relaunch
claude - Error appears on startup:
````
Claude configuration file at C:\Users\<user>\.claude.json is corrupted: JSON Parse error: Unrecognized token ''
The corrupted file has already been backed up.
- Repeat steps 2-5 — the error occurs on nearly every restart.
Evidence
8 concurrent claude.exe processes observed via tasklist during a single session, all targeting the same ~/.claude.json.
47 corrupted snapshots accumulated in ~/.claude/backups/ in a single day, many within the same millisecond:
.claude.json.corrupted.1772128941435 77 bytes
.claude.json.corrupted.1772128941449 77 bytes
.claude.json.corrupted.1772128941450 77 bytes
.claude.json.corrupted.1772128941463 77 bytes
Corruption patterns
Truncated mid-write (trailing comma, no closing brace — 80 bytes):
{
"clientDataCache": {
"data": {},
"timestamp": 1772128933289
},
Partial write (only first key flushed — 77 bytes):
{
"clientDataCache": {
"data": {},
"timestamp": 1772129541144
}
}
The full valid config file is ~5KB with 38 top-level keys.
Suggested Fix
Use atomic writes: write JSON to a temporary file in the same directory, then fs.rename() over the target. On Windows, rename on the same volume is near-atomic and eliminates the truncate-then-write race. Alternatively, implement file locking via fs.open with exclusive flags or a lockfile to serialize concurrent writes.
Environment
- OS: Windows 11 Pro 10.0.22631
- Shell: Git Bash (bash.exe)
- Claude Code version: 2.1.59
- Install method: native
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗