Intermediate · Optional lab · about 25 minutes · Enforcer Badge
Hooks that fail closed
The job
A session rewrote package-lock.json last week, and Sam wants the till's key in .env safe even if someone renames a script. Claude also stops with a test failing. A note in CLAUDE.md won't do: Sam wants it impossible.
After this Lesson you can
- decide which rules need a hook rather than an instruction
- make a guard that blocks even when its own script is missing, and test it from inside a session
- stop Claude from ending a turn while the tests fail
What you practise
chmod +x .claude/hooks/protect-files.sh: Claude Code runs a hook script directly, so it must be executable.mv .claude/hooks/protect-files.sh .claude/hooks/protect-files.off: rename the guard, so the hook can't startecho '{"stop_hook_active":false}' | CLAUDE_PROJECT_DIR=$PWD .claude/hooks/test-gate.sh; echo "exit $?": run the gate with the JSON a Stop event sends/hooks: lists what is registered
Intermediate and Advanced open with a free Account.