~/.claude.json corrupts repeatedly on Windows, silently wiping user-scope mcpServers
What happens
On Windows, ~/.claude.json is periodically corrupted and rewritten. Claude Code saves the damaged copy as .claude.json.corrupted.<epoch> and then continues with a config whose user-scope mcpServers is empty, silently dropping configured MCP servers (in my case: gitlab, playwright, ssh).
Evidence (my machine)
- 45
.claude.json.corrupted.*files accumulated between 2026-04-11 and 2026-07-01 (corruption on 13 distinct days). - 4 of them are 0 bytes; the rest range up to ~90 KB.
- The current live
.claude.jsonhasmcpServers: {}, while a 2026-06-26 backup clearly contains{ssh, gitlab, playwright}.
Impact
Silent loss of configured MCP servers (and potentially other user config) with no warning surfaced in the UI. Recovery requires manually digging through the .corrupted.* backups and re-adding each server.
Environment
- OS: Windows 11 (10.0.26200.8655)
- Claude Code: 2.1.198
Suspected cause
Non-atomic / concurrent writes to the single large (~90 KB) monolithic ~/.claude.json. A crash or an overlapping write mid-serialize truncates the file (hence the 0-byte and partial copies), and the fallback path then proceeds from defaults, dropping mcpServers.
Suggested fixes
- Atomic write for
~/.claude.json(write to a temp file +rename), so a partial write never replaces the good file. - On parse failure, auto-restore
mcpServersfrom the last known-good backup instead of silently starting empty. - Surface a warning in the UI when a corrupted config is detected and a
.corrupted.*backup is written, so the loss isn't silent.