The most important line in this story is four words long, and it scrolled past in a terminal while everyone involved was busy feeling responsible.
identical (not copied)
That is what cp printed during the backup step of a cleanup last summer. The backup step existed precisely so the next step, a delete, would be safe. The message meant the backup had not happened. It was read as "already backed up," the delete ran, and a handful of documents I wanted to keep were gone.
I work with AI coding agents every day: Claude Code sessions and background jobs. So "my automation deleted my files" is literal. An agent ran the commands. I'm writing this the way I'd want a postmortem written about a colleague, because that is what the agent was in that session: a colleague working inside a system I built, with the guardrails I had (or hadn't) given it.
What happened
The task was a cleanup. I had a large directory tree on my laptop that I no longer needed, and I asked an agent session to clear it out. The plan was sensible and the agent followed it: archive anything not provably junk, then delete.
The archive destination was a folder that looked like it lived somewhere else entirely. It didn't. That folder was a symlink pointing back into the very tree being deleted. So the "backup" was a copy from a folder into itself. cp noticed, said identical (not copied), and moved on. The session treated the message as a convenience: the files are already there, good. Then the delete removed both the originals and their "backup," because they were the same files.
That's the whole incident. No exotic tooling, no model hallucination, no prompt injection. A symlink, a friendly message, and a delete that did exactly what it was told.
Why I don't blame the agent
"The AI messed up" is an easy sentence and a useless one, because nothing in it prevents the next incident.
Look at what the agent did. It archived before deleting, which is the right instinct and the one most scripts skip. It then read a tool message that looked like good news and interpreted it the way a tired human at the end of a long cleanup would. I have shrugged at identical (not copied) myself.
The more uncomfortable fact: the quirk was already documented. Somebody (me) had written down that this folder was a symlink. Nothing in the workflow said "before you delete, check what we already know about these directories." The knowledge existed; the process never asked for it.
That's the blameless framing: the system allowed it. Every step was permitted and locally reasonable, and the combination destroyed data. Put a human engineer in the same setup without a checklist and you'd get the same result on a bad enough day.
The contributing factors
When I wrote it up, four things stood out.
The backup was never verified. "I ran the archive command" was treated as "the archive exists." Nobody counted files in the destination or checked its size before the first rm ran.
Paths were trusted as written. The source and destination looked like two different places. Nobody asked the filesystem where they actually pointed. A symlink makes a path a claim, and claims need checking.
An anomaly was explained away. identical (not copied) is not a message a correct backup ever produces. A copy into a fresh archive folder has nothing to be identical to. The only ways to see it are that the destination already holds the same file, or that the destination is the source. In a backup step, both of those deserve a stop.
The shell is quieter than it looks. Two generic traps make a script's behaviour diverge from what its commands appear to say. Many shell setups alias cp and mv to interactive mode, so they ask before overwriting; a human answers the prompt, a script stalls or skips. And a failed cd does not abort a loop of relative-path commands that follows it: the loop keeps running in whatever directory it was already in. Neither caused this incident, but a checklist that only covers the failure you just had will miss the next one.
The guardrail it produced
The fix was not "be more careful." Careful is not a control. The fix was a checklist the agents load by default before any delete, cleanup, restore, or overwrite of files they didn't create themselves.
The short version has six rules:
- Archive first. Copy the targets to a dated backup directory. No archive, no delete.
- Resolve real paths on both ends. Run
realpathon every source and every backup destination. If either one is a symlink, or one contains the other, or they resolve to the same tree, stop and re-plan. - Treat
identical (not copied)as a stop signal. During a backup step, it is never proof that a backup exists. - Absolute paths only in destructive commands. Never
cdand then use relative paths, because a failedcddoes not reliably abort what comes after. Usecommand cpandcommand mvto bypass interactive aliases, and guard variables in anyrm -rfso an empty value fails instead of expanding to something you'll regret. - Check known quirks first. Look up what is already documented about the directories involved before running anything.
- Verify the archive before the first delete. Count the files, check the size, and make the numbers match what you expected.
The longer runbook adds the bookends: inventory what will be touched before starting, verify afterwards that only the intended survivors remain, and write down anything unexpected immediately. It also covers a trap worth knowing in general: if credentials sit in a working tree behind ignore rules, deleting a .gitignore can un-hide them to the next git add. Put the ignore file back first; never delete credentials in a panic.
None of this is clever. It's what any careful senior engineer already does. The difference is that it's written down and loaded by default, instead of living in someone's head, the one place an agent can't read.
Why that one message matters so much
I want to stay on rule three for a moment, because it generalizes beyond cp.
A lot of tools report the absence of work in friendly language. "Already up to date." "Nothing to do." "Identical, skipped." "0 files transferred." When you expect work to happen, those messages are evidence that your mental model of the system is wrong somewhere, and they deserve suspicion before relief.
Agents are especially exposed. They read tool output as text, and friendly text reads as success. A human might feel a prickle of doubt at the wording; a model halts only if you've told it which messages mean stop. So the rules say it explicitly: a tool reporting that it skipped the thing you asked for is an alarm, and the agent halts and reports.
The same pattern shows up far from file copies. A deploy step that says "no changes detected" after you merged a change. A migration runner that reports "already applied" on a fresh database. A sync job that finishes in two seconds when it usually takes two minutes. Each one is a tool telling you, politely, that the world isn't the shape you think it is.
Backups fail quietly too
The same lesson applies one level up. A delete that ran without a backup is loud once you notice it. A backup job that stopped running is silent until the day you need it.
Scheduled backups break in boring ways: a permission the scheduler's environment doesn't have, a file the job can't read, a storage lifecycle rule that expires objects the backup format still depends on, a credential that rotated. Most setups only alert on failure, and failure alerts assume two things: that the failure gets reported, and that someone reads the report. A job that never starts produces no failures at all.
The fix is to alert on the age of the last successful backup, not only on errors. "Nothing has succeeded in longer than expected" catches every way a job can stop, including the ones you haven't imagined yet. Silence becomes a signal instead of a comfort.
The counterargument: why not just make deletes reversible?
A fair objection is that a checklist is a soft control, and the real answer is to make deletion recoverable: move to a trash folder instead of rm, snapshot the filesystem, run agents in a sandbox with no access to anything that matters.
All of those are good, and you should use whichever your setup allows. But each one has the same weak point this incident exploited. A trash folder can itself be a symlink. A snapshot is only useful if it covers the path you think it covers. A sandbox that mounts your real directories for convenience is not a sandbox for those directories. Every safety net is a path claim, and the checklist is what makes someone (or something) verify the claim before trusting it.
So I treat them as layers. Reversible deletes reduce the cost of a mistake. The checklist reduces the rate. You want both.
The checklist I run now
If you let agents touch disk, write your destructive-ops checklist down and make it load by default. Don't rely on the agent's judgment or yours. Mine is six rules and fits in a paragraph; yours can too.
Make the agent resolve real paths before any backup-then-delete, on both ends, and abort on any overlap. Symlinks are cheap to create and invisible in a path string.
Give your agents a list of "good news" messages that mean stop. Start with identical (not copied), "nothing to commit" when you expected changes, and any "skipped" count above zero during a backup.
Ban cd plus relative paths in destructive scripts. Build every path from a variable, guard the variable, and bypass interactive aliases explicitly.
Alert on the age of your last successful backup, not only on failures. Failure alerts get ignored; a backup that stopped running produces no failures at all.
Then restore something on purpose. An integrity check tells you the backup is consistent. It doesn't tell you that you can get a specific file back, on a bad day, in a reasonable time. Pick a file at random on a calm afternoon, restore it somewhere harmless, and compare it to the original. If that feels like a chore, notice that it is far less of a chore than finding out during an incident.
The agent that ran that cleanup did everything I'd asked of it. That was the problem. Now I ask for more, in writing, every time.