claude-code - 💡(How to fix) Fix Edit tool: fails when linter/formatter modifies file between Read and Edit

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…

Fix Action

Fix / Workaround

The user has no control over this timing, and the only workaround is to re-read the file and try again — which can loop if the formatter keeps running.

RAW_BUFFERClick to expand / collapse

Problem

The Edit tool fails with "File has been modified since read, either by the user or by a linter" when an auto-formatter or pre-commit hook modifies the file after Read but before Edit.

This is a race condition in any project with:

  • Format-on-save (Prettier, Black, isort, etc.)
  • Auto-fix ESLint rules
  • Editor auto-save with formatting

The user has no control over this timing, and the only workaround is to re-read the file and try again — which can loop if the formatter keeps running.

Impact

Workflow blocker for projects with auto-formatters. Observed consistently over 26+ days.

Suggested Fixes (any of these would help)

  1. Auto-re-read: When the modification is detected, automatically re-read the file and retry the match against the new content.
  2. Show what changed: Display a diff between expected and actual file content so the user can understand what the formatter did.
  3. Brief retry window: Wait 500ms after detecting a modification, re-read, and retry once before failing.

Option 1 would fully solve the problem. Option 2 would at least make debugging faster.

Environment

  • Claude Code CLI on Windows 11
  • VS Code with format-on-save enabled
  • Projects using Black, Prettier, and pre-commit hooks

extent analysis

TL;DR

Implementing an auto-re-read feature when a file modification is detected is the most likely fix to resolve the Edit tool failure due to race conditions with auto-formatters.

Guidance

  • Consider implementing Auto-re-read as suggested, which would automatically re-read the file and retry the match against the new content when a modification is detected.
  • Displaying a diff between expected and actual file content could help users understand what changes were made by the formatter, aiding in debugging.
  • Introducing a brief retry window of 500ms after detecting a modification, re-reading, and retrying once before failing could mitigate the issue.
  • Evaluate the feasibility of integrating with existing format-on-save tools (like Prettier, Black) and pre-commit hooks to synchronize or delay formatting until the Edit tool operation is complete.

Example

No specific code example is provided due to the lack of detailed implementation context, but the approach would involve detecting file modifications, re-reading the file, and retrying the edit operation.

Notes

The effectiveness of these suggestions may vary depending on the specific project setup, the speed of the auto-formatters, and the frequency of file modifications. Testing these approaches in a controlled environment before implementing them in production is recommended.

Recommendation

Apply the Auto-re-read workaround as it directly addresses the race condition issue by ensuring the Edit tool works with the most current version of the file, thus preventing failures due to modifications by auto-formatters or pre-commit hooks.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Edit tool: fails when linter/formatter modifies file between Read and Edit