hook-template
npx machina-cli add skill claude-world/director-mode-lite/hook-template --openclawHook Template Generator
Generate a hook script and configuration based on requirements.
Usage: /hook-template [hook-type] [purpose]
Hook Types
| Type | When it Runs | Use Case |
|---|---|---|
PreToolUse | Before tool | Block, validate |
PostToolUse | After tool | Log, notify |
Stop | When stopping | Continue loops |
Notification | On alerts | External notify |
Process
-
Gather Requirements
- Hook type
- Purpose
- Matcher (for Pre/PostToolUse)
-
Generate Script at
.claude/hooks/[name].sh -
Update settings.json with hook config
-
Make Executable:
chmod +x -
Validate with
/hooks-check
Templates
PreToolUse (Blocker)
#!/bin/bash
INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool_name')
# Your logic
echo '{"decision": "allow"}'
Stop (Auto-Loop)
#!/bin/bash
CHECKPOINT=".auto-loop/checkpoint.json"
if [[ ! -f "$CHECKPOINT" ]]; then
echo '{"decision": "allow"}'
exit 0
fi
# Continue logic
Example
/hook-template PreToolUse "block edits to package-lock.json"
Creates:
- .claude/hooks/protect-lockfile.sh
- Updates .claude/settings.json
Source
git clone https://github.com/claude-world/director-mode-lite/blob/main/skills/hook-template/SKILL.mdView on GitHub Overview
Hook Template Generator creates standardized hook scripts from templates for tool workflows. It supports PreToolUse, PostToolUse, Stop, and Notification hooks, generating .claude/hooks/[name].sh, updating settings.json, and marking scripts executable. This streamlines policy enforcement, monitoring, and automated responses in runs.
How This Skill Works
Provide the hook type and purpose via /hook-template. The system selects the corresponding template, generates the script to .claude/hooks/[name].sh, updates the project settings.json with the hook config, and runs chmod +x to make it executable. You can then validate execution with /hooks-check.
When to Use It
- Enforce policy before a tool runs (PreToolUse).
- Log results or notify teams after a tool completes (PostToolUse).
- Continue loops or handle shutdowns with Stop hooks (auto-loop).
- Trigger external alerts or messages via Notification hooks.
- Create concrete blockers for critical files or policies (e.g., protecting a lockfile)
Quick Start
- Step 1: Run /hook-template with your desired hook-type and purpose, e.g. /hook-template PreToolUse "block edits to package-lock.json".
- Step 2: Review the generated script path (.claude/hooks/[name].sh) and confirm .claude/settings.json has the hook config.
- Step 3: Make the script executable (chmod +x .claude/hooks/[name].sh) and validate with /hooks-check.
Best Practices
- Define a clear hookType and purpose for every hook to avoid ambiguity.
- Use PreToolUse blockers for critical checks where possible.
- Keep templates small, idempotent, and easy to audit.
- Test hooks with /hooks-check and dry-run scenarios before relying on them.
- Version-control your generated scripts and corresponding settings.json updates.
Example Use Cases
- /hook-template PreToolUse "block edits to package-lock.json" creates .claude/hooks/protect-lockfile.sh and updates .claude/settings.json.
- After a tool finishes, use PostToolUse to log results to a central monitoring service.
- Use Stop to auto-loop a process until a checkpoint is reached.
- Trigger external alerts via Notification hooks when a tool signals a warning or failure.
- Create a blocker to prevent changes to a critical file in CI pipelines (e.g., a lockfile or config).