← cc-safe-setup

How to Stop Claude Code from Deleting Your Files

April 20, 2026 · 5 min read · by yurukusa

TL;DR: Claude Code can and does run rm -rf on user directories. It has destroyed 50+ GB of data across multiple incidents. Run npx cc-safe-setup to install a hook that blocks it. Takes 10 seconds.

The Incidents

These are real reports from GitHub Issues on the anthropics/claude-code repository. Each one involves actual data loss.

#49129 — 50 GB / 1,500 files permanently deleted

Claude ran rm -rf and permanently destroyed approximately 50 GB of data and 1,500 files from a user's directory. April 2026.

#49554 — All SSH keys wiped

Auto mode approved deletion of ~/.ssh. Every SSH key on the machine was gone. No confirmation prompt was shown to the user.

#49539 — Git credentials deleted

~/.git-credentials containing Personal Access Tokens was deleted without confirmation. Access to all repositories revoked instantly.

#46058 — 3,467 files / ~7 GB deleted

Claude decided to "clean up" a project directory. 3,467 files totaling roughly 7 GB were removed with a single rm -rf command.

#36339 — Entire user directory via NTFS junction

On Windows (WSL), Claude followed an NTFS junction point and deleted the entire user directory. The junction made a project subdirectory point to ~.

Why This Happens

Claude Code executes shell commands to accomplish tasks. When it decides a directory is "unnecessary" or wants to "start fresh," it reaches for rm -rf — the same command any developer would use. The difference is that Claude doesn't have the intuition for "wait, that's my home directory."

The built-in permission system helps, but has gaps:

The Fix: 10 Seconds

Install cc-safe-setup:
npx cc-safe-setup

This installs 8 safety hooks into your ~/.claude/settings.json. The prevent-rm-rf hook intercepts every Bash command and blocks any rm that targets dangerous paths (/, ~, .git, .ssh, .env, and more).

How the Hook Works

Claude Code fires a PreToolUse event before every tool execution. The hook receives a JSON payload with the command about to run:

{
  "tool_name": "Bash",
  "tool_input": {
    "command": "rm -rf ~/projects"
  }
}

The prevent-rm-rf hook parses the command, checks it against a blocklist of dangerous patterns, and returns a DENY response if it matches:

#!/bin/bash
# Simplified — real hook handles more edge cases
CMD=$(cat | jq -r '.tool_input.command // empty')

if echo "$CMD" | grep -qE 'rm\s+(-[rfRF]+\s+)*(/|~|\.git|\.ssh|\.env)'; then
  echo '{"decision":"DENY","reason":"Blocked: destructive rm targeting protected path"}'
fi

The command never executes. Claude sees the denial message and adjusts its approach — usually by asking what you'd like to do instead.

What Else Gets Blocked

The 8 default hooks from cc-safe-setup also protect against:

Beyond the Defaults: 700+ Example Hooks

The repository includes 700+ additional hook examples organized by category. Some highlights:

Use the Hook Selector to find hooks for your specific workflow.

Don't wait for the incident

Every incident above happened to someone who thought "it won't happen to me."

Install cc-safe-setup Read the Survival Guide

Tracking 73+ real incidents from GitHub Issues · Token optimization guide →