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

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

Open stippi opened this issue 8 months ago • 0 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • 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.

stippi avatar Jun 05 '25 15:06 stippi