Hooks are your superpower
Lifecycle interceptors that run outside the LLM loop. Zero token cost. Total control. 8 events. 3 exit codes. Infinite patterns.
The 8 lifecycle events
Every hook targets one of these events. Know when each fires and you can intercept anything.
| Event | When it fires | Primary use | Type |
|---|---|---|---|
| PreToolUse | Before any tool executes | Validation, blocking, context prep | sync |
| PostToolUse | After any tool completes | Context injection, feedback loops | sync |
| SessionStart | Session opens | Load git status, PRs, env info | either |
| Stop | Claude finishes responding | Notifications, cost logging | either |
| Notification | Claude needs user input | Alert integrations, paging | async |
| InstructionsLoaded | CLAUDE.md files loaded | Validate config, inject extra context | sync |
| WorktreeCreate | New worktree created | Scaffold project, install deps | either |
| WorktreeRemove | Worktree removed | Cleanup, archiving | async |
Three outcomes, total control
Your hook's exit code tells Claude exactly what to do next.
The feedback loop
exit 0 + JSON on stdout = Claude proceeds AND receives your context. This is how you build self-correcting workflows.
Three ways to hook in
Pick the right type for your use case. Each has different capabilities and costs.
Fire and forget
Async hooks run in the background. Claude doesn't wait. Exit codes are ignored. Perfect for logging, notifications, and analytics.
timeout: 0 in your hook config to make it async. The hook runs but Claude moves on immediately — no blocking, no delays.Target exactly what you need
Matchers filter which tool calls trigger your hook. Combine event + tool + path for precision.
10 patterns you can use today
Copy any of these into your .claude/hooks/ folder. Each is production-ready.
ESLint runs after every file edit. If errors are found, the JSON output tells Claude exactly what to fix — zero manual intervention.
Logs token usage and estimated cost to a daily CSV file. Runs asynchronously so Claude is never blocked.
Blocks any write to a non-active client folder. Set ACTIVE_CLIENT in your environment and Claude cannot touch other clients' files.
Scans staged files for API keys, tokens, and passwords before any git commit. Blocks the commit if secrets are detected.
Sends a Slack message whenever Claude modifies a config file. Uses an HTTP webhook — no extra dependencies required.
A prompt hook evaluates bash commands semantically. Regex cannot catch everything — the LLM decides if a command is safe.
Creates a timestamped backup of any file before Claude edits it. Maintains the last 10 versions automatically.
Extracts the Jira ticket ID from the current branch name and moves the ticket to In Review when Claude pushes code.
Plays a sound and sends a macOS notification when Claude finishes. You can walk away and come back when it is done.
Loads git status, open PRs, and environment info at session start. Claude begins every session fully oriented.
Build your own hook
Configure your hook and get the settings.json config and shell script instantly.
Configuration
Generated Config
Test your hooks knowledge
5 questions. Pick the best answer.
You know advanced hooks
8 lifecycle events. 3 exit codes. 3 hook types. 10 production patterns. One hook builder. Now go ship something great.
.claude/hooks/ and add the config to .claude/settings.json.