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

[BUG] Error: Found 2 matches of the string to replace, but replace_all is false.

Open nullbio opened this issue 6 months ago • 19 comments

I get this red colored error happen a lot. Is there something I need to do to fix this?

● Update(run.py)
  ⎿  Error: Found 2 matches of the string to replace, but replace_all is false. To replace all occurrences, set replace_all to true. To replace only one occurrence, please
     provide more context to uniquely identify the instance.
     String:         <string here>

nullbio avatar Jul 11 '25 12:07 nullbio

I would expect Claude to recover itself from this, it happens when the file is large or contains many lines of code that are similar to each other. Claude will try to Read more of the file and adjust its Update request to correctly identify the specific piece of code to change, but it may struggle if there are many pieces that are similar or identical.

For ways you could help Claude, consider breaking your code into multiple files that contain unique behaviour. You could even ask Claude to identify parts of the code that seem duplicated in functionality, or literal code, that could be safely modularised.

nevercast avatar Jul 11 '25 13:07 nevercast

+1

LittleMaxi avatar Jul 14 '25 03:07 LittleMaxi

+1

barlas avatar Jul 17 '25 23:07 barlas

My Claude was trying to find and replace a set of strings in a file, so it tried and failed to use MultiEdit twice before giving up and resorting to sed instead:

✻ Thinking…

  Let me fix all the occurrences of asyncRenderString in this test file. I'll use MultiEdit to make all the changes at
   once:

● Update(__tests__/general/formTest.js)
  ⎿  Error: Found 2 matches of the string to replace, but replace_all is false. To replace all occurrences, set 
     replace_all to true. To replace only one occurrence, please provide more context to uniquely identify the 
     instance.
     String:     it("logs an error if path isn't an array.", async function () {

✻ Thinking…

  Let me fix this by being more specific about the instances:

● Update(__tests__/general/formTest.js)
  ⎿  Error: Found 2 matches of the string to replace, but replace_all is false. To replace all occurrences, set 
     replace_all to true. To replace only one occurrence, please provide more context to uniquely identify the 
     instance.
     String:   it("Works with multiple forms", async function () {

✻ Thinking…

  Let me run the tests to see if we have the issue fixed with what we've changed so far. I'll need to make sure all 
  the async related changes are done:

● Bash(sed -i 's/await nunjucks\.asyncRenderString/nunjucks.renderString/g'
      /workspace/apps/__tests__/general/formTest.js)
  ⎿  Running…

cyreb7 avatar Jul 18 '25 16:07 cyreb7

+1

Ale1x avatar Jul 25 '25 13:07 Ale1x

+1

cotovanu-cristian avatar Jul 26 '25 16:07 cotovanu-cristian

+1

harvey-propelle avatar Jul 27 '25 20:07 harvey-propelle

+1

mechanin avatar Jul 28 '25 10:07 mechanin

+1

jqhr avatar Jul 29 '25 01:07 jqhr

+1 it recovered but it would be nice if was something we could enabled instead of claude code having to do 20+ different edits of the same thing

seanGSISG avatar Jul 30 '25 17:07 seanGSISG

+1

alexandrosk avatar Jul 30 '25 18:07 alexandrosk

+1

onurku avatar Jul 31 '25 13:07 onurku

+1

farishrf avatar Aug 02 '25 04:08 farishrf

I don't understand how anyone is using claude code when it literally does this multiple times a session. Is everyone "using" claude code just faking it? this is unusable in its current state.

You're telling me that of all AI products, Claude Code runs into literal errors doing multiple replacements?

Its entire purpose is editing files like this!

Is this a joke? Or are we doing something wrong? How does anyone actually use this tool if it constantly runs into issues with multiple replacements? Every basic AI coding tool out there can do this.

Th0rGarden avatar Aug 02 '25 17:08 Th0rGarden

+1, but it will resume soon

FYZAFH avatar Sep 01 '25 06:09 FYZAFH

No response, no resolution, nothing. Anthropic is an embarrassment. If Claude Code of all tools can't do multiple replacements without running into errors all the time then Anthropic is a pure fraud company.

Th0rGarden avatar Sep 01 '25 11:09 Th0rGarden

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.

github-actions[bot] avatar Dec 06 '25 10:12 github-actions[bot]

I left claude code because of this mess. Is this still a problem?

Th0rGarden avatar Dec 06 '25 16:12 Th0rGarden

I left claude code because of this mess. Is this still a problem?

no @Th0rGarden

FYZAFH avatar Dec 06 '25 16:12 FYZAFH