claude-code - 💡(How to fix) Fix Sequential edits to same file can silently drop first edit [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47858Fetched 2026-04-15 06:40:19
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×3commented ×2cross-referenced ×1

When making two rapid sequential edits to the same file, the first edit can be silently lost. The second edit succeeds, but the file state after both edits only reflects the second change.

Root Cause

When making two rapid sequential edits to the same file, the first edit can be silently lost. The second edit succeeds, but the file state after both edits only reflects the second change.

Fix Action

Workaround

Combine both changes into a single Edit call rather than making sequential edits to the same file.

RAW_BUFFERClick to expand / collapse

Description

When making two rapid sequential edits to the same file, the first edit can be silently lost. The second edit succeeds, but the file state after both edits only reflects the second change.

Reproduction

  1. Read a file
  2. Make an Edit to add an import line near the top of the file
  3. Immediately make a second Edit to add a registration call later in the same file
  4. The Edit tool reports: File has been modified since read, either by the user or by a linter. Read it again before attempting to write it.
  5. On re-read, the first edit (import line) is missing — only the original file content is present
  6. The second edit (registration call) was applied successfully

Environment

  • No linter, formatter, file watcher, or git hook is configured in the repo
  • No .eslintrc, prettier, biome, lint-staged, or husky configuration exists
  • No VS Code workspace settings or editor integrations active
  • The file was not modified by any external process

Expected behavior

Both edits should be applied, or the second edit should block/fail cleanly until the first edit is fully persisted.

Actual behavior

The first edit is silently dropped. The file-change detection fires between edits, and the intermediate state seen on re-read does not include the first edit. This causes unnecessary rework (re-applying the lost edit).

Workaround

Combine both changes into a single Edit call rather than making sequential edits to the same file.

extent analysis

TL;DR

Making sequential edits to the same file can cause the first edit to be silently lost, but combining both changes into a single Edit call can serve as a workaround.

Guidance

  • The issue seems to be related to the timing of the edits and the file-change detection mechanism, which fires between edits and causes the intermediate state to not include the first edit.
  • To verify this, try introducing a delay between the two edits to see if the first edit is persisted before the second edit is applied.
  • The workaround of combining both changes into a single Edit call can help avoid this issue, but it may not be feasible in all scenarios.
  • Consider reviewing the Edit tool's documentation to see if there are any configuration options or best practices for handling sequential edits.

Example

No code snippet is provided as the issue does not mention specific code or APIs.

Notes

The root cause of the issue is not explicitly stated, but it appears to be related to the interaction between the Edit tool and the file-change detection mechanism. The workaround provided may not be suitable for all use cases, and further investigation may be needed to determine a more robust solution.

Recommendation

Apply the workaround of combining both changes into a single Edit call, as it is a straightforward and effective way to avoid the issue, at least until a more permanent fix can be found.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Both edits should be applied, or the second edit should block/fail cleanly until the first edit is fully persisted.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING