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.
8 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-claude-code-hooks-creators
What is the main idea of "Hooks: Automating Reactions To Tool Calls"?
Which concept is most central to "Hooks: Automating Reactions To Tool Calls"?
Which use of AI fits this topic best?
What should a careful learner remember about "Configured in settings.json"?
You want to use AI after this lesson. What is the safest next step?
How should AI output about hook be treated?
Name one way to verify an AI answer about hook.
Which action would help you apply "Hooks: Automating Reactions To Tool Calls" responsibly?