Edit/Write tool changes silently reverted after Bash execution (vitest, build commands)
Description
Edit and Write tool changes are silently reverted after executing Bash commands (particularly test runners like npx vitest run). This affects both direct (Boss) edits and sub-agent edits. The issue is reproducible and has been forensically analyzed across 3 independent incidents in a single session.
Environment
- Claude Code v2.1.90 (also reproduced on v2.1.89)
- macOS Darwin 25.2.0
- Node.js 22, TypeScript project with vitest
- CLI mode (not desktop app)
Reproduction Steps
- Read a source file with the Read tool
- Edit the file with the Edit tool (success reported, file-history-snapshot backup recorded)
- Run a Bash command:
npm run build && npx vitest run - Check with
git diff --stat→ empty (all changes gone) - Verify with
grep→ file shows pre-edit content
Key Finding: vitest as Trigger
Across 3 incidents in one session, the common denominator was npx vitest run:
| Attempt | Write method | vitest run? | Changes persisted? |
|---------|-------------|-------------|-------------------|
| 1 | Sub-agent Edit tool | Yes | No |
| 2 | Boss direct Edit tool | Yes | No |
| 3a | Python open().write() via Bash | Yes | No |
| 3b | Python open().write() via Bash | No (build only) | Yes |
When npx vitest run was omitted (only npm run build), changes persisted. This suggests the test runner triggers CC's file cache re-synchronization, which overwrites disk with cached pre-edit content.
Evidence
- Edit tool returns "The file has been updated successfully"
file-history-snapshotbackups are recorded (proving Edit executed)git diff --statshows changes immediately after Edit- After
npx vitest run,git diff --statreturns empty - Even Python
open().write()via Bash (bypassing Edit tool entirely) gets reverted when vitest runs afterward - System-reminder "file was modified, either by the user or by a linter" sometimes appears
Workaround
- Use
sed -iorpythonvia Bash instead of Edit/Write tools git add && git commitimmediately after edits, before running any test commands- Do NOT run test suites between editing and committing
Related Issues
- #4462 — Sub-agents claim successful file creation but files don't persist
- #9458 — Sub-agent Write tool operations don't persist to filesystem (closed NOT_PLANNED)
- #3032 — Subagents reading outdated versions of files (closed NOT_PLANNED)
- #7443 — Edit tool fails with "File has been unexpectedly modified"
- #40227 — Desktop app Write/Edit report success but don't persist
Impact
This makes orchestration workflows (multi-agent code editing) unreliable. The only safe pattern is to avoid the Edit/Write tools for source files and use shell commands instead, which defeats the purpose of having dedicated file editing tools.
6 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Not a duplicate of the suggested issues. Key differences:
/compactused. The trigger isnpx vitest run, not compaction.Our issue has a unique, confirmed trigger: running
npx vitest runvia Bash after Edit/Write causes CC's file cache to overwrite disk. Omitting vitest (build only) makes changes persist. This is a different code path from compaction-triggered reverts.The forensic evidence (3 incidents, same session, controlled variable = vitest execution) is in the issue description.
We experienced the exact same bug independently during a long session on Linux.
No context compaction occurred — the conversation was within the context window the entire time.
Setup: Multiple fixes applied sequentially via Edit tool across ~15 files. Each fix was tested and verified with build commands.
Trigger: After launching sub-agents (via the Agent tool) that ran build/test commands, previously-applied edits in unrelated files were silently reverted to their pre-edit state.
Simplified reproduction:
Impact: ~4 hours of tested, validated fixes across 10+ files silently destroyed. ~2 additional hours debugging before understanding the scope. The system-reminder "file was modified, either by the user or by a linter" appeared multiple times.
Key observation: This happened 3+ times in our session. Any Bash execution (build, test) in the main conversation or in a sub-agent triggers the revert of all previously-edited files, including files the Bash command never touched.
Workaround:
git commitimmediately after edits, before running any build/test commands.Environment: Claude Code on Linux (Ubuntu 22.04), Opus model, long session (~8 hours), multi-language project.
Additional data point: Write tool also affected, git commit as workaround
Environment
New findings
1. Write tool (full file overwrite) is also affected — not just Edit
In a session with 5 parallel sub-agents editing different files, all Edit-based changes to existing files were silently reverted. We then switched to Write tool (full file replacement) — same result. Changes appeared in
git statusimmediately after Write, but were gone by the next tool call.| Write method | Existing file | New file | Persisted? |
|---|---|---|---|
| Edit tool | ✓ | — | ❌ Reverted |
| Write tool | ✓ | — | ❌ Reverted |
| Write tool | — | ✓ | ✅ Persisted |
| Bash
python3 open().write()| ✓ | — | ✅ Persisted |Key finding: New file creation via Write tool is NOT affected. Only overwrites of existing files are reverted.
2. Bash python3 writes persist — confirms file cache theory
Writing via
python3 -c "..."in Bash tool bypasses CC's file tracking entirely, so changes survive. This is consistent with the file cache re-sync theory from the original report.3. Immediate
git commitprevents revertEven when using Bash python3 to write, we found that committing immediately after each file write (
git add <file> && git commit) is necessary. Without commit, changes could still be lost if a subsequent Bash call (e.g.,npx vitest run) triggers the cache re-sync.Workaround (confirmed working)
This survived a full session with 8 files changed across 4 sub-agents.
it was because of my test codes, not Claude's.
closing the issue
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.