AC claude-code-hooks
How to write, test, register, and debug Claude Code hooks — PreToolUse / PostToolUse / SessionStart / Stop Bash guards that enforce a rule the model would otherwise talk itself past. Use whenever the user wants to create a hook, block/intercept a tool call, turn a repeatedly-violated rule into a hard gate, add a guard rail, debug a hook that misfires or "poisons the session", register a hook across profiles, or mentions hooks / PreToolUse / Stop hook / 拦截 / 守卫 / 钩子 / 拦下. Bakes in the hard-won pitfalls: UserPromptSubmit only ever sees user input, never Claude's own text — a rule about Claude's own output belongs on Stop instead; token-level shlex matching (never awk splitting); bash -n + real-JSON end-to-end testing BEFORE registering (a corrupted PreToolUse hook poisons every Bash call); SSOT + symlink so a ~/.claude reinstall can't lose it; multi-profile convergence; and human-confirmation release gates. Reach for this even for "make it stop doing X" — a durable stop is a hook, not a reminder.
How to write, test, register, and debug Claude Code hooks — PreToolUse / PostToolUse / SessionStart / Stop Bash guards that enforce a rule the model would…
As a process C 59/100 · Has gaps — weak spots: result and completion, inputs and preconditions, execution cost
How to improve
- The SKILL.md body is over 5,000 tokens: move reference detail into references/ and load it when needed.
- Your own cases (evals/evals.json, 4–6 real requests with expected answers): the full check would then run those instead of a model-drafted suite.
- A spec.yaml with trigger phrases and assertions — a behaviour contract for CI; `skilltest init` writes a template.
Guard findings · 0
✓ No critical or high findings
Files scanned: 5. Evidence is masked. Grey chips explain why severity was lowered.
Against the Agent Skills spec
- warning
body-longSKILL.md body ≈ 21791 tokens (recommended < 5000); move details to references/
Process rating: all ten parameters 59/100
- 0Result and completion. Does not say what the result is
- 0Inputs and preconditions. Does not say what the process needs to start
- 10Execution cost. Instruction body is 21791 tokens: crowds the task out of the window
- 60Tools and files. Uses tools (bash, web, git, python) that frontmatter does not declare
- 70When it triggers. States when to use, but not when not to
- 100Steps. 59 steps
- 100Failures and branches. 3 branches, has a failure section
- 100Consistency. Name and required fields are in place
- 100Running it twice. Mutating operations check current state
- 100Progress reporting. Reports progress
- medium Safety rules and hard prohibitions inside a skill: they belong in the system prompt, here they protect nothing
- low The response is described with custom markup (16 tags): a typed call is more reliable
Everything here is measured from the skill text rather than judged by a model, so the numbers are checkable. A parameter weighs more when it is a more common reason for the process to stall.
Quality signals
- +4Description does not say when NOT to use the skill (false activations)
- +3Description length 1009: 120–800 characters recommended
- +3Output format is not stated: the model decides each time
- +1No license
- +2Single-language instructions
- +5Description quotes 2 example trigger phrases
- +4Structure: 18 headings
- +3Step-by-step instructions: 59 items
- +4Has examples (11 code blocks)
- +4Reference files are cited in the instructions (2 of 2)
- +3All 2 scripts are documented
Quality base 70; lint remarks subtract, signals add up to 100. Result: 83.