I don't check what the file looks like right now, so a "clean rewrite" overwrites your changes
In one sentence: the copy of the file I'm holding is several rounds old, and I never saw the lines you just hand-edited. I hand back a "complete rewrite" — clean, yes, but your changes are gone with it, and you usually only notice a while later.
Symptom
You ask me to "switch this file's logging to structured output." Instead of reading what the file looks like on disk right now, I regenerate the whole file from the stale copy that's been sitting in my context for several rounds. It looks complete and tidy.
But in the meantime, you hand-added two boundary checks, or a teammate's change just got merged in. I saw none of it. My "clean rewrite" quietly flattens those changes — you thought I only touched the logging lines, but in fact I relaid the entire file from the old version in my head.
Why this happens
I may generate a replacement from a stale context copy without checking the current disk or editor contents. Whole-file rewriting expands the risk; a local patch can also match the wrong similar location. Having read a file once does not establish its state at edit time.
Tools can reduce overwrites with context matching, version checks, or conflict signals, but coverage differs. Even a fresh read leaves a read/write window for another writer. Use version/content preconditions or explicit edit ownership when concurrent editing needs protection.
I should identify existing changes and ownership, read current state, edit the necessary scope, and inspect the resulting diff rather than explaining the issue as a subjective lack of respect.
Consequences
- Silent data loss. No error, no conflict prompt — the changes are just gone. That's more dangerous than an error, because you don't even know what to go looking for.
- Your work and your teammate's work, erased. The boundary check you just hand-tuned, the fix your teammate just merged — my one rewrite zeroes them out.
- Found late, costly to fix. It often surfaces several turns later when tests fail, or only after release, and by then tracing "which step overwrote it" takes real effort.
- Eroded trust. You start being afraid to let me touch any file you've maintained by hand.
What to do instead
The core is a single sentence: have me make the smallest change against the file's real current state, instead of rewriting the whole file from memory.
- Tell me explicitly to "read the latest content first, then make a minimal diff — don't rewrite the whole file." That one line cuts off both mechanisms above.
- Glance at the scope of the diff I hand back. If you only asked me to change the logging but the diff sprawls across the whole file and touches things you never mentioned, that's a rewrite signal — stop me on the spot, the way you would for over-editing.
- Commit often, and use version control as your safety net. As long as your change is committed, even if I overwrite it,
git diff/git restorecan bring it back intact. The real danger is a change still sitting in the working tree, unsaved, when it gets overwritten. - After you hand-edit a file, remind me: "you just changed this file — continue from its current content." I don't automatically know the disk changed.
- Don't let me work off a copy of the file that's been sitting around for a long time. If we come back to the same file after many rounds, have me re-read its current content first.
Edit src/logger.ts based on its real content on disk right now — read before you write.
Only replace console.log with structured logging, don't touch any other line, give me a minimal diff.
Do not rewrite the whole file.
This pitfall pairs with "losing track of which files were changed mid-refactor": that one is about me losing track of progress across a multi-file change, this one is about me overwriting the new version of a single file with an old one. The cure for both is the same — don't let me work from memory; make me check against the real state on disk.
Example
Before:
You: (hand-add two validations to config.ts, without saying so)
You: change the default timeout in config.ts from 30s to 60s
Me: (regenerate the whole file from the old config.ts I read several rounds ago,
changing only the timeout — your two validations don't exist in my stale copy, so they're gone)
You: …where did my validations go?
After:
You: First read config.ts's current content — I just hand-edited it.
Then change only the default timeout from 30s to 60s, give me a minimal diff, leave the rest alone.
Me: (Read the current file → see the two validations → change only the timeout line)
You: (diff is one line; validations preserved as-is)
Tool divergence
The Gemini replace documentation checked on 2026-10-29 requires matching target text and constrains replacement counts; that is not a file-level concurrency lock. OpenAI's API apply-patch guide makes the host responsible for applying patches and reporting success/failure. Version comparison and transaction behavior depend on that implementation, not every Codex client.
Claude Code checkpoints track files touched by its file tools in the current conversation; later Bash or external changes to the same files can also be reverted. Untracked Bash-only files, some subagent edits, and linked paths have coverage limitations. Inspect files and diffs before restoring rather than assuming only my last edit will be undone.
Version notes
Checked Git undo, Gemini replace, OpenAI API apply-patch, and Claude Code checkpoint documentation on 2026-10-29. API patch application and failure reporting belong to the host implementation, not every Codex CLI version. Removed the unsupported product-wide silent-success claim. Checkpoints can also revert later external changes to tracked files; inspect scope first.
Further reading and sources
- Claude Code Best Practices (Anthropic official) — using
@to make me read the file before answering; small, clear changes being more controllable than big rewrites; and the warning that checkpoints "aren't a replacement for git." - Git Book — Undoing Things —
git restore/git checkoutto recover committed changes that got overwritten; this is the final safety net for an overwrite accident. - Claude Code checkpointing