Create hook
Skill KhaledSaeed18/dotclaude/skills/engineering/create-hook
Author a new Claude Code hook for this repository end to end by scaffolding it with pnpm new, writing the hook script and its settings.json wiring, documenting activation in HOOK.md, then regenerating the registry. Use when creating, scaffolding, or reviewing a hook in this repo.From its SKILL.md
npx -y skills add KhaledSaeed18/dotclaude --skill create-hookAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.9 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it
Create a hook: a script Claude Code runs on a lifecycle event (before a tool, after a prompt, on stop, and so on). Make it do one deterministic thing, fail safe, and ship with documentation a user can paste into settings.json. Then regenerate the derived files and validate.
Source layout is hooks/<category>/<name>/HOOK.md plus the script. Hooks are folder-layout: the whole folder installs to .claude/hooks/<name>/, so the script and any helpers ride along. The category is the folder; registry.json and the README catalog are generated by pnpm gen. Never hand-edit generated files.
Hooks differ from skills, agents, and commands in one critical way: they are configuration, not a loadable file. The shadcn installer copies the script and HOOK.md but cannot edit a user's settings.json. So HOOK.md must document the exact settings block to add, and the hook is inert until the user adds it.
Hard rules: never break these
- Fail safe and non-blocking by default. Unless the hook's job is to block, swallow its own errors and exit
0so it can never interrupt or break a tool call or session. Exit2only when blocking is the intended behavior for that event. HOOK.mdmust document activation. Include the precisesettings.jsonblock, the event, the matcher, and the command line. Without it the hook does nothing after install.- Be safe with data. Hooks see tool inputs and outputs. Redact secret-looking fields and truncate large payloads before logging or sending anything.
- Zero or pinned dependencies. Prefer the language's standard library so the script runs anywhere it lands. State the runtime requirement.
nameis globally unique and equals the folder name, kebab-case.- Never hand-write
registry.jsonor the README catalog. Runpnpm gen. - No AI/co-author mentions anywhere in the hook or its output.
Step 1: Define the hook
- The one thing it does, in a sentence.
- The event it fires on and whether it needs a matcher (for example
PreToolUsematched toBash). Event list, matcher support, and the input/exit-code contract: reference/events.md. - Blocking or observing. Does it just record/notify (exit
0), or veto an action (exit2on the right event)?
Step 2: Scaffold it
From the repo root:
pnpm new --type hook --category <category> --name <name> --description "<what it does>"
Current hook category: observability. Reuse it or add a new folder if justified. The scaffolder creates the folder and a HOOK.md stub and regenerates the registry; you then add the script.
Step 3: Write the hook script
Add the script alongside HOOK.md (for example <name>.mjs or <name>.sh). Contract, in brief (full detail in reference/events.md):
- The event payload arrives as JSON on stdin (
hook_event_name,tool_name,tool_input,cwd, and event-specific fields). - Exit
0= success. For most events stdout is logged; forUserPromptSubmit/SessionStartstdout is injected as context. - Exit
2= blocking error: stderr is fed back and the action is prevented (where the event supports it). - For finer control, exit
0and print a JSON object to stdout (continue,decision,hookSpecificOutput,systemMessage). - Reference the script path with
${CLAUDE_PROJECT_DIR}so it resolves regardless of working directory.
Step 4: Write HOOK.md
HOOK.md is the manifest and the documentation. Cover:
- Frontmatter
name+description(the description is the catalog/registry text). - What the hook does, its safety properties (non-blocking, redaction), and its runtime requirement.
- A Files table (script +
HOOK.md). - An Activate it section with the exact
settings.jsonblock to paste, calling out that the installer cannot do this step. Use${CLAUDE_PROJECT_DIR}in the command path. See the existingtool-call-loggerhook for the established shape.
Step 5: Regenerate and validate
pnpm gen
pnpm validate
Fix the source files if validation complains; never patch generated output.
Step 6: Review against the bar
- The hook does its one job and, unless it's meant to block, can never break a tool call (errors swallowed, exits
0). HOOK.mddocuments the exactsettings.jsonblock, event, and matcher.- Secret-looking data is redacted; large payloads truncated.
pnpm validatepasses and the README catalog shows the new row.
Report the hook's path, category, the event it targets, and the validation result. Leave committing to the user.
What ships with it: 2 files
5.6 KB alongside SKILL.md
reference/
- events.md4.6 KB
- registry.json1.0 KB
Gives 0 of the 12 instructions most skill authoring skills give in ~1.1k tokens
Counted across 408 of the 422 authors here whose files we hold, read 2026-09-06
- Keep SKILL.md under 500 linesin 118 of 408, across 104 files
- Write skill instructions in imperative formin 44 of 408, across 37 files
- Move detailed reference material into references filesin 41 of 408, across 34 files
- Run init_skill.py to initialize new skillsin 40 of 408, across 33 files
- Draft assertions while test runs are in progressin 32 of 408, across 25 files
- Keep description under 1024 charactersin 31 of 408, across 18 files
- Run package_skill.py once the skill is completein 29 of 408, across 23 files
- Spawn with-skill and baseline runs in the same turnin 28 of 408, across 21 files
- Test added scripts by actually running themin 27 of 408, across 21 files
- Follow the creation steps in orderin 24 of 408, across 17 files
- Generate the eval viewer before evaluating outputs yourselfin 24 of 408, across 17 files
- Write the description in third personin 24 of 408, across 18 files
Said here and by no other author read
- Scaffold the hook with pnpm new
- Write the hook script next to HOOK.md
- Make the hook do one deterministic thing
- Swallow errors and exit 0 unless blocking
- Document the exact settings.json block in HOOK.md
- Redact secret-looking fields and truncate large payloads
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.