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.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗