Patterns
Hooks
This is where the real power is. Configure behaviors once, they run silently forever. Format on every edit, block secrets before they commit, load context at session start.
On this page (9 sections)
You keep forgetting. Hooks don't.
Every time you tell Claude Code "remember to run Prettier after editing" or "always check for secrets before committing," you're burning a prompt. And you're going to forget to say it eventually.
Hooks fix this permanently. They're scripts that fire automatically before a tool runs, after a tool runs, or when a session starts. Set them up once and they work silently forever.
Think of them like git hooks, but for Claude Code. And frankly, they're more useful than most git hooks you've actually written.
The three hook types
PreToolUse
Fires before Claude Code does something. This is your gatekeeper.
Use it to block writes to protected files, catch secrets before they land in code, or add a confirmation step before anything destructive.
PostToolUse
Fires after Claude Code does something. This is your cleanup crew.
Auto-format code after every edit. Run a linter on new files. Log tool usage for auditing. The stuff you'd otherwise have to nag about constantly.
SessionStart
Fires when a session begins. This is your context loader.
Remind Claude Code to read memory files. Check that env vars are set. Load the latest handoff so you never start a session cold. This one is criminally underused.
How to configure them
Hooks live in your .claude/settings.json. Each one says when to fire and what to run.
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit",
"hook": "echo 'Checking file write...'"
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hook": "npx prettier --write $CLAUDE_FILE_PATH"
}
],
"SessionStart": [
{
"hook": "echo 'Remember: Read MEMORY.md and check handoffs/ for context.'"
}
]
}
}The matcher field controls which tools trigger the hook. Pipe-separate tool names like "Write|Edit" to match multiple. Leave it out and the hook fires on every tool call.
Your first hook (30 seconds, huge payoff)
The single highest-value hook ensures Claude Code never starts a session cold. I've used this one for months and it's saved me more time than any other single config change.
{
"hooks": {
"SessionStart": [
{
"hook": "cat ~/.claude/session-reminder.txt 2>/dev/null || echo 'No session reminder found.'"
}
]
}
}Create ~/.claude/session-reminder.txt with your startup checklist:
Session startup checklist:
1. Read MEMORY.md for persistent context
2. Check _context/handoffs/ for the latest handoff
3. Resume from where the last session left off
4. If no handoff exists, ask what we're working on todayNo more "wait, you forgot about what we did yesterday." Done.
Auto-format on every edit
The second hook everyone should have. Prettier runs after every file edit so formatting is never a conversation:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hook": "npx prettier --write $CLAUDE_FILE_PATH 2>/dev/null || true"
}
]
}
}The || true keeps things moving if Prettier can't handle a file type. Always add a fallback for non-critical hooks.
Tips that actually matter
Keep hooks fast. They block the action they're attached to. A 10-second hook means Claude Code pauses 10 seconds before every tool call. Under 1 second is the target. Profile your hooks if they feel slow.
Test with echo first. Before wiring up a real script, use echo to verify the hook fires when you expect. Confirm the timing, then swap in the real command.
Don't go overboard. Three or four well-chosen hooks beat twenty noisy ones. Start with a SessionStart reminder and one PostToolUse formatter. Add more only when you feel actual friction.
Scope them right. Hooks in .claude/settings.json at the project level only fire for that project. Hooks in ~/.claude/settings.json fire globally. Project-specific formatting goes at the project level. Universal safety checks go global.
Handle failures gracefully. A crashing hook can block your entire workflow. Always add 2>/dev/null || true for non-critical hooks. Test commands independently before adding them to config.
New guides, when they ship
One email, roughly weekly. CLAUDE.md templates, workflows I actually use, and the cut-for-length stuff that does not make the public guides. One-click unsubscribe.
Or follow on Substack