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

[BUG] Crash with Error: Cannot edit file: old_string is a substring of a new_string from a previous edit.

Open Yassine-64 opened this issue 1 year ago • 4 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude CLI version: claude-code/0.2.11
  • Operating System: macOS 14.x (MacBook Pro 2021)
  • Terminal: Terminal App (default macOS)

Bug Description

Claude Code CLI crashes immediately after completing the first TODO. The crash happens when it attempts a second edit, and throws the following error:

node:internal/process/promises:288
    triggerUncaughtException(err, true /* fromPromise */);
    ^

Error: Cannot edit file: old_string is a substring of a new_string from a previous edit.
    at oP (file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1652:530)
    at cZ4 (file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:2617:10945)
    at J (file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:2617:9923)
    at file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:2617:10189
    at WD (file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:21377)
    at MY (file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:40875)
    at file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:39071
    at Lj1 (file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:61:78877)
    at Immediate.Hj1 [as _onImmediate] (file:///Users/MAC/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:61:79295)
    at process.processImmediate (node:internal/timers:476:21)

Steps to Reproduce

  1. Run claude dev in a project with multiple TODOs
  2. Let Claude complete the first TODO
  3. After attempting the second edit, the CLI crashes with the above error

Expected Behavior

Claude should handle multiple TODO edits sequentially without crashing, even if new strings overlap with previous ones.

Actual Behavior

Claude crashes with a Node.js error due to old_string being a substring of new_string from a previous edit. This breaks the editing flow and stops further progress.

Additional Context

  • Node.js version: v18.20.8
  • Claude CLI installed locally via npm
  • Error possibly caused by improper handling of overlapping diffs or string replacements across edits

Yassine-64 avatar Jul 17 '25 21:07 Yassine-64

Possible duplicate of https://github.com/anthropics/claude-code/issues/2934?

fsc-eriker avatar Sep 05 '25 07:09 fsc-eriker

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]

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] avatar Jan 07 '26 10:01 github-actions[bot]

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.

github-actions[bot] avatar Jan 14 '26 14:01 github-actions[bot]