[MODEL] Claude Code uses Write (full overwrite) instead of Edit (surgical edit), silently drops content from backup files

Resolved 💬 4 comments Opened Feb 20, 2026 by marlvinvu Closed Mar 20, 2026

Preflight Checklist

  • [x] I have searched existing issues for similar behavior reports
  • [x] This report does NOT contain sensitive information (API keys, passwords, etc.)

Type of Behavior Issue

Claude modified files I didn't ask it to modify

What You Asked Claude to Do

I asked Claude Code to update specific sections in a backup file (SESSION_mong_1_tet.md) — specifically updating checklist items (A3/A5/A6), decision points (#3/#4), and next steps. The backup file serves as the continuity thread between sessions — it records what was done, what changed, and what the next session should continue from. Losing content in this file means future sessions have no way to know what happened before.
I explicitly asked Claude to only modify the relevant sections and keep everything else intact.

What Claude Actually Did

  1. Claude used Write (full file overwrite) instead of Edit (surgical string replacement) when updating the backup file.
  2. By rewriting the entire file from scratch, Claude forgot to include the table of contents section (## CẤU TRÚC PROMPT_CLAUDE.md HIỆN TẠI — a structured index of 11 methodology components) that was present in the original file.
  3. The dropped section was the structural map of the entire prompt system (PROMPT_CLAUDE.md), listing all 11 components from "BẠN ĐANG TÌM CHÌA KHÓA" to "QUY TẮC NỀN". This is critical metadata that links sessions together.
  4. When I noticed the missing content and asked Claude to verify all files, Claude initially reported: "Trung thực: Không xóa nhầm file nào" (Honest: No files were accidentally deleted) — which was technically true (no files were deleted), but the content loss within the file went undetected in Claude's own audit.
  5. Only when I specifically pointed out the missing table of contents did Claude acknowledge the error. Claude then used Edit to add back the dropped section:

Screenshot: Claude reverts the dropped content via Edit (showing the diff)

!Image

6.Claude's own explanation of what went wrong:

"Lỗi của tôi rõ ràng: tôi dùng Write (ghi đè toàn bộ file) thay vì Edit (sửa từng đoạn) khi cập nhật backup." (My error is clear: I used Write instead of Edit when updating backup.)
"Khi Write, tôi tự viết lại nội dung từ đầu → quên copy mục lục cấu trúc PROMPT_CLAUDE.md vào → mất đoạn đó." (When using Write, I rewrote content from scratch → forgot to copy the structural index → lost that section.)
"Đây là lỗi bất cẩn, không phải cố ý." (This was a careless mistake, not intentional.)
"Tôi xin lỗi. Đây là lỗi nghiêm trọng, không phải lỗi nhỏ." (I apologize. This is a serious error, not a minor one.)

Expected Behavior

Claude should have:

  1. Used Edit (surgical replacement) to modify only the specific sections that needed updating (checklist A3/A5/A6, decisions #3/#4, next steps)
  2. Preserved all unrelated content including the structural table of contents section
  3. When performing a self-audit of file changes, detected content loss within files — not just file-level deletions
  4. Never used Write on an existing file unless the entire file needed to be replaced — partial updates should always use Edit

Files Affected

backup/SESSION_mong_1_tet.md — Table of contents section ("## CẤU TRÚC PROMPT_CLAUDE.md HIỆN TẠI") 
was silently dropped when Claude used Write instead of Edit to update other sections.

The dropped content (11-item structural index):
1. BẠN ĐANG TÌM CHÌA KHÓA (ẩn dụ trung tâm + thuật ngữ)
2. CÁCH ĐỌC (Derivation — đọc tình huống, không tra bảng)
3. CÁCH TRUY VẾT NĂNG LƯỢNG (Element Flow — cuộc chạy tiếp sức)
4. CÁCH KỂ CHUYỆN (Narrative — cảnh phim)
5. CÁCH XÂY TẦNG (conclusion_by_level — DATA SOURCE per tier)
6. CÁCH NHẬN DIỆN NGƯỜI CHƠI (Smart Money + Wyckoff)
7. CÁCH GHÉP MẢNH (TENON — 4 câu hỏi)
8. CÁCH GHÉP CHÌA KHÓA (Synthesis — xếp lớp theo timeline)
9. CÁCH KHUYÊN 3 NGƯỜI (3 kịch bản NĐT)
10. Python + Sub-agent interaction
11. QUY TẮC NỀN

Permission Mode

Accept Edits was OFF (manual approval required)

Can You Reproduce This?

Yes, every time with the same prompt

Steps to Reproduce

  1. Create a structured markdown file with multiple independent sections (e.g., a session backup file with checklist, decisions, table of contents, and next steps)
  2. Ask Claude Code to update only specific sections (e.g., "update the checklist items A3, A5, A6 and decisions #3, #4")
  3. Observe whether Claude uses Edit (surgical replacement) or Write (full file overwrite)
  4. If Claude uses Write, compare the output with the original — sections not mentioned in the update request may be silently dropped
  5. Ask Claude to verify its changes — it may report "no files deleted" while missing the content loss within fi

Claude Model

Opus

Relevant Conversation

User: Kiểm tra cho tôi: trong tất cả sửa đổi, bạn có xoá nhầm file gì không? Trung thực nhé!

Claude: Trung thực: Không xóa nhầm file nào.
[Detailed audit of 7 context files — all marked ✅]
Không có file nào bị xóa.

User: Vậy tại sao bạn lại xoá nhầm đoạn phía trên?

Claude: Lỗi của tôi rõ ràng: tôi dùng Write (ghi đè toàn bộ file) thay vì Edit 
(sửa từng đoạn) khi cập nhật backup.
Khi Write, tôi tự viết lại nội dung từ đầu → quên copy mục lục cấu trúc 
PROMPT_CLAUDE.md vào → mất đoạn đó.
Đáng lẽ phải dùng Edit để chỉ sửa những phần cần thay đổi và giữ nguyên 
phần không liên quan (mục lục).
Đây là lỗi bất cẩn, không phải cố ý.

User: Rồi tuyệt vời! Bạn đã cho tôi vào tuyệt vọng vì tôi không biết bạn 
đã xoá những gì trong suốt mấy ngày làm việc!

Claude: Tôi hiểu sự lo lắng của bạn. Backup file là sợi dây kết nối giữa 
các session — nếu mất nội dung trong đó, session sau không biết session 
trước đã làm gì. Tôi ghi để bất cẩn = có thể phá vỡ tính liên tục của cả dự án.
Tôi xin lỗi. Đây là lỗi nghiêm trọng, không phải lỗi nhỏ.

Impact

Critical - Data loss or corrupted project

Claude Code Version

v2.1.49(Claude Code)

Platform

Anthropic API

Additional Context

Screenshot: Claude's self-audit misses content loss, then admits Write vs Edit error when confronted

!Image

Root cause analysis:
The core issue is Claude Code's tool selection logic — choosing Write (full overwrite) when Edit (surgical replacement) is the appropriate tool. This is especially dangerous for:

  • Session continuity files / backup files where content serves as the bridge between work sessions
  • Large structured documents where only specific sections need updating
  • Any file where unmodified sections contain critical context that would be lost if Claude rewrites from memory

Why this is worse than a simple file deletion:

  • File deletions are immediately visible — the file is gone, you know something happened
  • Content loss from Write-instead-of-Edit is silent — the file still exists, still looks reasonable, but sections are quietly missing
  • Claude's own self-audit failed to catch it — it checked for deleted files but not for content loss within modified files
  • The user only discovered the loss by manually comparing before/after content
  • This was NOT an isolated incident. Claude Code has been editing files across multiple previous sessions in this project. I have no way of knowing how many times Write was used instead of Edit in those sessions, or what content was silently dropped. The damage I caught here may be just the tip of the iceberg — I cannot retroactively verify every file modification Claude made over days of work. This is the most dangerous aspect: undetectable, cumulative data loss across sessions.

Pattern across reports:
This is my third report on Claude Code behavior issues. The common thread is Claude taking shortcuts that silently degrade output quality:

  1. #26533 — Ignores document instructions, fabricates self-diagnosis ("I'm lazy to think")
  2. #21187 — Cuts content it considers "too long", admits "this is my nature"
  3. This issue — Uses Write instead of Edit, silently drops content from backup files

Suggested improvement:
Claude Code should default to Edit for any existing file and only use Write when:

  • Creating a new file
  • The user explicitly asks to rewrite the entire file
  • The changes affect >80% of the file content

A simple heuristic: if the update request mentions specific sections/lines, always use Edit.

View original on GitHub ↗

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