.claude.json becomes corrupted (Unexpected EOF) during tool use — non-atomic config writes
Description
During normal tool use (Search, litSearch), .claude.json becomes corrupted — JSON parser hits Unexpected EOF, indicating the file was truncated mid-write.
Reproduction
- Run Claude Code on Windows with active tool calls (Search/litSearch)
- Config becomes corrupted during or around tool execution / permission prompts
- Error:
parse error: Unexpected EOF - Message:
.claude.json corrupted.<timestamp> - Auto-backup created at
C:\Users\Cassie\.claude\backups\.claude.json.backup.<timestamp> - Suggested restore command points to wrong path (
C:\Users\Cassie\.claude.jsoninstead of the actual config location)
Root Cause (Suspected)
Non-atomic config writes. The file is written in-place rather than using the safe pattern (write temp → fsync → rename). Possible triggers:
- Permission allowlist updates writing to config mid-operation
- Concurrent writes from multiple Claude sessions/processes
- Interruption mid-write (crash, kill, forced stop)
- Bun crashes (documented 29 times in 30 days on #21576) truncating in-progress writes
Expected Behavior
- Config writes should be atomic (write to temp file → fsync → rename)
- Concurrent writes should be locked (file lock or single-writer pattern)
- Permission prompt updates should not corrupt the config file
- Restore command should point to the correct path
Additional Context
This has occurred multiple times. On Feb 24 (documented on #21576 as repro 22), a Bun crash corrupted .claude.json with the same "JSON Parse error: Unexpected EOF" — mid-write truncation during crash. The auto-backup system saved us, but without it all user config (permissions, settings, allowlists) would be permanently lost.
The fact that this also happens during normal tool use (not just crashes) suggests the write pattern itself is unsafe, independent of Bun stability issues.
Environment: Claude Code v2.1.58, Windows 11 Pro Build 26200, Bun v1.3.10
This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗