[BUG] Edit tool gets stuck targeting wrong file in a loop (path contamination)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When generating Edit tool calls, the model repeatedly targets the wrong file path (a recently-edited file) instead of the intended file, even though its text output correctly states the intended target. It retries the same failing call 15+ times without self-correcting, despite receiving "No changes to make" errors each time.
What Should Happen?
The Edit tool should target the file path matching the model's stated intent. After receiving a "no changes" error, the model should recognize the wrong file is being targeted and correct the path instead of retrying identically.
Error Messages/Logs
No changes to make: old_string and new_string are exactly the same.
Returned 15+ consecutive times, each time the model retried the same failing Edit call with the identical wrong file path.
Steps to Reproduce
- Start a long conversation with many sequential Edit tool calls across multiple files in a similar
directory structure
- Edit one specific file several times in quick succession
- Ask the model to edit Claude Code's MEMORY.md file (located in .claude/projects/, a very different
path from the working directory)
- The model's text output will correctly state the intended file, but the Edit tool call targets the
previously-edited file instead
- The tool returns "No changes to make: old_string and new_string are exactly the same"
- The model retries the same failing call repeatedly without correcting the file path
Note: This occurred deep into a conversation (~40+ tool calls). The MEMORY.md path is significantly
different from the project files being edited throughout the session. May be difficult to reproduce on
demand — likely requires a long context with many Edit calls.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.78 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
Recovery was not clean — even after user interruption and stating intent to Read the correct file, the model still targeted the wrong file a few more times before eventually breaking free
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗