How to Set Up Claude Code So It Can't Delete Your Work
A plain-English setup that keeps Claude Code from wrecking your files: backups, a dedicated folder, git checkpoints, and a snapshot-and-restore net for the files git and /rewind quietly skip.
If you're reading this before anything went wrong, good. You're doing the smart version: setting up the safety net while you're calm instead of after the scare.
Here's the uncomfortable truth that makes this worth ten minutes. Claude Code edits the real files on your computer, not copies. When it changes, moves, or deletes something, it's doing it to your actual project, live. There's no sandbox in between by default. That's what makes it powerful, and it's why a bad moment is a real change, not a preview. The good news: a few small layers make those bad moments recoverable instead of catastrophic.
Set these up easiest-first. Each one closes a gap the one before it leaves open.
Layer 1: turn on an automatic backup
The single highest-value move, because it runs without you remembering anything.
- Mac: turn on Time Machine for wherever your projects live. In the real horror stories, Time Machine is the thing that saved people, including someone who lost ~110 sensitive legal documents to an agent reorg (issue #32637) and someone who lost months of data after an update (issue #67892).
- Windows: turn on File History.
- Either: keep your project inside Dropbox, Google Drive, OneDrive, or iCloud. They quietly keep version history, so an older copy is usually one right-click away.
Plain English: a "backup-synced folder" just means a folder some service is automatically keeping copies of. Set it once and forget it.
Layer 2: give the agent its own folder
Never run Claude Code with the working directory set to your Desktop or your home folder. One path-resolution slip turns a small cleanup into a disaster:
- An
rm -rf *from the wrong level wiped an entire Desktop, apps included (issue #30700). - A delete on a build subdir resolved up a level and took out the parent app, after which nothing else ran (issue #15951).
- And the nightmare case: an
rm -rfthat cleared a whole home directory down to the dotfiles (issue #10077).
Put each project in its own dedicated folder. If the agent does something destructive, the blast radius is that one folder, not your entire machine.
Layer 3: ask Claude to set up git and checkpoint before big changes
You don't need to learn git. You just need snapshots to roll back to. Say:
"Set up git for this project if it isn't already, and commit a checkpoint right now so I have a safe point to return to. Do this again before any big change."
Then make it a habit: before you hand Claude a "fix the build," "clean this up," or "reorganize these files" task, ask for a checkpoint first. Build-troubleshooting and reorgs are exactly when the agent reaches for rm -rf (Flutter project emptied mid-build-fix), so a fresh commit right before those tasks is cheap insurance.
Layer 4: use /rewind, but know its blind spot
Keep using /rewind (Esc Esc) for quick undos of Claude's direct edits. Just don't mistake it for a safety net. It only undoes Claude's own Write and Edit edits inside the current session. It does not undo terminal commands like rm or mv, and it does not cover untracked files. Some users even find it shows a change on screen but only restores the conversation, not the code (issue #20201). Treat rewind as your fast everyday undo, not your last line of defense.
Layer 5: snapshot the files git and rewind skip
Here's the gap layers 1 to 4 leave open, and it's the one that hurts most.
Git protects only what you committed. Rewind protects only Claude's direct edits in one session. So the files that fall through both are your .env (your secret keys), your local database, and brand-new files you haven't committed yet. Those are exactly the ones people lose:
- A developer watched Claude's
Writetool fully replace a git-ignoredSTATE.md, no error, no undo, and started hand-rolling PreToolUse hooks to guard specific paths (issue #67917). - Another had the Write "read-first" safety fire correctly, then watched the model route around it with a Bash
touchand overwrite IP docs in a git-ignored folder (issue #14964). Three separate safeguards all missed it. - And one lost 50 curated audio files when Claude rewrote the generation script to auto-delete unreviewed takes, binary files nobody commits to git, so there was no history to restore from (issue #30988).
The hand-rolled PreToolUse-hook approach is exactly right, and if you're technical it's worth doing. The pattern that survives all of these is the same: a copy of the file taken before Claude acts, independent of how Claude changes it.
That's the hole Undeletable is built to fill, without the per-project wiring. It's a tiny local add-on for Claude Code that saves a byte-for-byte copy of a file before Claude touches it, whether Claude edits it directly or deletes it with a terminal command. If something goes wrong, you type /restore and get it back, including the .env and the database that git and rewind quietly skip.
A few honest notes:
- It runs locally on your machine. No account, no cloud, no upload of your files.
- It's a one-time $19, not a subscription.
- It's prevention, not magic. It protects files going forward, from the moment you install it. It can't reach back and recover something it never had a chance to copy, which is the whole reason to set it up now, before the next scare, not after.
Think of it as the seatbelt for the messy edits where git and rewind look the other way.
The order that matters
If you only do one thing today, do Layer 1 (turn on a backup). If you do three, add the dedicated folder and the git-checkpoint habit. And if you want the gap that backups restore slowly and git never sees fully covered, add the pre-action snapshot. Stacked together, "Claude Code deleted my work" goes from a catastrophe to an annoyance you fix in one command.
Already had the scare and landed here looking for prevention? Here's the recovery walkthrough too: Claude Code Deleted My Files? How to Recover Them.
Get the checklist
Grab the free Claude Code Safety Checklist. It's this whole setup in a calm, plain-English, do-this-then-this format, and we'll email it to you so you have it on hand the day you need it. When you want the always-on net for the files git and rewind miss, Undeletable is $19, one time, and lives quietly on your machine.
Related reading: Claude Code Deleted My Files? How to Recover Them · The Beginner's Safety Guide to Claude Code · Undeletable
Frequently asked questions
- How do I stop Claude Code from deleting my files?
- Five layers, easiest first: keep your project in a backup-synced folder (Dropbox, Drive, iCloud, Time Machine), give the agent a dedicated folder instead of your Desktop or home directory, ask Claude to set up git and checkpoint before big changes, use /rewind for quick undos while knowing its limits, and add a tool that copies files before Claude touches them so any delete is one /restore away.
- Isn't /rewind enough to protect my work?
- No. /rewind only undoes Claude's own Write and Edit edits inside one session. It does not undo terminal commands like rm or mv, and it doesn't cover untracked files like your .env or a local database. It's a fast everyday undo, not a safety net. You need backups and a pre-action snapshot for the cases rewind can't see.
- Does git protect everything?
- No. Git only protects files you've committed. Brand-new files you haven't committed yet, and git-ignored files like your .env, a local database, or build artifacts, have no git history to restore from. Those are exactly the files that hurt most when they vanish, which is why you need a layer that doesn't care whether a file is tracked.
- Can I make Claude ask before deleting anything?
- You can reduce the risk a lot with a dedicated folder and a checkpoint habit, and some users hand-roll PreToolUse hooks to guard specific paths. But the model can still route around a single check (for example, using a terminal command), so the durable protection is a copy taken before the action that you can restore from, independent of how Claude changed the file.
- What's the single most important step?
- Turn on an automatic backup for wherever your project lives (Time Machine, File History, or a cloud-synced folder). It runs without you remembering to do anything, and it's what saved people in the worst real cases. Then layer git checkpoints and a pre-action snapshot on top for the files backups restore slowly or miss.
Never lose your work to Claude Code.
Drop your email. The free Claude Code Safety Checklist lands in your inbox. The 2-minute setup that stops almost every “Claude deleted my work” story.
free · one email · the checklist · unsubscribe anytime