Hook lifecycle management — writing, registering, testing, and maintaining Claude Code hooks. Activates on '/hookmaster', 'new hook', 'update a hook', 'hook audit', 'check the hooks'.
Activate when:
/hookmasterMid-session hook edits require hookmaster: If a hook file (.claude/hooks/*.sh) is being edited mid-session outside of a hookmaster invocation, stop and flag to the user that hookmaster verification is required — even if the edit appears minor. Minor hook changes can silently break event routing.
Before any hook work, load current state:
.claude/settings.json — the registration source of truth. Every active hook is registered here..claude/hooks/HOOKS_LOG.md — the changelog. What exists, when it was added/modified, why..claude/hooks/*.sh — the actual scripts on disk.Integrity check: Every .sh file in the hooks directory should have a corresponding entry in settings.json AND HOOKS_LOG.md. Flag any orphans (script exists but not registered) or ghosts (registered but script missing).
Pre-edit git status check (Write mode only): Before making any edits, run git status --short to see the current repo state. Plan to stage only files within the current task scope.
Then determine mode:
Before writing any code, answer these questions:
|.settings.json matchers. If the same tool already has a hook, either extend that hook or explain why a separate one is needed.For UserPromptSubmit / Stop / SubagentStop, run a capability probe first (minimal no-op hook + live-fire) before full implementation.
UserPromptSubmit hooks only — Q6: Are any trigger phrases or matchers ambiguous in other contexts? Map each phrase against the user's known multi-inbox environment. If a phrase could fire in a non-intent context:
\bphrase\b) and test against known false-positive triggersPresent the design to the user before writing code.
Every hook script follows this structure. Deviations from this template must be justified.
See resources/hook-patterns.md for the full template with all variants (advisory, blocking, confirmation-required, logging).
When writing spawn prompts for hook implementation, include this instruction verbatim:
"Read
.claude/skills/hookmaster/resources/hook-patterns.mdbefore writing any hook code. The canonical templates are there — the blocking pattern in particular usesexec 3>&2 2>/dev/null+>&3writes, which differs from naive implementations. Failure to read this file will result in broken blocking hooks."
Non-negotiable conventions:
exec 2>/dev/null + trap 'exit 0' ERR on all PreToolUse/PostToolUse hooks. A broken hook must never block work.input=$(cat 2>/dev/null) with empty guard. jq first, sed fallback for resilience.tr '\\' '/' on every path extracted from input. Windows sends backslashes./, never \.exit 0 = allow, exit 2 = block. No other exit codes.hookSpecificOutput object via jq -n construction. Never hand-build JSON strings. Blocking hooks (exit 2) use a completely different pattern: exec 3>&2 2>/dev/null at script top, then echo "BLOCKED: ..." >&3 before exit 2.flock -w 2 for concurrency safety."timeout": 10 (seconds). Hooks must be fast.After writing the script:
settings.json — find the correct event type array, add the matcher + command entry.C:/YourWorkspace/.claude/hooks/my-hook.sh.|. Regex matchers are allowed only when needed for a tool family, and must be anchored + documented in HOOKS_LOG.Every new or modified hook must pass all three layers before it's considered live.
bash -n .claude/hooks/my-hook.sh
Confirms syntax is valid. Does not execute.
Read settings.json and confirm:
Trigger the actual tool the hook is supposed to intercept. Observe:
additionalContext appear in the model's context?permissionDecision: "ask"?UserPromptSubmit hooks — standard test matrix: For any hook on the UserPromptSubmit event, live-fire must cover:
Trigger cases (MUST fire):
Non-trigger cases (must NOT fire):
Document pass/fail for each case in the HOOKS_LOG entry.
After verification passes, update .claude/hooks/HOOKS_LOG.md:
For new hooks: Add a new entry to the registry section with: name, event type, matcher, behavior, purpose, date added.
For modifications: Add a changelog entry under the hook's section with: date, what changed, why.
Write immediately. Do not defer to session end. Context compaction is real.
Minimal-diff discipline: Append only the relevant new entry. Do not normalize, reformat, or rewrite unrelated sections of HOOKS_LOG.md in the same edit.
When user asks for a health check:
.sh files in hooks directory vs. all entries in settings.json. Flag orphans and ghosts.exec 2>/dev/null present on all PreToolUse/PostToolUse hooks?trap 'exit 0' ERR safety net?Present findings as a table, flag issues by severity (BLOCKER / WARNING / INFO).
| Mechanism | When to Use | Examples |
|-----------|-------------|---------|
| Hook | Deterministic guard that must fire every time, regardless of which skill is active. No LLM reasoning needed. | Block destructive commands, log file touches, inject scope context |
| Skill | Deep guidance requiring LLM reasoning, context awareness, multi-step workflows. | GAS expert patterns, sheet architecture decisions, email drafting |
| Rule (.claude/rules/) | Lightweight always-on guardrails. Glob-matched to file types. | "Every .gs file needs @execution header", "Strip JSON fences in Python" |
Hook vs. Skill overlap: If a guard exists as both a hook AND a skill rule, that's intentional — hooks are the deterministic backstop, skills provide the deep guidance. Don't remove one because the other exists.
exec 2>/dev/null + trap 'exit 0' ERR on all PreToolUse/PostToolUse hooks.NOTE: Hook file edited — hookmaster 3-layer verification required before this change is considered live.
npx skills add socalfinanceinsights/hookmaster下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer