Why hooks matter
Hooks From Zero to Production
Six shell scripts that run automatically to protect your environment, your git history, and your sanity. Set once. Forget it.
Why hooks matter
Claude Code can run shell commands, edit files, and interact with git on your behalf. That power is useful until it touches something it should not. Hooks are your guardrails: shell scripts that fire automatically before or after Claude acts, blocking dangerous operations and logging everything silently in the background.
Hook lifecycle
Every event Claude Code emits, and when your script runs
The 6 hooks
Click any hook to expand the script and install instructions
Intercepts every Bash command Claude tries to run and blocks anything destructive. Prevents git commit (direct), force push, reset --hard, branch -D, and rm -rf. This is your first line of defense against Claude taking irreversible actions on your codebase without explicit approval.
- git commit (direct commits bypass your review)
- git push --force (overwrites remote history)
- git reset --hard (destroys uncommitted work)
- git branch -D (deletes branches permanently)
- rm -rf (recursive force delete)
Runs before any Edit or Write operation. Outright blocks access to .env files and credential files. Issues a warning (but allows) edits to CLAUDE.md, MEMORY.md, and settings.json so you are always aware when Claude modifies its own configuration.
- .env, .env.local, .env.production (secrets)
- credentials.json, credentials.* (API keys)
- CLAUDE.md (your profile; changes affect all sessions)
- MEMORY.md (session memory; data loss risk)
- settings.json (hook config; could disable safety)
Creates a timestamped copy of any file before Claude modifies it. Backups land in ~/.claude/backups/ with the original path encoded in the filename. Automatically prunes to keep only the last 10 versions per file. This gives you instant undo without needing git, useful when you are iterating fast and have not committed yet.
Intercepts Claude's web search queries and checks if any year (2020-2029) is already present. If not, it appends the current year to the query automatically. This prevents Claude from surfacing outdated documentation, deprecated APIs, or stale advice, a common problem when Claude searches without temporal context.
Fires after every Write or Edit operation and appends a line to a daily log file at ~/.claude/changes-YYYY-MM-DD.log. Each entry records the timestamp, tool used, and file path. Gives you a complete audit trail of everything Claude touched during a session, useful for debugging, reviewing, or just knowing what happened.
Fires when Claude completes a task (Stop event). Plays the macOS Glass system sound and sends an osascript notification so you see it even if the terminal is in the background. Perfect for long-running tasks: kick off a build, switch tabs, and get pulled back when it is done.
Activate all hooks in settings.json
Wire up all six with a single config block
Add this configuration to your ~/.claude/settings.json to wire up all six hooks. Each entry maps a hook lifecycle event to the script that handles it. Once saved, hooks activate immediately on the next Claude Code session.
Debugging hooks
Three ways to verify your hooks are wired correctly
don't miss what's next.
hooks, playbooks, and automation tools that save you hours. straight to your inbox. no spam. unsubscribe anytime.
Want this running in your business, not just your terminal? Our Claude Code development agency ships it for you, or book a free consultation to scope your setup.
Day 38: Context Engineering Mastery
Day 40: Founder OS: Full System
Ready to transform your business?
Let’s turn your next automation opportunity into a system that works.
Book a Free Strategy Call