Quiz
Hooks: rules the harness enforces so the agent cannot forget
Check what you learned
10 questions from this lesson. Answers are checked as you go; nothing is recorded.
1 / 10
What is the difference between a CLAUDE.md rule and a hook?
Hint
The note and the lock.
CLAUDE.md is followed "almost every time." A hook runs every time, whatever the agent thinks.
2 / 10
According to Anthropic, what is the sign that a rule belongs in a hook?
Hint
Capital letters are a clue.
"If you keep adding emphasis to a CLAUDE.md line and Claude still misses it, that's a sign the line belongs in a hook."
3 / 10
Which hook moment runs just before the agent edits a file or runs a command?
Hint
Before the tool.
PreToolUse runs before a tool is used, which is where blocking makes sense.
4 / 10
What does exit code 2 from a hook do?
Hint
Blocked, with a reason.
Exit 2 blocks, and what the hook printed goes back to the agent so it can change course.
5 / 10
What does a matcher such as Edit|Write do?
Hint
Narrows it.
A matcher means the hook only runs for the tools named, such as edits and writes.
6 / 10
The Stop hook in Anthropic's example blocks the finish when what happens?
Hint
No finishing with errors.
It runs the type checker and exits with 2 if it fails, so the agent has to fix the errors.
7 / 10
Where would you put a hook that should apply to every project on your computer in Claude Code?
Hint
Your home folder.
Hooks in ~/.claude/settings.json apply to every project; .claude/settings.json in a project applies to that project.
8 / 10
What does Cursor say about hooks set at the user level?
Hint
Not everywhere.
Cursor notes that user-level hooks do not run in cloud agents, so must-hold rules belong in the project.
9 / 10
Which of these is the safest first hook to try?
Hint
Harmless and useful.
A notification cannot harm anything and teaches you where hooks live.
10 / 10
Why read a hook carefully before installing it?
Hint
Power and risk.
A hook is a command that runs automatically with your permissions. Read it, keep it fast and test it on a scratch project first.
Worth another look
After the quiz
Using AI · Agents · Lesson 17 of 21
Hooks: rules the harness enforces so the agent cannot forget
Instructions are advice an agent follows almost every time. Hooks are rules the harness enforces every time. What hooks are, the five moments they run, how exit code 2 blocks an action, the hooks I use, and a safe first one to copy.