turnslip

Stop Claude Code from running rm -rf and git reset --hard

Last updated: 7 October 2026

Since v2.1.283, interactive Claude Code sessions start in auto mode: a classifier model reviews Claude's actions instead of you, and routine commands run without a prompt (permission modes). Two settings put a question, or a refusal, in front of the commands you care about. Neither is airtight, so this page also says what they miss.

1. Ask rules in your settings

Permission rules live in a settings file: .claude/settings.json applies to "everyone working in the folder that contains it", ~/.claude/settings.json to "you, in every project on this machine" (settings documentation). This makes Claude Code ask before the usual destructive commands:

{
  "permissions": {
    "ask": [
      "Bash(rm *)",
      "Bash(git reset --hard *)",
      "Bash(git clean *)",
      "Bash(git checkout -- *)",
      "Bash(git push --force *)",
      "PowerShell(Remove-Item *)"
    ]
  }
}

How the rules apply, from the documentation:

Checked on 7 October 2026 with Claude Code 2.1.292: with "ask": ["Bash(rm *)"] and every Bash command otherwise allowed, a non-interactive session asked to run rm -rf build got "Claude requested permissions to use Bash, but you haven't granted it yet." and the folder stayed; without the rule it was deleted. The screen above is the same rule in an interactive session.

What the rules miss: a rule matches the command text Claude writes, so Bash(rm *) stops rm -rf build/ but not /bin/rm -rf build/ or bash -c 'rm -rf build/'. The permissions documentation says such a rule "isn't a security boundary around the program".

Ask rules hold even when prompts are switched off: Claude Code "doesn't auto-approve the following in any mode, including bypassPermissions", and the first item is "Tools matched by an explicit ask rule" (permission modes). Of that mode the permissions documentation still says: "Only use this mode in isolated environments like containers or VMs where Claude Code can't cause damage."

2. A PreToolUse hook

A hook runs your own script before a tool runs and can refuse it. This is the example from the hooks documentation, How a hook resolves. In your settings file, the matcher narrows to Bash calls and the if condition to subcommands matching rm *:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "if": "Bash(rm *)",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-rm.sh",
            "args": []
          }
        ]
      }
    ]
  }
}

The script returns a permissionDecision of "deny" when the command contains rm -rf. Save it as .claude/hooks/block-rm.sh and make it executable with chmod +x .claude/hooks/block-rm.sh; it needs jq:

#!/bin/bash
# .claude/hooks/block-rm.sh
COMMAND=$(jq -r '.tool_input.command')

if echo "$COMMAND" | grep -q 'rm -rf'; then
  jq -n '{
    hookSpecificOutput: {
      hookEventName: "PreToolUse",
      permissionDecision: "deny",
      permissionDecisionReason: "Destructive command blocked by hook"
    }
  }'
else
  exit 0  # no decision; normal permission flow applies
fi

It looks for the text rm -rf, so rm -fr build gets through, and it misses the disguised forms above too. The hooks documentation itself advises: "use the permission system rather than a hook to enforce a hard allow or deny". A hook is for checks a rule cannot express.

3. A backstop: see what happened, and undo it

Where each safeguard acts Ask and deny rules and a PreToolUse hook act before a command Claude writes runs. turnslip acts after the turn: it shows what changed and can put files back. Claude writes a command Before it runs Ask / deny rules in settings.json PreToolUse hook your own script The command runs After the turn turnslip shows what changed /turnslip:undo puts files back
Rules and hooks can stop a command; turnslip cannot, it shows and undoes what a turn did.

Rules and hooks only stop what they match. turnslip is detection, not prevention: after each turn it shows one line with what changed on disk, including a deletion count, and /turnslip:undo puts the turn's files back, files a shell command removed included. It does not keep paths your .gitignore excludes, and a database migration or a git push stays done. Commit before large requests as well.

If files are already gone: Claude Code deleted my files: what can still come back.

Related: How to undo Claude Code changes · All guides · Install turnslip, free