Edit tool can silently wipe ~/.claude.json during a running session
Summary
During a running Claude Code CLI session, using the built-in Edit tool to modify ~/.claude.json caused the file to be silently wiped from ~800 lines (containing all MCP server configs, project metadata, session stats, OAuth data, cached feature flags, etc.) down to ~8 lines. No backup was created, no warning was issued, and no rollback was possible.
Steps to Reproduce
- Start a Claude Code CLI session (v2.1.38)
- Read
~/.claude.json(the CLI's internal config file) - Use the
Edittool to modify a section of the file (in this case, adding an entry to the top-levelmcpServersobject) - The edit is accepted and written to disk
- Within seconds, the file is overwritten — reduced to a minimal skeleton with almost all data lost
What Was Lost
- All MCP server configurations (user-scoped and project-local)
- All project metadata entries (trust dialog states, onboarding flags, session stats for ~12 projects)
- OAuth account cache
- Feature flag cache (
cachedGrowthBookFeatures) - Tips history
- All session cost/duration tracking data
Expected Behavior
At minimum, one of:
- The CLI should not allow its own Edit tool to modify
~/.claude.json(treat it as a protected file) - The CLI should create a backup before any write to this file
- The CLI should use file locking or atomic compare-and-swap to prevent data loss from concurrent writes
- The CLI should merge external changes rather than overwriting with potentially stale/minimal in-memory state
Environment
- Claude Code v2.1.38 (native install)
- macOS Darwin 25.2.0
- Model: claude-opus-4-6
Session Transcript
Full session transcript (JSONL) showing the exact sequence of events:
https://gist.github.com/mgmead/dcd8ae2b74f226a1b3bea08ad6f1465d
Recovery
MCP servers were re-added via claude mcp add-json --scope user. Project metadata will regenerate over time. But there is no way to recover the original file contents — the only reason the data was known at all is because it had been Read earlier in the same session that destroyed it.
Additional Context
The user was trying to move a google_workspace MCP entry from project-local scope to user scope — a reasonable config change. The claude mcp add-json command works correctly for this. The failure mode is that the Edit tool has no guardrails against modifying the CLI's own live config file, and the CLI's write behavior (whatever the mechanism) can silently destroy the file's contents.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗