I wired five Claude Code hooks on a demo repo: three of three reads of a secrets file were blocked, and two hooks stayed at zero until I fixed one matcher each.
agentshipped
/
notes-api
Agent Shipped demo repo (notes-api): the public playground used in the channel's videos.
notes-api
A tiny Express notes API. This is a public demo repo for the Agent Shipped YouTube channel techniques from real projects are shown here, on code anyone can clone.
npm install
npm start # http://localhost:3000/notes
npm test # node:test (no tests yet - that is on purpose)
Endpoints: GET /health, GET /notes, GET /notes/:id, POST /notes {title, body}, DELETE /notes/:id.
Shown in
Videos on the Agent Shipped channel that use this repo:
- One git hook blocked a fake GitHub token, so no secret hit history #Shorts · E002 · 2026-11-02
- Claude Code invented one endpoint shape. A 3-line rule fixed it #Shorts · E001 · 2026-11-03
- I let Claude Code test my Express API, then ran it myself three times · E003 · 2026-11-08 · write-up
- I don't trust an agent's restart. I trust a counter going up by one #Shorts · E010…
A hook that never matches prints no error, so the settings file cannot tell you which hooks will fire. Counting what each hook did found the two silent ones.
A guard hook with a log
A hook is a command that Claude Code runs around a tool call. You register it in .claude/settings.json under an event name, with a matcher that picks the tools it listens to. Claude Code passes the command a JSON object on standard input with the tool name and the tool input.
The first hook is a guard that listens before every Bash and Read call. The script reads stdin with jq, takes tool_input.command if it exists, otherwise tool_input.file_path, and calls that the target. If the target mentions .env, it exits with code 2 and writes one sentence to stderr. That is the whole blocking mechanism. The agent gets the sentence as the reason the call failed.
The script also appends one line to a log on every call, so you can count what it did instead of trusting it. I told the agent not to run the script, because a test run would add extra lines.
A secret to protect
There is no real secret in the repo. The terminal builds a .env with a random token at run time:
printf 'TOKEN=%s\n' "$(openssl rand -hex 18)" > .env && echo 'created .env' && cat .claude/hooks/guard.sh
The script parses with jq, picks the target, logs one line, then decides. A match writes the blocked line, speaks on stderr and exits 2. Anything else exits 0.
Three ways in
In a fresh session, so the hook is loaded, I asked for exactly three attempts at the same file, with no other way around a block:
- The Read tool on
.env. - The Bash tool running
cat .env. - The Bash tool running a
grepthat would print the token line.
One matcher, Bash|Read, has to catch three routes. Each attempt came back with the stderr sentence, and no file content appeared.
Count the blocks
grep -c '^blocked' .claude/hooks.log
The number is 3: three attempts, three blocked.

The grep count of blocked lines: 3 of 3 attempts. · watch this step
A guard that works is the easy half of the story.
Four more hooks, two planted wrong
The second prompt asked for four more scripts, registered next to the guard: a syntax check, a stop marker, an audit log and a change log. Each appends one line with its own label to the same log, which makes it countable.
I planted two mistakes and told the agent to write the matchers exactly as given. The audit hook got bash in lower case. The change hook got Write. A model that tidies a typo would hide the lesson.
The syntax hook runs after Edit or Write and calls node --check. The stop hook has no matcher, because the Stop event fires when the agent finishes its turn and there is no tool to match.
What is registered
jq .hooks .claude/settings.json
PreToolUse holds the guard on Bash|Read and the audit hook on bash. PostToolUse holds the syntax hook on Edit|Write and the change hook on Write. Stop holds one entry with no matcher. The paths are right and the JSON is valid. Nothing looks wrong, and that is the trap.
A real edit
I asked the agent to edit an existing file with the Edit tool, not rewrite it: change not found to note not found, then run node --check src/index.js. Silence means the file still parses. The screen only shows the edit, not which hooks ran.
The count
One count per label, zeros included:
for h in guard blocked syntax stop audit changed; do printf '%s %s\n' "$(grep -c "^$h" .claude/hooks.log)" "$h"; done

Look at the two zeros: audit and changed. Blocked is 3. · watch this step
blocked is still 3. guard, syntax and stop are above zero. audit and changed are 0, each for its own reason.
-
audit: matchers are case sensitive. The tool is
Bashand the matcher saysbash. No error, no warning. -
changed: the agent never used Write. Changing an existing file is an Edit call, and Write is for creating a file or replacing it whole. The syntax hook has
Editin its matcher, which is why it has a count.
The one-line fix
Two substitutions in the settings file, then a list of every matcher:
sed -i -E 's/("matcher" *: *)"bash"/\1"Bash"/; s/("matcher" *: *)"Write"/\1"Edit|Write"/' .claude/settings.json && jq -c '[.hooks[][].matcher]' .claude/settings.json

The matcher list after the fix; the Stop entry shows null. · watch this step
The pattern only touches a matcher whose whole value is that word, so the syntax hook stays as it was. The scripts are untouched: the only wrong thing was the line that tells Claude Code when to call them. The Stop entry shows null because it has no matcher by design.
Edit once more
Same kind of task in a fresh session, so the fixed settings load: change note not found to Note not found in the same file, then run node --check src/index.js. Only the two matchers differ.
The verdict
The same count loop again:

Same count loop after the fix: audit and changed are no longer zero. · watch this step
audit and changed are above zero. blocked is still 3, because nothing tried to read the secrets file this time. All five hooks have now run.
What to copy
- Give every hook script a one-line log with its own label, then print a count per hook. Trust that number, not the settings file.
- Blocking is exit code 2 plus one sentence on stderr.
- Write matchers as exact tool names:
Bash, notbash. - Match the tool the agent really uses:
Edit|Writefor a change hook. - Do not switch a hook off to make a demo pass. Fix the line that decides when it runs.
Not just JavaScript
The same hook contract works in any stack. In a Python repo, use python -m py_compile instead of node --check, and ruff or mypy instead of a JS linter. The guard reads the same stdin JSON.
Video with the full run: https://youtu.be/aR5c3T0jqvc
Techniques from my real projects, shown on a public demo repo.
Narration: AI voice. The sessions, code and errors are real. Not affiliated with Anthropic or any tool vendor.
Top comments (1)
"Trust that number, not the settings file" is the line to keep. A guard that never fires looks identical to a guard that never needed to, and the config can't tell you which one you have. The job-site version is a smoke detector with no test button: installed, inspected, and silent either way. Counting what each hook did is the test button. The case-sensitive matcher (Bash, not bash) failing with no error is something I'd want surfaced at load time. Did you find any way to make an unmatched hook warn, or is the per-hook count the only signal today?