Koda Dojo
· Claude Code

Module 11: Hooks Recipe Book

Eight working hook recipes and one audit you can paste into settings.json today, from activity logging to commit-blocking security gates, so your rules are enforced mechanically instead of remembered.

Lessons

  1. Firing order. Lay seven hook events on one turn, then run the playhead and see which ones fire where you put them.
  2. Exit codes. Four hooks. Set the exit line, or where the hook sits, and run the turn as often as you like.
  3. Config review. Edit the values in Priya's settings.json, run the turn with your file, and see which gates fire.
  4. Rule router. Eight rules. Put each in CLAUDE.md or on a hook event, run the turn, and try other homes.
  5. Audit a clone. Open a teammate's fork without firing its hooks, then keep or drop each of its six hooks and start a session.
  6. Fresh check. A case you have not seen: a Stop hook blocks a malformed file. Act on it and watch it run. Your first result is kept.

What you take away

  • Hooks are deterministic where instructions are probabilistic: rules that must hold 100 percent of the time belong in settings.json, not CLAUDE.md
  • The whole system runs on one contract: exit 0 proceeds, exit 2 blocks, and on a tool or Stop hook the exit-2 stderr becomes Claude's instructions
  • Almost every useful hook is jq-extract, test, exit: learn that three-step shape and you can write any recipe here from memory
  • Layer your gates: PreToolUse prevents, PostToolUse corrects, Stop refuses to finish, SessionStart briefs the next shift
  • Hooks execute with your permissions, so audit your own like production code and strangers' repos before the first session

Field exercises

  • Recipe: Log Successful Edit and Write Events
  • Test Formatting Hooks on Supported Write Events
  • Recipe: Block Dangerous Commands Before They Run
  • Recipe: Test a Protected-Path File-Tool Hook
  • Recipe: Block Claude's Commits That Stage a Known Key Pattern
  • Test Source-Edit Feedback with Explicit Hook Results
  • Recipe: Test a Bounded Stop Reminder
  • Recipe: Inject Fresh Context Into Every Session Start
  • Audit the Hooks and Permissions You Can See

All fifteen modules of the Claude Code Dojo