[BUG] Edit tool frequently fails with "String to replace not found" on exact matches (macOS)

Resolved 💬 3 comments Opened May 20, 2026 by phpmac Closed May 24, 2026

Description

The Edit tool frequently fails with String to replace was not found even when the old_string exactly matches the file content (confirmed by prior Read output). A second attempt with the identical old_string usually succeeds, suggesting a stale file state cache issue.

Steps to Reproduce

  1. Read a file with the Read tool
  2. Attempt to Edit the file using content from the Read output
  3. Frequently get: Error editing file: String to replace was not found
  4. Re-read the file (content is identical)
  5. Same Edit call succeeds

Expected Behavior

Edit tool should match old_string when it exactly matches the file content as shown by the Read tool.

Actual Behavior

First Edit attempt fails ~30-50% of the time, requiring a redundant Read before retry.

Environment

  • Claude Code version: 2.1.139
  • macOS: 26.5 (Build 25F71)
  • Shell: fish (/opt/homebrew/bin/fish)
  • Model: GLM-5.1
  • Node.js: (via bun)

Additional Context

This happens consistently across multiple sessions and different file types (PHP, JS, JSON, TS). The pattern is: first Edit fails -> Read confirms content unchanged -> second Edit succeeds. This suggests the Edit tool's internal file state cache is not always in sync with the actual filesystem.

Related issues: #52482, #52241

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗