feat: Edit tool should auto-verify fresh file content before applying changes

Resolved 💬 1 comment Opened May 18, 2026 by xjp0422 Closed Jun 16, 2026

Problem

When conversations become long, early Read tool results get compressed into summaries via context compaction. If Claude then tries to Edit based on stale/cached content, the old_string may not match the actual file state, causing silent overwrites of user's manual code changes.

This has been observed in practice — user's uncommitted changes were lost because an Edit was based on a stale conversation summary rather than the actual file on disk.

Current Behavior

  1. User manually edits files outside the conversation
  2. Claude reads files earlier in the conversation
  3. Context compaction compresses the Read results into summaries
  4. Claude attempts Edit using stale content from the summary
  5. old_string partially matches or misses, potentially corrupting the file

Proposed Solution

The Edit tool should verify it has fresh file content before applying changes. Options:

  1. Auto-Read before Edit: If a file hasn't been Read in the current conversation turn (or since last file modification), automatically Read it first before applying the Edit
  2. Stale content rejection: If the old_string doesn't exactly match the current file content, fail with a clear error instead of attempting a fuzzy/partial replacement
  3. Configurable option: Add a setting like "alwaysReadBeforeEdit": true in settings.json to enforce this at the platform level

Why Memory/Prompt Workarounds Are Insufficient

Saving a "always Read before Edit" instruction to memory helps, but:

  • It relies on the AI following a prompt instruction, not a platform guarantee
  • Memory can be ignored or forgotten in complex multi-step tasks
  • New sessions may not load the memory in time
  • It's a band-aid for what should be a platform-level safety check

Impact

This affects any user doing iterative code editing in long conversations — which is a core Claude Code use case. Losing uncommitted work due to stale content is a high-severity UX issue.

Environment

  • Claude Code CLI (latest)
  • Windows 11
  • Large Java Spring Boot project (conversations tend to be long)

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗