Configuration file (.claude.json) repeatedly corrupts during normal operation
Description
The user-level configuration file (~/.claude.json) repeatedly corrupts during normal Claude Code sessions. The corruption occurs without any manual editing of the file — it happens during standard CLI usage (e.g., after /clear, during thinking/processing phases).
Observed behavior
- Claude Code detects JSON parse errors on its own config file mid-session:
JSON Parse error: Unexpected EOFJSON Parse error: Unable to parse JSON string- Multiple corruption events fire in rapid succession (within seconds of each other)
- The tool automatically backs up the corrupted file and references a prior backup, but does not auto-restore
- The suggested manual restore command is provided each time:
````
cp "<backup-path>" "<config-path>"
- After restoring, the file corrupts again shortly after, suggesting a race condition or write issue rather than a one-off event
Expected behavior
The configuration file should not corrupt during normal operation. Writes to .claude.json should be atomic (write to temp file, then rename) to prevent partial writes from producing invalid JSON.
Environment
- OS: Windows 11 Pro (10.0.26200)
- Shell: Git Bash
- Platform: win32
- Node.js runtime: Standard system install
Reproduction
Difficult to reproduce on demand — it appears intermittently during regular CLI sessions. In this instance it triggered repeatedly after a /clear command while the CLI was in plan mode.
Possible root cause
Non-atomic file writes to .claude.json. If two writes overlap (e.g., concurrent config updates from different async operations), the file can end up with truncated or malformed JSON. This is especially likely on Windows where file operations may behave differently under concurrent access.
Suggested fix
- Use atomic writes (write to
.claude.json.tmp, thenfs.rename) - Add a write lock/queue to serialize config file updates
- Auto-restore from backup when corruption is detected, rather than requiring manual intervention
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗