Loading lesson…
Hooks let you run scripts before or after Claude Code does anything. They're how you turn 'guidance' into 'enforcement' — or how you debug what the agent is doing.
A hook is a small script Claude Code runs at a defined point in its lifecycle — before a tool call, after a tool call, when a session starts, when it stops. The hook can read what the agent is about to do, transform it, log it, or block it. Hooks are how you turn project rules from optional suggestions into enforced behavior.
| Event | Fires when | Use it for |
|---|---|---|
| PreToolUse | Before any tool call | Block, transform, or log |
| PostToolUse | After any tool call | Validate result, audit |
| UserPromptSubmit | When you submit a message | Inject context, log queries |
| SessionStart | On `claude` start | Pull in project state |
| Stop | Session end | Cleanup, summary, audit log |
{
"hooks": {
"PreToolUse": [
{
"matcher": { "tool": "Bash" },
"command": "./scripts/block-destructive.sh"
}
],
"PostToolUse": [
{
"matcher": { "tool": "Edit" },
"command": "pnpm prettier --write $CLAUDE_TOUCHED_FILE"
}
]
}
}A minimal hooks block. The matcher decides which tool calls fire the hook; the command runs the script.CLAUDE.md says 'don't push to main directly.' A hook BLOCKS pushes to main, period. Anywhere the cost of a mistake is high enough that 'usually respects' isn't good enough, a hook is the right answer. The model is no longer the only line of defense.
The big idea: prompts persuade, hooks enforce. Build hooks for the rules you actually need to hold.
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-claude-code-hooks-creators
What is the core idea behind "Hooks: Automating Reactions To Tool Calls"?
Which term best describes a foundational idea in "Hooks: Automating Reactions To Tool Calls"?
A learner studying Hooks: Automating Reactions To Tool Calls would need to understand which concept?
Which of these is directly relevant to Hooks: Automating Reactions To Tool Calls?
Which of the following is a key point about Hooks: Automating Reactions To Tool Calls?
What is the key insight about "Configured in settings.json" in the context of Hooks: Automating Reactions To Tool Calls?
What is the key insight about "Hooks can hang the agent" in the context of Hooks: Automating Reactions To Tool Calls?
What is the key insight about "From the community" in the context of Hooks: Automating Reactions To Tool Calls?
Which statement accurately describes an aspect of Hooks: Automating Reactions To Tool Calls?
What does working with Hooks: Automating Reactions To Tool Calls typically involve?
Which of the following is true about Hooks: Automating Reactions To Tool Calls?
Which best describes the scope of "Hooks: Automating Reactions To Tool Calls"?
Which section heading best belongs in a lesson about Hooks: Automating Reactions To Tool Calls?
Which section heading best belongs in a lesson about Hooks: Automating Reactions To Tool Calls?
Which section heading best belongs in a lesson about Hooks: Automating Reactions To Tool Calls?