modul 2 — the toolbox in depth
hooks: rules that always run
CLAUDE.md is a request; a hook is a guarantee. Attach shell commands to the agent's lifecycle and the rule executes every time – no model judgment involved.
~2 min read · ~9 min with the exercise · v1.1 · verified: 2026-07-15
when asking is not enough
Everything in this course so far asks the agent to behave: CLAUDE.md, skills, your requests. The agent follows instructions well, but "well" is not "always", and some rules can't afford exceptions. Formatting must run after every edit. A protected file must never be touched. That's what a hook (a user-defined command that the tool executes automatically at a fixed point in the agent's lifecycle – deterministically, without asking the model) is for: the official docs define hooks as commands that "execute automatically at specific points in Claude Code's lifecycle". Not a suggestion the model weighs, but code that runs.