[BUG] "Error: String to replace not found in file."
Environment
- Platform (select one):
- [x] Anthropic API
- Claude CLI version: 0.2.101 (Claude Code)
- Operating System: macOS Sequoia 15.5
- Terminal: iTerm2
Bug Description
Claude Code is unable to use the Update tool successfully. The error in the title is occurring on every single attempt to use the Update tool. 100% failure rate.
Steps to Reproduce
- Trigger the Update tool by any mechanism.
Expected Behavior
Given that Claude Code should always have a copy of the current code in the context when using an Update tool I would expect it to always be successful. I can't think of any case that one would expect an LLM to fail at string matching tasks given a working UTF-8 source code tokenizer.
Actual Behavior
I only ever get an error in response to the Update tool being called.
⏺ Update(../../node/graph_shader.go)…
⎿ Error: String to replace not found in file.
Additional Context
I am using go in most of my coding projects. Does Claude Code not use the on disk file content in the context? Perhaps Claude Code is relying on the idea that LLM output code remains unchanged when written to the file? If so this would fail to account for ecosystems like go in which source code might be reformatted on the fly. Claude Code should be careful to update its context with actual file content prior to every api call to insure that file content is quoted correctly accounting for external tool and user manipulation. But this is just my blind speculation as to a possible causes.
12 Comments
This is marked as a dupe but not clear what it is a dupe of, is it #781 ?
I'm seeing this in Python projects as well:
I'm seeing this in a php project as well. It happens all the time so that I already thought that's "normal" before looking it up.
Doubling up on this an receive it in python all update tools too
Can confirm, this started last week in all my Swift/ObjectiveC projects.
Seeing this in VSCode on Windows 11 in WSL a lot with LF file endings in a NodeJS project. Uses a lot of tokens retrying and failing.
Feedback ID: babf96e8-9a7b-4e8e-931e-b0f04ddd7beb
EDIT: Might be because of tabs? https://github.com/anthropics/claude-code/issues/781
EDIT 2: I stopped having this problem after converting all tabs to spaces in my codebase
EDIT 3: Spoke too soon, but at least it does not need 10 tries per change now
Same issue,
b27edbbb-8570-4482-a606-14b266bc779eSeems like this is related to using tabs over spaces for me. I switched my Biome linter to use spaces and reduced the issue occurrence.
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 am seeing an issue like this.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
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.