Claude Code Auto Mode Safety Guide

Auto Mode in Claude Code runs tools without asking for permission. No "Allow this command?" prompts. No confirmation dialogs. This is powerful for autonomous work — and dangerous without guardrails.

What Auto Mode Changes

BehaviorNormal ModeAuto Mode
rm -rf /Asks for permissionRuns immediately
git push --forceAsks for permissionRuns immediately
git add .envAsks for permissionRuns immediately
Edit any fileShows diff firstEdits immediately

Auto Mode + No Hooks = No Safety Net

CLAUDE.md rules are suggestions. In Auto Mode, Claude doesn't pause to reconsider rules before acting. If it decides rm -rf is the right approach, it executes immediately. The only thing that can stop it is a hook.

How Hooks Work in Auto Mode

Hooks run at the process level, outside the model's control. They execute before (PreToolUse) or after (PostToolUse) every tool call — regardless of whether Claude is in normal mode or Auto Mode.

This means a hook that exits with code 2 blocks the operation even in Auto Mode. The model cannot bypass hooks.

Example: Block rm -rf in Auto Mode

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": "bash -c 'CMD=$(cat | jq -r \".tool_input.command // empty\"); echo \"$CMD\" | grep -qE \"rm\\s+-rf\\s+(/|~)\" && exit 2; exit 0'"
      }]
    }]
  }
}

Add this to ~/.claude/settings.json. Claude will never be able to run rm -rf / or rm -rf ~/, even in Auto Mode.

Essential Hooks for Auto Mode

If you're running Auto Mode, these 8 hooks are the minimum safety net:

  1. destructive-guard — blocks rm -rf, git reset --hard, chmod 777
  2. branch-guard — prevents push to main, force-push
  3. secret-guard — catches git add .env, credential files
  4. syntax-check — validates files after every edit
  5. context-monitor — warns before context fills up
  6. npm-publish — prevents accidental publishes
  7. response-budget — limits runaway sessions
  8. commit-msg — enforces commit message quality

Install All 8 in 10 Seconds

npx cc-safe-setup

Works in Auto Mode. Blocks dangerous operations before they execute. 9,200+ tests 655 examples

GitHub · npm · Getting Started Guide

Want More Than 8 Hooks?

Browse 655 example hooks covering security, code quality, deployment, and monitoring:

npx cc-safe-setup --examples

Check Your Safety Score

npx cc-health-check

Free 20-point diagnostic. If you're using Auto Mode and your score is below 80, you have gaps.

Related

cc-safe-setup is open source, zero dependencies, and installs nothing globally. View source on GitHub.

New: Hook if field — reduce overhead (v2.1.85)

Learn more: Production Guide · All Tools