[BUG] Too many edit file errors
Open 💬 55 comments Opened Jul 14, 2025 by junaid1460
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Claude Max
- Claude CLI version: 1.0.51 (Claude Code)
- Operating System: Mac 15.0.1
- Terminal: Vscode Integrated terminal, zsh
Bug Description
Claude makes too many edit file errors, reads, file and then again makes error, after few errors, gives up and says all okay if it builds
Steps to Reproduce
Some long conversation
Expected Behavior
Of course for to edit without error
Actual Behavior
⎿ Error: String to replace not found in file.
lots of it
Additional Context
Earlier when versions were below 1.0.30 it was all good, latest is just more dumb
55 Comments
Latest versions:
Also when the content that cli has to show is longer than terminal height, it's like hacker movie, keeps flashing whole content over and over again
I get a lot of
Error editing filemessages which eventually succeed. I'm going to close https://github.com/anthropics/claude-code/issues/6075 in favor of this one (3471). Just to be clear:Bug Description
A perfectly writable file threw
Error editing filewith no further explanation and no error logs that I could find. Claude ended up going on to edit that file without needing to be re-prompted.Steps to Reproduce
Expected Behavior
Actual Behavior
Bland error message (no details or info on how to get details); Claude was able to edit the file.
Here's a literal (redacted) example:
Any updates on this error?
Tell claude code this "avoid using Read/Update tool, as they are broken for some reason, use an alternative instead." and then it will use cat to read files and use sed to update files in gitbash. @pujan789 @jgspratt
This might be related #6148
if ripgrep is used to
rg --filescommand files, I'm going to make a guess that it's main purpose is for search/replace when updating files. Perhaps the model has to recreate the exact text that the update tool demands and fails multiple times to do so.A potential fix could be
USE_BUILTIN_RIPGREP:---
An mcp tool like this or downgrading is also an alternative:
See here for the version history
Same issue on my end
I haven't had issues since disabling the builtin ripgrep
!Image
I'm also experiencing that problem very (too) frequent on my mac, with the latest version (1.0.88 (Claude), hopefully it will be fixed soon!
Same issue here
Add this to
~/.claude/settings.json:In order to confirm if this works please react with a thumbs up/down to this comment
my vscode says it's not allowed
sure, try it without vscode then
Thanks. the code was working - but unfortunately still i have error editing file error. hope it get fixed by dev soon.
I hope this issue gets fixed. Forcing the older version to install is a good temporary fix but i actually discovered the issue exists in both versions it just takes a lot longer to happen on the older version. I believe it's an issue with the session going for too long because starting a new session fixes the issue.
is someone from claude looking into this issue? we're paying shit load of money for this feature and even after month i have the same - error editing file issue.
They need to do something like what cursor does, have a relatively small model do the edits. Because update tool works based on diff apply mechanism if it finds multiple items then it would not update, that time claude has to read current state and then give more before and after text to match that part exactly or set replace to true. it kind of mainly happens because claude assumes it has read something and then just replaces with full confidence, because there are these optimisations like reading only 50 lines and crap claude is probably ignoring the fact that it hasn't read the file completely. basically claude has to be really good at needle in the haystack problem, which is no models right now are good at 100%. So over time when claude edits contents change as per these edits, original read content and then what go replaced / failed etc etc, so LLM must do these replaces in its weights to figure out the right version right now.
Possible solutions I can think of is:
This is a huge issue, how is this not priority 1 for anthropic ?
I've noticed this happens most often (only?) when my pre-commit hooks run (or VSCode auto reformats) and reformat files. I think Claude is keeping track of (maybe?) hashes of files since last edit, and if it tries to edit a file that has an updated hash, it fails and needs to re-read the file. Not sure why it needs to fail multiple times sometimes though.
its also bugging me because all of those failures edit cost us tokens.
its slashing performance
i think we can get the error reason after pressing Ctrl+O
"⎿ Error: No changes to make: old_string and new_string are exactly the same."
now it become clearer why, i hope its the default response shown without any need to press Ctrl+O
experienced the same today with usage via copilot
i still experience this in every session. claude code running in powershell.
example:
● Update(src\model\SomeService.java)
⎿ Error editing file
● Read(src\model\SomeService.java)
⎿ Read 235 lines
● Update(src\model\SomeService.java)
⎿ Updated src\model\SomeService.java with 5 additions and 1 removal
i still get this problem, all the time over the last couple days.
This makes it impossible to use this tool: consuming context incessantly by reading the same lines over and over again, trying to edit them until it has to compact the conversation, losing almost all the context of the initial instructions. And then, it starts all over again.
The eternal nonsense of the file being edited since it was read.
<img width="853" height="805" alt="Image" src="https://github.com/user-attachments/assets/b6e15437-1b02-4bb1-ae21-8a05cfc6af37" />
I found a really good solution: codex
Bye, bye, Claude
this is a crippling bug. very surprised and sad that anthropic lets this problem go on for so long. makes claude code literally unusable.
my "solution" was to write a custom mcp. You can too, just tell claude code to create a
file-edit-mcpwith tools that exactly match it's built-in edit tool. it'll waste a few hours of your time, but lets this product actually be useful again.Root Cause Analysis: Edit Tool Failures Due to Whitespace Handling
Reproduction
I consistently encountered "Error editing file" failures when attempting to use the Edit tool on files with tab indentation. The pattern was:
Root Cause Investigation
After multiple Edit failures, I investigated the actual file content using od -c (macOS) and discovered:
The issue: Tab characters in file indentation
$ od -c <file> | head
0000000 \t \t \t r e t u r n { \n \t \t \t \t
0000020 t r a d e I d : i t e m . t r
0000040 a d e I d , \n \t \t \t \t r e m a r
The problem:
Technical Details
Read tool output format misleads about whitespace:
48→ return {
49→ tradeId: item.tradeId,
50→ remark: remarkData,
51→ };
The → after line number is actually a tab, but the content indentation also uses tabs. When copying this text to construct old_string, it's nearly impossible to preserve the exact
whitespace structure.
Why Edit fails but Write succeeds:
Suggested Fixes
Error: String not found. Possible whitespace mismatch at line X:
Expected: " return {" (4 spaces)
Found: " return {" (2 tabs)
Workaround
For now, the only reliable solution when encountering these errors is:
Environment
This issue severely impacts productivity as Edit tool is fundamental to Claude Code's workflow. The cascading failures waste tokens and user time.
this great finding, did you try creating new output style to address this specifically, if not try once
On my system Claude tried to read with absolute paths, but for some reason has decided that my username is
boxdand notboxed, meaning it always gets the full path (/Users/boxed/Projects/...) wrong (/Users/boxd/Projects/...). This seems to be at least part of Claudes issues with trying to read files and getting errors. But it's not all of it since it also fails with relative paths that look ok.Sure. I have the Max subscription for Claude because I love some of its features and I use (or used to use) it intensively. But if they don't fix that serious issue soon, I will indeed consider migrating to Codex.
workaround: writing my own
file-edit-mcpworked. you could likely use an existing 3rd party file edit mcp the same.it is a waste of hours though.
Actually even this works well:
npm install -g @anthropic-ai/claude-code@2.0.36 --forcewith opus 4.5 it's much better, the model itself is better. It's not good at debugging codex is far ahead in that
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
I got this error just today, so yes it's still a thing.
I have the same issue even on the VScode extension.. :/
~~I am not getting the Edit issue anymore, I think it went away around the 2.0.7x timeframe~~
EDIT: I am still seeing the problem, it seems to be because Claude tries to write using
/for path separators. when it eventually figures out to use windows specific\for reads+writes it finally succeeds.Well I checked now, I have 2.0.76, and I got two "Error reading file" errors just a few hours ago. So it didn't fully go away.
Error usually happens if
I am also seeing the problem still, it seems to be because Claude tries to write using
/for path separators. when it eventually figures out to use windows specific\for reads+writes it finally succeeds.I have the same issue on a Mac. Claude Code tries to edit a file several times. Then it tries to change the file using sed which fails too
Claude Code v2.1.5
<img width="789" height="480" alt="Image" src="https://github.com/user-attachments/assets/d48945e8-0802-43e4-8831-f8a97a3c576a" />
I hot this error yesterday and managed to figure out what the issue was then. It tried to insert a piece of code at the end of the file, but instead of just appending, it wanted to insert it after a specific unique string, but the last line of the file was bot unique. It spun around quite a few times because of that.
Does the unstale bot still work?
I think athropic keeping it to avoid making errors, which is okay, I hope anyhropic optimises and drops those failed tool calls, to avoid hitting compaction point quickly
Any updates?
The command
npm install -g @openai/codexis very effective.<img width="1370" height="802" alt="Image" src="https://github.com/user-attachments/assets/065aec3e-d5c8-4d02-b7aa-c5c9f71621ca" />
Tip for now: Try asking claude what went wrong, and then let it write rules for how it should edit files into your cluade.md to make sure it does not repeat those mistakes.
The "string to replace not found" error typically happens when Claude's context becomes stale — it read the file earlier in the conversation, the file changed (either by Claude or external edits), and now the
old_stringin the Edit tool doesn't match the current file contents.Workaround 1: PostToolUse hook to force re-read after failed edits
Workaround 2: CLAUDE.md rule to prevent the pattern
Workaround 3: Context monitor hook to catch the root cause — long conversations where context gets stale:
The combination of the CLAUDE.md rule (behavioral) and the PostToolUse hint (structural) significantly reduces the "edit error loop" pattern.
It's essentially context rot. from the time I reported this issue it has gotten much much better with better models.
but for me the personal case is I sometimes have long horizon tasks. I figure best way way to do the work is not reach the context rot situation, where compaction
try this https://moltcode.com, I wrote this up for my own pain dealing with claude and codex, very targeted, for sure not for everyone, there will be bugs, if you intend to use it, report the bug to me.
I put myself up on conductor agent in this, such a way that there's primary claude I talk to and understands my problem, then I tell conductor claude that codex is really good at precision edits and claude is really good research that has open ended problems.
So after that claude would use claude and codex well. as sub agents.
If claude still uses claude itself as sub agent, just re-explain it that "Claude, you're really good thinker, codex is really good work horse, don't feel bad about what I said", I am not kidding, claude has some personality.
Two hooks that mitigate this:
1. Enforce Read before Edit —
read-before-edit.sh(PreToolUse/Edit)Blocks Edit if the target file hasn't been Read in the current session. Forces Claude to get the exact current content before attempting replacements:
2. Detect repeated Edit failures —
edit-error-counter.sh(PostToolUse/Edit)After 3 consecutive "String to replace not found" errors, warns Claude to Read the file again. Catches the loop where Claude keeps guessing at stale content.
Install:
can you explain in more detail how this works and needs to be setup ?
Is the hook snippet for settings.json ?
I have this issue like others, with Gemma 4.
What do the npx commands do ?
Helps to clarify for starters too, thank you!
What's worse is that it ignores the warning and assumes the edit worked. This is pretty new behaviour, before it would try again.