Running Claude Code unattended — overnight builds, CI pipelines, headless mode — means no human is watching when it decides to rm -rf node_modules, force-push to main, or commit your .env file. Hooks are the only safety layer that works without human oversight.
Claude Code in autonomous mode has full terminal access and makes decisions without asking. In attended sessions, you catch mistakes before they happen. In autonomous mode, every mistake executes.
Real autonomous mode incidents
Blocks rm -rf, chmod 777, mkfs, and other filesystem-destroying commands.
# Blocks: rm -rf /, rm -r -f /home, chmod -R 777 /
# Allows: rm temp.txt, rm -rf node_modules (configurable)
Blocks pushes to main/master and all force-pushes.
# Blocks: git push origin main, git push --force
# Allows: git push origin feature-branch
Blocks staging of .env files, credential files, and private keys.
# Blocks: git add .env, git add credentials.json
# Allows: git add .env.example
Detects when Claude repeats the same command 5+ times and breaks the cycle.
# Blocks: same command repeated 5+ times
# Prevents: infinite retry loops burning tokens
Warns when the context window is running low, preventing compaction-related mistakes.
# Warns: context usage above 80%
# Prevents: uncontrolled compaction and post-compact drift
npx cc-safe-setup
Installs 8 hooks (the 5 above plus syntax checking, session handoff, and auto-approve for safe read commands). Takes 10 seconds. No dependencies.
# Check all hooks are installed and working
npx cc-safe-setup --doctor
# Run the audit (0-100 safety score)
npx cc-safe-setup --audit
# Full health check
npx cc-health-check
npx cc-safe-setup
Process-level protection that works even when the model forgets instructions. 9,200+ tests 655 examples
GitHub · npm · Getting Started
Open source, zero dependencies. View source.
Related: rm -rf · force-push · if field · autonomous · all tools
Learn more: Production Guide · All Tools