cline icon indicating copy to clipboard operation
cline copied to clipboard

replace_in_file does not work at all

Open JacobHerlin opened this issue 7 months ago • 2 comments

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

  1. Load any project with a python 3.12.0 virtual environment
  2. 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

JacobHerlin avatar May 29 '25 00:05 JacobHerlin

It almost always fails for me as well

prmichaelsen avatar May 29 '25 03:05 prmichaelsen

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.

JacobHerlin avatar May 29 '25 17:05 JacobHerlin

I have the same problem with a similar setup.

fmarwede avatar May 30 '25 15:05 fmarwede

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?

joaomj avatar May 31 '25 20:05 joaomj

Yes, up to now Cline has been very fast and streamlined, this has completely short circuited this tool.

triptych avatar Jun 01 '25 21:06 triptych

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.

fmarwede avatar Jun 02 '25 21:06 fmarwede

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.

sgd2z avatar Jun 11 '25 14:06 sgd2z

Thanks for reporting! This has been consolidated into #4384.

celestial-vault avatar Jun 23 '25 03:06 celestial-vault