Edit/Write tool changes silently reverted after Bash execution (vitest, build commands)

Resolved 💬 6 comments Opened Apr 2, 2026 by my-name-is-yu Closed Apr 10, 2026

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

  1. Read a source file with the Read tool
  2. Edit the file with the Edit tool (success reported, file-history-snapshot backup recorded)
  3. Run a Bash command: npm run build && npx vitest run
  4. Check with git diff --statempty (all changes gone)
  5. 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-snapshot backups are recorded (proving Edit executed)
  • git diff --stat shows changes immediately after Edit
  • After npx vitest run, git diff --stat returns 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

  1. Use sed -i or python via Bash instead of Edit/Write tools
  2. git add && git commit immediately after edits, before running any test commands
  3. 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.

View original on GitHub ↗

This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗