Claude Code Hooks: 5 Automations That Eliminate Developer Friction
Stop clicking approve buttons and losing flow state. These 5 production-ready hooks transform Claude Code from assistant to autonomous teammate.
Problem: You're deep in flow state, building a feature. Claude needs to write a file. Click approve. Run a command. Click approve. Format code. Click approve. Twenty interruptions later, you've forgotten what you were building.
Quick Win: Add this to .claude/settings.json and never approve a Prettier format again:
Every file Claude writes now auto-formats. Zero clicks. Zero context switches.
The 8 Hook Types (Quick Reference)
Hooks intercept Claude Code events and execute shell commands. Here's what triggers each:
| Hook | When It Fires | Best Use |
|---|---|---|
| PreToolUse | Before any tool runs | Block dangerous operations |
| PostToolUse | After tool completes | Auto-format, lint, log |
| PermissionRequest | Before permission dialog | Auto-approve safe commands |
| SessionStart | Session begins | Inject context (git status, TODOs) |
| Stop | Claude finishes responding | Run tests, validate output |
| PreCompact | Before context compaction | Backup transcripts |
| SubagentStop | Subagent completes | Validate agent output |
| UserPromptSubmit | You hit enter | Inject instructions, validate input |
Hook 1: Auto-Format on Save
The formatter hook above runs Prettier after every Write or Edit. Extend it for your stack:
Multiple hooks run in parallel. Your code is formatted AND linted before Claude's response appears.
Hook 2: Session Context Injection
Start every session with project awareness:
Claude now sees uncommitted changes and pending TODOs before you say anything.
Hook 3: Auto-Approve Safe Commands
Tired of approving npm test every time? Use PermissionRequest:
The hook returns JSON with decision: approve. Test commands run without prompts.
Hook 4: Test After Implementation
Catch bugs immediately with a Stop hook:
Every time Claude finishes responding, tests run. Failures appear in context.
Hook 5: Skill Activation (ClaudeFast)
The Skill Activation Hook appends skill recommendations to your prompts:
Type "implement a feature" and Claude sees which skills to load. No memory required.
Configuration Locations
Three places to configure hooks:
| Location | Scope | Use Case |
|---|---|---|
.claude/settings.json | Project (shared) | Team standards |
.claude/settings.local.json | Project (personal) | Your preferences |
~/.claude/settings.json | All projects | Global defaults |
Project settings override user settings.
When Things Go Wrong
Hook not triggering
Check matcher syntax. Write|Edit works. Write | Edit (spaces) fails.
Command failing silently
Add logging: your-command 2>&1 | tee ~/.claude/hook-debug.log
Too slow Hooks have 60-second timeout. For slow operations, run in background.
Start With One Hook
Pick your biggest friction point:
- Constant formatting? Add PostToolUse formatter
- Approving safe commands? Add PermissionRequest auto-approve
- Missing context? Add SessionStart injection
One hook. One friction point eliminated. Then iterate.
Next Steps
- Install the Permission Hook for intelligent auto-approval
- Set up Skill Activation for automatic skill loading
- Learn configuration basics for complete Claude Code setup
Last updated on