claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

String to replace not found in file - CRLF/LF issue

Open alrightryanx opened this issue 10 months ago • 34 comments

Getting this issue often when it tries to edit files. Using WSL in Windows, wondering if it relates to my CRLF/LF issue. I did configure my git line endings via git config --global core.autocrlf, still getting this issue.

alrightryanx avatar Feb 26 '25 23:02 alrightryanx

If you're hitting this a lot, would you mind reporting an issue through /bug and posting the feedback id here?

bcherny avatar Feb 27 '25 00:02 bcherny

07e72b6b-c112-4b02-905e-d8eec9baf2ff

alrightryanx avatar Feb 27 '25 00:02 alrightryanx

having the same issue, 74171893-4d01-47ba-aaa0-f20f7792d81f

DaCuDev avatar Feb 27 '25 07:02 DaCuDev

Me too a9f54b59-e5af-4298-9fe5-03c7bbf81903

ernesto-butto avatar Feb 27 '25 10:02 ernesto-butto

Same here: c4cb55e4-9f92-455e-8fe4-ac1a55f63205

bretthodgkins avatar Feb 27 '25 12:02 bretthodgkins

Same here: cdf32a47-aad0-48f7-8cbc-d1b178324b4f

johnkimdy avatar Feb 28 '25 05:02 johnkimdy

I am also seeing these all the time on ubuntu. It manages to edit the code anyway but it typically has to follow up each failed Update with a slower Read and some other operations to get the editing done.

grimmen avatar Feb 28 '25 07:02 grimmen

Had the same issue, on a Linux system. Using SHELL=/bin/bash claude, to clarify.

Image It managed to waste $1.31 in just 3 minutes

Feedback id: 2088a5a9-2e48-4c7c-8243-7678a181019e

skerit avatar Feb 28 '25 11:02 skerit

Same issue, very frustrating: 76f2ea25-5913-4013-ac44-594dbe97e50f

nathanswavely avatar Mar 01 '25 16:03 nathanswavely

This is also the case on ubuntu, not just windows

thversfelt avatar Mar 03 '25 19:03 thversfelt

same issue as reported above, windows WSL ubuntu, claude started from project directory

thanks!

xenrax avatar Mar 04 '25 01:03 xenrax

The issue is that Claude is trying to replace a segment of code in a file. When it has this task, it tries to locate the code by a matching string, but it is required to match perfectly to tiniest degree including the surrounding whitespace etc. ( I grilled Claude hard to get that info). I suggested a simple workaround... "Instead of doing an "in-file" replacement, just write a new copy of the file from scratch, keeping the full content except for the segment you need to replace, and write that in accordingly." Works perfect every time. I also asked Claude why it would get endlessly stuck on such a simple hurdle, it replied, "Tunnel Vision, and trying to over engineer solutions instead of the simple and obvious."

This little work around is a staple in my sessions with Claude Code now. Have Claude dig in and explain its failures. I'm finding most to be trivial for human reasoning.

MitchellSys avatar Mar 04 '25 03:03 MitchellSys

Check your file if you are using CRLF. Changing to LF fixed the issue for me reliably. You can easily check and change the line encoding in VS Code (bottom right).

sebastiangeiger01 avatar Mar 04 '25 07:03 sebastiangeiger01

Check your file if you are using CRLF. Changing to LF fixed the issue for me reliably. You can easily check and change the line encoding in VS Code (bottom right).

Can confirm. This solved the issue for me on Fedora.

suyeonORG avatar Mar 04 '25 09:03 suyeonORG

Check your file if you are using CRLF. Changing to LF fixed the issue for me reliably. You can easily check and change the line encoding in VS Code (bottom right).

This helped me too, though the issue persists to a much lesser degree.

WorkByMartin avatar Mar 05 '25 03:03 WorkByMartin

Check your file if you are using CRLF. Changing to LF fixed the issue for me reliably. You can easily check and change the line encoding in VS Code (bottom right).

Helped me as well once I moved everything in my repo to LF, thank you!

xenrax avatar Mar 06 '25 03:03 xenrax

switching to LF fixed the issue for me

Surebob avatar Mar 06 '25 04:03 Surebob

Switching to LF did NOT work for me :/ Env: Arch Linux, Bash, Konsole

c44ad734-d20e-4f7b-b0eb-4eb9ddb769dd

nickelberg avatar Mar 12 '25 09:03 nickelberg

This is fixed in 0.2.38. Restart to update!

bcherny avatar Mar 12 '25 17:03 bcherny

Still getting this, latest bug report e46e005f-e0fd-4597-9c4a-72c9f2f185d8

wilson avatar Mar 29 '25 18:03 wilson

Still see this a lot too on Mac. Files are set to LF.

eAi avatar Apr 24 '25 10:04 eAi

Seeing this in VSCode on Windows 11 in WSL a lot with LF file endings.

Feedback ID: babf96e8-9a7b-4e8e-931e-b0f04ddd7beb

Possible solution is to ensure spaces and not tabs in files:

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

Originally posted by @Dekadinious in #968

Dekadinious avatar May 12 '25 06:05 Dekadinious

I also have this problem EXTREMELY often. I don't really want to convert all my tabs to spaces ☹

MartinMouritzen avatar May 13 '25 07:05 MartinMouritzen

Same issue here on windows 11 wsl2 arch linux using zsh shell if that matters.

GitMurf avatar May 17 '25 08:05 GitMurf

You guys have to fix this, we can't always control line endings in third party code and sometimes are editing files that require windows line endings.

muchcharles avatar May 21 '25 12:05 muchcharles

You guys have to fix this, we can't always control line endings in third party code and sometimes are editing files that require windows line endings.

Yeah, I'm not usually one for the dramatics, but this one really is a deal breaker. It wastes tons of tokens and really is frustrating and makes Claude code for the most part unusable for me.

GitMurf avatar May 21 '25 12:05 GitMurf

I am seeing this error a lot (latest Mac OS, fresh/latest Claude Code and VSCode). I just started using Claude Code and find that my context window is getting maxed out pretty fast whenever seeing these errors. It feels like there should be some kind of "credits" refunded to customers who are encountering this and rapidly approaching their API limits when this would not be the case if this bug were resolved. If the LF change doesn't work, I assume there's nothing that can be done on user end, right?

dgarson avatar May 27 '25 02:05 dgarson

12855be1-b017-43a0-8ff8-5a75266114ed

freiit avatar May 27 '25 15:05 freiit

I was pulling my hair out over this. What helped was a user memory I added:

# If you see "String to replace not found in file", try using sed instead.

tholst avatar Jun 09 '25 13:06 tholst

If you see "String to replace not found in file", try using sed instead.

this seems to work for me, bot sometimes it produces some weird output and then claude fixes it, consuming more token. This whole situation is consuming a lot of token, sigh...

GiampaoloGabba avatar Jun 09 '25 15:06 GiampaoloGabba