hooks-builder
Skill0 starsChanged 4 months agoMITView on GitHub
Designs, builds, optimizes, or audits Claude Code HOOKS — event-driven shell commands in settings.json that fire on SessionStart/PreToolUse/PostToolUse/Stop etc. to allow/block tools, inject context, or trigger side effects. Type `/hooks-builder` when a behavior must happen mechanically on every matched event ("run X every time I edit/commit/start a session", "block tool X when…", "audit my hooks"). Hooks run arbitrary shell as Gera, so every build ends in a mandatory supervised first-fire test.
- Reads credentials
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- GerardoRdz96/aios-starter-kitedited, first seen Jul 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- GerardoRdz96/aios-starter-kit★ 371% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository50 other files it gives its agents.
- aegisSkill
- agent-builderSkill
- agents-team-builderSkill
- ai-applySkill
- auditSkill
- bottleneckSkill
- buildSkill
- capability-radarSkill
- clay-leadsSkill
- cowatchSkill
- deepforkSkill
- design-blueprintSkill
- evalSkill
- fable-modeSkill
- financesSkill
- forgeSkill
- framework-builderSkill
- grill-meSkill
- level-upSkill
- loops-builderSkill
- meeting-hudSkill
- multi-brainSkill
- nate-watchSkill
- onboardSkill
- plugin-builderSkill
- ponytailSkill
- presentSkill
- prompt-evalSkill
- radar-harvestSkill
- rag-forgeSkill
- rlsgateSkill
- rnd-loopSkill
- rndSkill
- roastSkill
- routines-builderSkill
- servy-routineSkill
- session-handoffSkill
- skill-builderSkill
- skill-harvestSkill
- sparkSkill
- storm-researchSkill
- studySkill
- talkSkill
- taste-skillSkill
- verify-loopSkill
- verify-specificsSkill
- wheel-of-lifeSkill
- workanaSkill
- workaround-builderSkill
- workflow-builderSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Audit: all configured hooks (user + project + plugin layers).
- Distinctive: line 18
Use this whenever Gera says "every time / whenever / always when <event>, do X" about a LOCAL, in-session behavior.
- Distinctive: line 40
Must it fire every time, deterministically?: If "usually / when relevant" → it's an instruction for CLAUDE.md or a skill, not a hook.
- Very specific: line 110
Test: echo '{}' | bash .claude/hooks/session-end-ping.sh.
- Distinctive: line 116
Read before optimizing; test before arming.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/hooks-builder
Builds Claude Code hooks: event-driven commands the harness executes deterministically on matched events. A hook is the right tool when the behavior must happen EVERY time, mechanically — memory and prompts cannot fulfill "always do X on Y"; only the hook layer can. Sibling of /skill-builder, /agent-builder, /routines-builder, /agents-team-builder, /plugin-builder, /servy-routine — that family picks the mechanism; this one is the event-driven-local specialist (the hooks lane /routines-builder hands off to). Schema, events, and the stdin/exit-code protocol live in reference.md.
What this skill does
- Build a new hook: decision gate → discovery → script + config → supervised first fire → register.
- Optimize an existing hook (read it first).
- Audit all configured hooks (user + project + plugin layers).
Use this whenever Gera says "every time / whenever / always when <event>, do X" about a LOCAL, in-session behavior.
Quick start — hook vs the other cadence mechanisms
| Mechanism | Fires when | Machine on? | Session open? | Builder |
| Hook | a Claude Code EVENT matches | yes | a CC process must exist (no human needed) | this skill |
| Cloud routine | cron schedule, Anthropic cloud | no | no | /servy-routine |
launchd/cron + claude -p | local schedule | yes | no | /routines-builder |
/loop | recurring interval inside one session | yes | yes | /loop itself |
| Skill-scoped hook | only while a specific skill runs | yes | yes | /skill-builder (frontmatter) |
| Plugin hook | shipped inside a plugin, fires for its users | — | — | /plugin-builder |
Scope (v1): Servy-authored hooks are type:"command" only. Claude Code also supports http/mcp_tool/prompt/agent handlers and fields like if/async — prompt/agent handlers spend tokens on every match, so they need an explicit cost case; see reference.md before reaching for them.
Division of labor with update-config: that built-in skill owns the mechanical settings.json edit. This skill owns everything around it — the decision, the design, the script, the test discipline — and invokes update-config for the write (or edits directly when update-config is unavailable, reporting exactly what changed).
Mode 1: Build
Step 0 — The Decision Gate (FIRST)
- Is it event-driven inside Claude Code sessions? (a tool call, session start/end, a stop) If it's clock-driven →
/routines-builder//servy-routine. STOP and refer. - Must it fire every time, deterministically? If "usually / when relevant" → it's an instruction for CLAUDE.md or a skill, not a hook. STOP and refer.
- Only while one skill runs? → skill-scoped hooks in that skill's frontmatter via
/skill-builder. STOP and refer. - Shipping to others? → plugin
hooks/hooks.jsonvia/plugin-builder. STOP and refer. - Deterministic, no LLM judgment needed in the action? Hooks should run scripts, not think. If the action needs judgment, the hook may still fire
claude -p— but flag the cost and consider whether a skill ritual fits better.
State the verdict in one sentence before interviewing.
Step 1 — Discovery Interview
AskUserQuestion, one round at a time; skip what's known. Why each matters: wrong event = never fires; wrong matcher = fires constantly; wrong failure mode = blocked sessions.
- Round A — Trigger. Which event? Core set:
SessionStart,UserPromptSubmit,PreToolUse,PostToolUse,Stop(end of each RESPONSE, not session),SubagentStop,SessionEnd,PreCompact— extended events in reference.md. Which matcher (for tool events: tool-name regex, e.g.Write|Edit; several non-tool events also accept matchers — see reference.md per-event table)? How often will that realistically fire per session (every-Read hooks run hundreds of times — keep them <100ms)? - Round B — Action. What does it DO: allow/block (exit 2 = block), inject context (stdout on certain events), or side effect (notify, log, format, validate)? Inline command or script file? (Anything >1 line → a script in
.claude/hooks/(project) or~/.claude/hooks/(user).) - Round C — Scope + failure. Scope: user (
~/.claude/settings.json, all projects), project-shared (.claude/settings.json, committed), project-personal (.claude/settings.local.json)? Timeout (default 5-10s — ALWAYS set one)? On script failure: fail-open (log, continue) or fail-closed (block)? Default fail-open unless it's a guard. - Confirmation — echo a fenced
## Hook Summary(event, matcher, action, scope, timeout, failure mode, script path) and get explicit yes.
Step 2 — Build
- Write the script (if any) to the scoped hooks dir;
chmod +x. Script contract: read the event JSON from stdin, do ONE thing, exit 0 (allow / success) or 2 (block, PreToolUse) — full protocol in reference.md. Never put secrets in the command line; source them inside the script from.env. - Config edit: invoke the
update-configskill with the exact hooks JSON block (shape in reference.md). If editing directly, show the diff of the settings file.
Step 3 — Supervised first-fire test (MANDATORY — don't skip, don't leave unverified)
Hooks run as Gera with his permissions on every matched event. Before calling it done:
- Dry-fire the script standalone:
echo '<realistic event JSON>' | <script>— verify output + exit code for both the match case and a benign case. - Live-fire once: trigger the real event in-session (e.g. a harmless Write for a
PreToolUse:Writehook) and confirm: fired? right decision? no latency pain? - Failure drill: make the script fail (or time out) once; confirm the session degrades the way Round C chose.
- Report exactly what you ran and what happened. A hook that can't pass all three stays UNARMED (config commented out / removed).
Step 4 — Document & register
CLAUDE.md one-liner if it changes how Servy behaves day-to-day (2-line cap); append references/log.md (## [<date>] create | Hook — <name>); note in pending.md anything deferred. New hook-layer facts → update reference.md.
Mode 2: Optimize
Read the current config + script FIRST — never optimize what you haven't read. Symptoms → fixes: fires too often → tighten matcher regex; session feels slow → measure script runtime, move work async or cache; silent failures → add logging to a file (never stdout on non-inject events); blocks unexpectedly → check exit codes (a crashing script can read as exit 2); hook stopped working after an update → re-verify event names + settings layer precedence.
Mode 3: Audit
For every hook across ~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json, and active plugins:
- Event + matcher still match real tool names (no stale regexes)
- Timeout set; script exists, executable, <100ms for high-frequency events
- Failure mode intentional (fail-open vs fail-closed) and documented
- No secrets in command lines; scripts source
.envinternally - Still wanted — kill zombie hooks (each one taxes every matched event forever)
- Layer is right (user vs project vs local) for who should get it
- Registered: log entry exists; CLAUDE.md mentions it if behavior-changing
Complete example
Goal: Telegram ping whenever a session in Servy ends (SessionEnd — NOT Stop, which fires at the end of every response).
.claude/hooks/session-end-ping.sh:
#!/usr/bin/env bash
# SessionEnd ping; fail-open. Reads event JSON on stdin (unused).
set -a; source ~/Desktop/Servy/.env 2>/dev/null; set +a
curl -sm 4 "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \
-d chat_id="${TG_CHAT_ID}" -d text="🔔 Servy session ended" >/dev/null || true
exit 0.claude/settings.local.json fragment (via update-config):
{ "hooks": { "SessionEnd": [ { "hooks": [ { "type": "command",
"command": "bash ~/Desktop/Servy/.claude/hooks/session-end-ping.sh", "timeout": 6 } ] } ] } }Test: echo '{}' | bash .claude/hooks/session-end-ping.sh; echo $? → message arrives, exit 0. Then end one disposable session live. Failure drill: run with FAIL_TEST=1 injected (add [ "${FAIL_TEST:-}" = 1 ] && exit 1 at the top during testing) in a disposable session → session unaffected (fail-open) → remove the test line.
Important notes
- The decision gate is not optional — most "automate X" asks are routines or skills, not hooks.
- Hooks are the only layer that can guarantee "always" — but each one runs forever on every match. Bias toward FEW, fast, well-tested hooks.
- Read before optimizing; test before arming; Codex reviews any non-trivial hook script (No-Self-Review Law).
- Full schema/protocol: reference.md. Official docs: https://code.claude.com/docs/en/hooks
Related
- reference.md — events, settings schema, stdin/exit protocol, live inventory.
/routines-builder— clock-driven cadence (hands event-driven work here).update-config— the mechanical settings.json writer this skill delegates to./skill-builder(skill-scoped hooks) ·/plugin-builder(plugin hooks).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

