Short answer: Add deny rules for delete commands in Claude Code’s settings, or add a PreToolUse hook that blocks them before they run. For a ready-made guard that also covers databases, cloud and secrets, install Antelog with one command.
Why it happens
Claude Code runs shell commands for you. When you turn off the permission prompts, or click “yes” without reading, a single wrong rm -rf can delete your project, your home folder or your unpushed work. Files deleted this way skip the Trash.
Option 1: deny rules in settings
Claude Code reads permission rules from ~/.claude/settings.json (all projects) or .claude/settings.json (one project). A deny rule blocks a command even in auto-accept modes:
{
"permissions": {
"deny": ["Bash(rm -rf:*)", "Bash(git push --force:*)"]
}
}
This is simple, but it only matches the exact start of a command. cd / && rm -rf x, find . -delete or a Python script that deletes files are not caught.
Option 2: a PreToolUse hook
A hook is a small program Claude Code runs before every tool call. If it exits with code 2, the call is blocked and Claude is told why. See how to write one.
Option 3: install a guard
Antelog is a free hook that is already written and tested. It checks every action before it runs, blocks deleting your project, home folder or code history, and also covers databases, cloud resources and leaked secrets. Normal clean-up like node_modules or dist still runs.
Install Antelog
Free for developers. On macOS and Linux:
$ curl -fsSL https://antelog.dev/install.sh | shWindows and other tools: see the docs.