If Claude Code deleted or broke files, first stop the session, then run /rewind (or press Esc twice with an empty prompt) and choose Restore code. That brings back anything Claude changed with its own file editing tools. It does not bring back files that were only changed by shell commands such as rm or mv: for those you need Git or a backup. To stop it happening again, commit before you start, avoid bypassPermissions mode on your own machine, add deny rules for destructive commands, and turn on the Bash sandbox.
Why this is in the news
On November 14, 2026 a report about Claude deleting a law professor's files after being asked to renumber pages reached Hacker News (45 points and 64 comments when we checked). We have not verified the details of that report and do not describe it further here. What we can see is that people search for this: Google autocomplete suggests phrases such as "claude code deleted files", "claude code deleted all my files", "claude cowork deleted my files" and "claude code undo rewind". Autocomplete shows that a phrase is searched, not how often. This post sticks to what Anthropic's documentation says about recovery and prevention.
Step 1: stop, then rewind
Anthropic's checkpointing page says Claude Code "automatically tracks Claude's file edits as you work", and that every prompt you send that starts a turn creates a new checkpoint. To go back:
- Interrupt the session if Claude is still working, so nothing else changes.
- Run
/rewindor its alias/undo, or pressEsctwice when the prompt input is empty. (If the input has text in it, doubleEscclears the text instead.) - Pick the prompt you want to go back to, then choose what to restore.
| Rewind option | What it does |
|---|---|
| Restore code and conversation | Puts the files and the conversation back to that point. |
| Restore conversation | Rewinds the chat only. Files on disk stay as they are now. |
| Restore code | Puts the tracked files back and keeps the conversation, useful when you want Claude to remember what went wrong. |
| Summarize from here / Summarize up to here | Compresses part of the conversation. Does not change files on disk. |
| Never mind | Closes the menu. |
The two code options only appear when that checkpoint has tracked file changes to revert. Checkpoints are saved with the conversation, so /rewind still works after you resume a session. Claude Code keeps file snapshots for the 100 most recent checkpoints in a session and, by default, deletes them about 30 days after the session last saved one; the cleanupPeriodDays setting can keep them longer. One detail worth knowing: rewound messages can come back if you exit before sending your next prompt.
What /rewind cannot undo
This is where most "it deleted my files and undo did nothing" stories come from. Based on Anthropic's checkpointing page:
| Change | Restored by /rewind? |
|---|---|
| Edits made with Claude's file editing tools | Yes |
| Bash commands that later change a file Claude had already edited with its file tools | Yes, those changes are undone too |
Files changed only by Bash commands (rm, mv, cp, scripts, build tools) | No. The page says to use version control such as Git |
| Your own edits outside Claude Code, and edits from other concurrent sessions | Normally no, unless they touch the same files as the current session |
| Edits by most subagents | Only for files Claude had already edited in your conversation |
| Symlinked and hard-linked paths | Skipped, with a "skipped N files" warning |
The page is direct about the purpose: checkpoints "are designed for quick, session-level recovery", and for permanent history you should "continue using version control, such as Git". Nothing on the page describes checkpoints as a backup of your project, and they are not one.
Step 2: if rewind did not bring it back
- Git. Run
git statusto see what changed or disappeared. Tracked files that were deleted or modified since the last commit can be restored withgit restore <path>(orgit restore .for everything, which also throws away changes you wanted, so check first). Files that were never committed are not in Git and cannot be recovered this way. - Backups and sync history. If the folder is covered by your operating system's backups or a cloud drive with version history, restore from there. Do this before you keep working in the folder.
- Ask Claude what it ran. The conversation shows the exact commands. Knowing whether a file was deleted, moved or overwritten tells you where to look (a
mvmay have put it somewhere else).
For agents that change production systems rather than a local folder, the recovery question is bigger: see our guide to AI agent rollback and recovery.
How to prevent it
1. Commit before you hand over
Start each Claude Code task from a clean commit, ideally on a branch. Then any damage inside the repository is one git restore or git reset away, whatever tool caused it. Keep anything you cannot afford to lose, such as personal documents or notes, out of the folder you give an agent.
2. Choose the permission mode deliberately
Claude Code's permission modes are default (labelled Manual in the CLI), acceptEdits, plan, auto, dontAsk and bypassPermissions. Two are worth understanding before you use them:
acceptEditsautomatically accepts file edits and common filesystem commands such asmkdir,touch,mvandcpfor paths in the working directory. That is convenient, and it means moves and overwrites happen without a prompt.bypassPermissionsskips permission prompts. Anthropic's permissions page warns that in this mode Claude Code skips prompts "including for writes to protected paths such as.gitand.claude". Use it only in a disposable environment such as a container or VM, never on your laptop's home directory.
3. Add deny and ask rules for destructive commands
Permission rules use the form Tool or Tool(specifier), and a * in a Bash rule matches any text. Rules are evaluated deny first, then ask, then allow, and "an allow rule can't carve an exception out of a deny rule". A starting point for .claude/settings.json:
{
"permissions": {
"deny": ["Bash(rm *)", "Bash(git push *)"],
"ask": ["Bash(git reset *)", "Bash(git clean *)"]
}
}
Know the limit. Anthropic says Bash patterns that try to constrain arguments "are fragile", and that a deny rule "isn't a security boundary around the program". Its own example: Bash(rm *) stops rm -rf build/ but not /bin/rm -rf build/ or bash -c 'rm -rf build/'. Deny rules catch the usual case; they do not replace Git or the sandbox. Where settings files live, and how to keep personal approvals out of the repository, is covered in our post on Claude Code settings.local.json.
4. Turn on the Bash sandbox
The sandbox is "a boundary that the operating system enforces around the shell commands Claude runs", and it is off by default. Turn it on with /sandbox in a session, or set sandbox.enabled to true in a settings file. Once on, shell commands can write only to the working directory, a per-user temp directory and directories you add, and network access goes through a proxy whose allowed domains start empty. It runs on macOS, Linux and WSL2; on native Windows, commands run unsandboxed.
Two settings make it stricter: sandbox.failIfUnavailable set to true makes Claude Code exit at startup instead of quietly running unsandboxed when the sandbox cannot start, and allowUnsandboxedCommands set to false in the sandbox settings stops Claude from retrying a failed command outside the sandbox. If you add paths with sandbox.filesystem.allowWrite, add only what the task needs.
Note what the sandbox does not do. Writes are allowed in the working directory by default, so a sandboxed rm can still delete files inside your project, and Claude's file tools run outside the Bash sandbox. The sandbox protects the rest of your machine; Git protects the project. Our AI agent sandboxing guide compares how Claude Code and Codex sandbox commands.
5. For teams: set it once, centrally
If several developers use Claude Code, put the deny rules and sandbox settings in managed settings so a single person's local choice cannot switch them off. We cover how in Claude Code managed settings for company policy, and the wider controls in our AI agent security checklist.
How we approach this
When we use coding agents on client work, the agent runs on a branch from a clean commit, with destructive commands on deny or ask, the Bash sandbox on, and nothing in the working directory that is not in version control. We treat /rewind as a convenience for undoing a bad edit, and Git plus the client's own backups as the recovery plan. If you are rolling agents out across a team and want those defaults set up properly, talk to us.
Sources (read November 15, 2026): Anthropic, Claude Code checkpointing, Anthropic, Claude Code permissions, Anthropic, Claude Code sandboxing. The Hacker News figures were taken from the Hacker News search API on the same day.