[BUG] Edit tool applies only one replacement when diff shows multiple

Status Fixed / completed
Maintainer reply ✓ Yes — igorkofman
Activity 7 comments · opened Jun 5, 2025 · closed Jul 6, 2025
💡 Likely answer: A maintainer (igorkofman, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 1.0.11 (Claude Code)
  • Operating System: 15.5 (24F74)
  • Terminal: Terminal App

Bug Description

When I confirm a diff that shows multiple occurrences of a string replacement, all occurrences should
be replaced

Clause says, this could be:

  • A bug in how the Edit tool handles multiple identical strings
  • An issue with the replace_all parameter not working as expected
  • A problem with the diff preview showing more changes than will actually be applied

Steps to Reproduce

  1. Be in a situation where Claude wants (or needs) to replace multiple occurrences of the same string
  2. Confirm a diff that shows multiple hunks

Expected Behavior

The resulting diff should match what was displayed to be confirmed

Actual Behavior

  • The tool result transforms to show only one hunk
  • Only one replacement occurred in the file

Additional Context

I've asked Claude to tell me the exact parameters it passed to the tool:

Tool: Edit
  Parameters:
  {
    "file_path": "[REDACTED].py",
    "old_string": "/v1/batches",
    "new_string": "/batches",
    "replace_all": true
  }

I saw three matches when I was prompted to confirm the edit. Only one was applied. In the code, it should have definitely applied three replacements.

View original on GitHub ↗

7 Comments

0xGosu · 1 year ago

This bug heavily impact Claude Code ability to do code refactoring. It constantly misses line to be refactored, running the same refactoring prompt did help but if there are not so many similar places / identical codes to be replaced in a same file.

igorkofman collaborator · 1 year ago

Actually the bug here is fixed as reported (just tested). If you have another bug, please open a new issue with exact repro steps. Thanks!!

iambaseddev · 1 year ago

Still getting this on 1.0.48

igorkofman collaborator · 1 year ago

Please open a new issues with exact repro steps. Thanks!

s4suryapal · 1 year ago

facing same issue :

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

stippi · 1 year ago
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

But that is expected. The model either must provide more context in old_text, or set replace_all to true.

github-actions[bot] · 1 year ago

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.