Wire the Hook Lifecycle: an Auto-Format Hook and a Stop Gate That Runs the Tests
Take a small notes app with a green test suite and wire two production-pattern hooks around it: a PostToolUse hook that auto-formats every file Claude writes or edits, and a Stop hook that runs the tests and refuses to let the session end while they are red. A local self-check feeds your real hook scripts the same JSON events Claude Code would send and writes your proof-of-work evidence only when both hooks behave on every event.
1.3 hrs
Est. time
4
Outcomes
5
Rubric criteria
65%
Pass score
What you'll learn
Skills you'll have real reps in after shipping this.
The scenario
On a real team, 'run the formatter after you edit' and 'make sure the tests pass before you call it done' are instructions an agent can forget. Hooks make both mechanical: they are commands Claude Code executes at fixed lifecycle points, each fed a JSON event on stdin, so the formatter runs after every matching write and the test suite gates every attempt to end the turn, whether or not the model remembers.
This task wires that setup on sparkjot, a tiny snippet-notes app with a green unittest suite. You write a PostToolUse hook that formats whatever file Claude just touched, a Stop hook that blocks the end of the turn while the suite is red, and the settings.json registration that binds each script to the right event with the right matcher. A local self-check runs your actual hooks against simulated Write, Read, Bash, and Stop events in a temporary copy of the kit, and only writes the evidence file when the formatter fires, unmatched tools are left alone, and the stop gate blocks on red, allows on green, and respects the loop guard.
Your role
You are the engineer who owns the Claude Code configuration for a small repo. Your deliverable is a working pair of lifecycle hooks (a PostToolUse formatter and a Stop test gate), their registration in .claude/settings.json, machine-generated evidence that both fire correctly, and a short set of notes on the event contracts, packaged as a single submission.
Start the task to unlock the full brief
You'll get the step-by-step requirements, setup commands, the 5-criterion grading rubric, tips, and the ability to submit your solution for instant AI grading.
Free to start · submit when you're ready
Wire real Claude Code hooks across the lifecycle, hands-on
Hooks are how you make Claude Code do the right thing every time: commands that run at fixed lifecycle points with a JSON event payload on stdin. In this task you wire the two patterns teams actually ship: a PostToolUse hook that auto-formats every file Claude writes or edits, and a Stop gate that runs the unittest suite and blocks the end of the turn while tests are red. A local self-check feeds your real hook scripts the same events Claude Code would send, so you learn each event's stdin contract, matcher scoping, per-event exit-code semantics, and the JSON decision output by making them work. You leave with machine-generated evidence that your hooks fire correctly and a loop-safe stop gate pattern you can drop into any repo.