The Essential Five
- Auto-lint
- Block .env
- Run tests
- Guard config
- Auto-format
Run your linter after every file edit so Claude sees and fixes issues immediately.Why: Catches style violations in real-time instead of accumulating them. Claude sees the linter output and self-corrects on the next edit.
Where to Configure
Hooks go in your settings files:| File | Scope |
|---|---|
.claude/settings.json | Team-shared (commit to git) |
.claude/settings.local.json | Personal (gitignored) |
~/.claude/settings.json | All your projects |
.claude/settings.json. Personal preferences go in local or user settings.
Beyond the Essential Five
Hooks fire on 12 lifecycle events — not justPreToolUse and PostToolUse:
| Event | When it fires | Use for |
|---|---|---|
SessionStart | Session begins (new, resume, or post-clear) | Load context, run diagnostics |
UserPromptSubmit | Before Claude processes your message | Skill activation, input validation |
PreToolUse | Before a tool executes | Block dangerous actions |
PermissionRequest | When Claude requests permission | Automated approval/denial |
PostToolUse | After a tool executes | Auto-lint, auto-format, run tests |
PostToolUseFailure | After a tool fails | Error reporting, fallback logic |
SubagentStart / SubagentStop | Agent lifecycle | Agent monitoring, logging |
Stop | Before Claude finishes responding | Enforce completion conditions (all tests pass, all tasks done) |
PreCompact | Before context compaction | Backup critical state |
Setup | During initial setup | Onboarding automation |
SessionEnd | Session closes | Cleanup, transcript backup |
0 = allow, 1 = block the action, 2 = force Claude to continue (useful for Stop hooks that enforce quality gates).
Setup hooks can run in deterministic mode (fast, CI-friendly) or agentic mode (supervised, with diagnostics). HTTP hooks POST events to endpoints instead of running local scripts — useful for centralized logging and remote validation.
Hook Design Principles
- Fast hooks only. Hooks run synchronously — a slow hook slows every action. Keep them under 2 seconds.
- Fail open for warnings, fail closed for security. Lint warnings shouldn’t block work.
.envprotection must. - Use
|| truefor non-critical hooks. A crashing linter shouldn’t halt Claude’s workflow. - Test your hooks manually first. Run the command yourself before adding it as a hook.