Claude Code deleted my files. Here is how to stop the next one.

First, get it back

  1. Stop the agent session before it runs anything else.
  2. Tracked files: run git status and restore only the paths it lists as deleted, for example git restore -- src/app.js. Do not run git restore .: it also throws away uncommitted edits in files that survived. Committed work is in git reflog.
  3. Untracked files: check your editor's local history, Time Machine or your backup. rm does not use the Trash.

Then stop the next one

A line in CLAUDE.md is a request the model can forget. A PreToolUse hook runs before every command and can refuse it. This is what ThumbGate's hook answers when the agent tries rm -rf ~ (default install, recorded Dec 2, 2026, reasoning lines cut):

{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "[GATE:rm-rf-home-or-root] Broad rm -rf against root, home or a top-level home folder is blocked. Name the folder you mean, at least two levels under home."}}

rm -rf on your home folder or the root is Denied on a default install, the first time. A delete inside your project (for example rm -rf ./src) gets a Warning by default. Give that one a thumbs-down and the same command is Denied the next time, with your reason.

One command, free

Adds the hook to Claude Code. No account; the checks run on your machine.

$ npx thumbgate init --agent claude --ref deleted-my-files

What it does not catch

A reworded delete is not caught: after a thumbs-down on rm -rf ./src, python3 -c "shutil.rmtree('src')" still runs. ThumbGate is a check before the command, not a sandbox.

Free keeps 3 learned rules active. Pro keeps all of them.