Repository navigation
[BUG] Edit tool silently no-ops on disk while Read returns the edited content (sub-agent worktrees + main session) #61471
Description
Preflight Checklist
- I have searched existing issues and this hasn't been reported yet
- This is a single bug report (please file separate reports for different bugs)
- I am using the latest version of Claude Code
What's Wrong?
Description:
The Edit tool returns success but the change is never written to disk. The Read tool subsequently returns the imagined post-edit content (an in-memory or cached view), but git status / git diff / awk / grep against the file all show the pre-edit content. The discrepancy is silent — no error, no warning.
What Should Happen?
Expected: Edit either persists the change OR errors loudly. Read should reflect on-disk state, not a hypothetical post-edit state.
Actual: Edit silently no-ops; Read returns stale (post-edit-in-memory) content; subsequent Bash commands see the unmodified file.
Frequency: ~8 incidents in one day across multiple sub-agent dispatches (~7 different isolation: "worktree" agents) plus once in the main session. Approx 30-50% hit rate on the first Edit of a session.
Expected: Edit either persists the change OR errors loudly. Read should reflect on-disk state, not a hypothetical post-edit state.
Actual: Edit silently no-ops; Read returns stale (post-edit-in-memory) content; subsequent Bash commands see the unmodified file.
Environment:
- Claude Code CLI 2.1.148
- Model: Opus 4.7 (1M context) — claude-opus-4-7[1m]
- macOS Darwin 25.4.0
- Multiple parallel sub-agents in isolation: "worktree" mode
- Project: Next.js 16 + TypeScript + git worktrees
Notes:
- The cached Read state survives across multiple Read calls in the same session — it's not a transient cache miss.
- The pattern is most prevalent in nested worktrees (sub-agent dispatched from a sub-agent).
- Suspected cause: the Edit tool's persistence layer may not be writing to the actual on-disk file when the agent's cwd is reported as one path but the harness has the file mounted at another (worktree mounting layer).
Error Messages/Logs
Steps to Reproduce
Steps to reproduce:
- Spawn a sub-agent with
Agent({ isolation: "worktree", ... })(also reproduces in the main session occasionally). - Have the agent run
Edit({ file_path: "/absolute/path/to/file.ts", old_string: "X", new_string: "Y" }). - Tool returns "The file ... has been updated successfully."
- Have the agent run
Read({ file_path: "/absolute/path/to/file.ts" })— returns content withY. - Have the agent run
Bash({ command: "git diff -- /absolute/path/to/file.ts" })— diff is empty. - Have the agent run
Bash({ command: "awk 'NR==<line>' /absolute/path/to/file.ts" })— prints the pre-editX.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
No response
Claude Code Version
2.1.148
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
No response
Activity
github-actions commentedon May 22, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
falaky commentedon May 22, 2026
Thanks for flagging the candidate duplicates. Reviewed each:
Keeping this open — happy to be marked as related-but-not-duplicate, since the macOS-CLI repro adds a distinct datapoint.
jshaofa-ui commentedon May 22, 2026
claude-code #61471: Edit Tool Silently No-ops on Disk While Read Returns Edited Content — Fix
Issue Summary
The Edit tool reports success and subsequent Read calls return the edited content (from memory/buffer), but the actual file on disk is never modified. This is a silent data integrity failure — the user and agent believe the edit succeeded when it did not.
Severity: Critical — silent data corruption, undermines trust in all edit operations
Labels: bug, has repro, area:tools, area:core
Competition: Zero
Root Cause Analysis
Primary Root Cause: Write-Ahead Buffer Without fsync Verification
The Edit tool likely follows this flow:
fs.writeFile()orfs.promises.writeFile()The failure occurs at step 3→4 boundary: the in-memory buffer is updated regardless of whether the disk write succeeded. Possible failure modes:
fs.writeFile()promise rejection is caught but not propagated — the catch block updates the buffer anywayFailure Pattern:
Why This Is Hard to Detect:
Proposed Fix
Fix 1: Post-Write Verification (Primary Fix)
File:
src/tools/edit-tool.ts(or equivalent)Fix 2: Atomic Write with Rollback
Fix 3: Error Propagation (No Silent Swallowing)
Fix 4: Cache Invalidation on Write Failure
Test Plan
Unit Tests
fs.writeFilerejection → verify error propagated, buffer NOT updatedIntegration Tests
Regression Tests
Risk Assessment
Overall Risk: LOW — all changes are defensive, additive, and improve correctness without changing the happy path.
References
fs.promises.writeFiledocs: https://nodejs.org/api/fs.html#fspromiseswritefilefile-data-optionsgithub-actions commentedon Jun 22, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Aug 25, 2026
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.