replace_in_file does not work at all
What happened?
python 3.12.0, vscode 1.100.2, claude-sonnet-4
ever since the 3.17.0 update, replace_in_file never works. it always defaults to write_to_file after some number Diff Edit Mismatches. Updates 3.17.3, 3.17.5, 3.17.6 and 3.17.7 all mention this issue and none of them have fixed it, the only thing that has changed is how many Diff Edit Mismatches it takes. sometimes after the failure cline thinks it must be a json formatting error even though there are no jsons involved.
also it appears to be ignoring my custom instructions which include "Never use replace_in_file, it never works. Just go straight to write_to_file."
Steps to reproduce
- Load any project with a python 3.12.0 virtual environment
- Ask cline to modify any .py file
Relevant API REQUEST output
Provider/Model
cline:anthropic/claude-sonnet-4
Operating System
Windows 10
System Info
Intel Core i5-10600k, Nvidia Geforce GTX 1080 Ti (11 GB), 32 GB RAM
Cline Version
3.17.7
Additional context
No response
It almost always fails for me as well
I have had similar issues with gpt-4.1, though not every time. In one case it hilariously replaced most of the file with a "this section remains unchanged" comment.
I have the same problem with a similar setup.
cline is such a good tool, but this bug is ruining it for me! And it happens with all the models: Gemini, Claude, OpenAI... nothing from the team?
Yes, up to now Cline has been very fast and streamlined, this has completely short circuited this tool.
As a workaround, I reverted to 3.16.3. I haven't checked in detail what cool new enhancements I'm missing now but it works decently well.
I found the solution to this problem. I turned off auto format on save in VS Code. Autoformat on save was causing whitespace changes that made replace in file fail.
Thanks for reporting! This has been consolidated into #4384.