Skip to content

Instantly share code, notes, and snippets.

@yurukusa
Last active May 2, 2026 08:11
Show Gist options
  • Select an option

  • Save yurukusa/1122dfa65919aef721381a4df0d065f5 to your computer and use it in GitHub Desktop.

Select an option

Save yurukusa/1122dfa65919aef721381a4df0d065f5 to your computer and use it in GitHub Desktop.
CC Safety 101

Claude Code Safety 101: From Zero to Protected in 60 Seconds

Claude Code is powerful. It can write code, run commands, push to git, and modify any file on your system.

That last part should concern you.

By default, Claude Code has no safety rails. No command is blocked. No file is protected. A user recently lost their entire C:\Users directory when Claude ran rm -rf that followed NTFS junctions.

Here's how to fix that in 60 seconds.

Step 1: Install safety hooks

npx cc-safe-setup

This installs 8 hooks that:

  • Block rm -rf /, git reset --hard, git clean -fd
  • Prevent pushes to main/master
  • Stop git add .env from leaking secrets
  • Catch syntax errors after every file edit
  • Warn when context window is running low

Step 2: Verify

npx cc-safe-setup --doctor

13 automated checks. Everything should show a checkmark.

Step 3: Test it

npx cc-safe-setup --simulate "rm -rf /"
# BLOCK — destructive-guard

npx cc-safe-setup --simulate "git status"
# This command would trigger a permission prompt

That's it. 60 seconds. Your Claude Code session is now protected against the most common accidents.

Going further

Reduce permission prompt fatigue:

npx cc-safe-setup --install-example auto-approve-readonly

Auto-approves cat, ls, grep, git log — commands that can't modify anything. Reduces prompts by ~80%.

Maximum safety for overnight sessions:

npx cc-safe-setup --shield

Why hooks instead of CLAUDE.md rules?

CLAUDE.md rules live in the AI's context. When context fills up and gets compressed, rules can be lost. Hooks run at the process level — outside the AI's context. They can't be forgotten, ignored, or "interpreted as an exception."

Exit code 2 from a hook = the tool call is physically blocked. The AI cannot bypass it.


cc-safe-setup is open source (MIT). 718 hooks, 9,200+ tests.

GitHub: github.com/yurukusa/cc-safe-setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment