Hooks in Claude Code are shell commands that run automatically in response to events. Think of them as git hooks, but for your AI coding agent.
I run 45 hooks that handle everything from pre-commit quality gates to post-deploy verification. Here are the most impactful ones.
What Are Hooks?
A hook is a shell command that fires when Claude Code does something. Events include:
- PreToolUse: Before a tool runs (file edit, bash command, etc.)
- PostToolUse: After a tool completes
- UserPromptSubmit: When you send a message
- Stop: When Claude finishes its response
Each hook can inspect the event, modify behavior, or block the action entirely.
My Top 10 Hooks (Ranked by Impact)
1. Credential Auto-Injector
Event: UserPromptSubmit
Detects when the conversation mentions a service (Stripe, GitHub, etc.) and auto-injects available credentials from the vault. No more asking for API keys.
2. Research Reminder
Event: PreToolUse (on file writes)
Before writing to a file, checks if Claude has READ the file first. If not, blocks the edit. This single hook eliminated 80% of blind edit errors.
3. Build Verification
Event: PostToolUse (on file writes)
After any source file is modified, automatically runs the build. No more batching 10 changes then discovering the first one broke everything.
4. Security Scanner
Event: PreToolUse (on bash commands)
Scans commands for dangerous patterns: destructive deletions, database drops, force pushes, exposed secrets. Blocks and explains why.
5. Legal Guard
Event: PreToolUse (on browser automation)
Before any Playwright action on an external platform, checks compliance with platform ToS and relevant laws.
6. Git Context Injector
Event: UserPromptSubmit
Auto-injects current git branch, recent commits, and uncommitted changes. Claude always knows the repo state.
7. Failure Pattern Matcher
Event: PostToolUse (on build failures)
Matches errors against 220+ known failure patterns with proven fixes. Instead of debugging from scratch, it says this matches pattern #47 and provides the fix.
8. Context Enricher
Event: UserPromptSubmit
Enriches every prompt with relevant project context: architecture decisions, recent changes, known issues.
9. Session State Tracker
Event: Stop
Updates session state after every response with what was done, what is in progress, and next steps. Enables seamless session resumption.
10. Quality Gate
Event: PreToolUse (on git commit)
Runs build + tests + type check + lint before any commit. Blocks if anything fails. Zero broken commits.
Results
| Before Hooks | After Hooks |
|---|---|
| Blind edits broke files weekly | Zero blind edits in 3 months |
| Secrets leaked to logs twice | Zero leaks |
| 30% of commits broke the build | Zero broken commits |
| Forgot context between sessions | Perfect session continuity |
Getting Started
- Start with ONE hook: the read-before-write guard
- Add git context injection next
- Then build verification
- Scale from there based on what errors you see most
The goal: make it impossible for the AI to make common mistakes.
45 hooks, 13 MCP servers, 146 commands — this is the WEDGE Method infrastructure powering autonomous AI consulting.
What hooks are you running? Share your setup in the comments.
Top comments (0)