What are hooks?
In Level 9 you learned to write things in CLAUDE.md — “always run the formatter after editing,” “never touch the migrations folder.” That works most of the time. But it’s a request. Claude reads it, usually follows it, and occasionally — busy, distracted by a hard problem — forgets.
For the rules that absolutely cannot be forgotten, you want something stronger.
A hook is a command that the Claude Code program runs automatically at a specific moment — like every time a file is edited, or just before any command runs. It fires no matter what Claude decides, because the harness runs it, not the model.
That last part is the whole point, so let’s sit on it.
Asking vs. guaranteeing
There are two different actors here, and hooks live with the reliable one.
- The model is Claude’s brain. Smart, but it makes judgment calls — and judgment can vary.
- The harness is the program wrapped around the brain (the thing you installed in Lesson 2.2). It’s plain software. It does exactly what it’s configured to do, every single time.
CLAUDE.md talks to the model — “please do this.” A hook is wired into the harness — “this will happen.” One is a sticky note on the fridge. The other is the smoke detector that goes off whether or not anyone remembered to watch the stove.
If forgetting it even once is a real problem, it’s a hook — not a line in
CLAUDE.md.
Hooks fire on events
You don’t write a hook to run “whenever.” You attach it to a moment in Claude’s work. The common ones:
- PreToolUse — just before Claude uses a tool (runs a command, edits a file). This one can even block the action. A hook here can catch
rm -rfand refuse it before it runs. - PostToolUse — just after. The classic: a file was edited, so run the formatter on it now.
- UserPromptSubmit — right after you hit enter, before Claude sees your message.
- Stop — when Claude finishes and hands the turn back to you. Good for a “done!” sound or a desktop notification.
Each event hands your hook some information (which tool, which file, what command) so it can decide what to do.
What people actually use them for
The honest list is short and practical:
- Auto-format every file the moment Claude edits it, so the code is always tidy.
- Block dangerous commands — a
PreToolUsehook that refuses to let anything touch production. - Run the linter or tests after a change and feed failures back so Claude fixes them.
- Notify you — a sound or a phone push when a long task finishes, so you can walk away.
Notice the theme: these are the boring, must-happen-every-time chores. That’s the sweet spot. Hooks turn “I hope Claude remembers” into “the machine handles it.”
What’s next
Now the satisfying part: you’ll actually write one. A short hook that runs every time Claude edits a file — and you’ll see it fire on its own.