Hook Development for Claude Code
A reference skill for designing, configuring, and debugging Claude Code hooks — prompt-based and command-based — across all nine hook events.
Dev & CodingIntermediate★ 514⑂ 46AI score 8/10Last updated: Jul 23, 2026
What it does
- Documents all nine hook events (PreToolUse, PostToolUse, Stop, SubagentStop, UserPromptSubmit, SessionStart, SessionEnd, PreCompact, Notification) with a quick-reference table of when to use each.
- Explains when to choose prompt hooks (LLM reasoning, flexible) versus command hooks (deterministic, fast bash checks).
- Clarifies the two config shapes: plugin
hooks/hooks.json(wrapped in{"hooks": {...}}) versus user.claude/settings.json(events at top level). - Gives the hook stdin/stdout JSON contracts, exit codes (0 / 2),
permissionDecision,decision: approve|block, andsystemMessage. - Covers matcher regex patterns (
Read|Write|Edit,mcp__.*__delete.*),${CLAUDE_PLUGIN_ROOT}for portable paths, timeout defaults, parallel-execution implications, and security rules (path traversal, sensitive files, quoting bash variables). - Adds patterns for conditionally enabled hooks via flag files or config, plus a debugging workflow with
claude --debugand/hooks.
Who it's for
- Developers building Claude Code plugins or team-wide guardrails.
- Tech leads who want to block dangerous Bash commands or edits to secrets.
- Anyone enforcing completion criteria (tests, builds) with a Stop hook.
- Anyone auto-loading project context or env vars at session start.
Example uses
- "Add a PreToolUse hook that denies path traversal and
.envwrites" → generateshooks.jsonwith aWrite|Editmatcher plus a validation script. - "Don't let the agent stop until tests and build pass" → a prompt-based Stop hook returning
decision: blockwith a reason. - "Detect project type on session start and persist it" → a SessionStart command hook appending exports to
$CLAUDE_ENV_FILE.
· · · Install guide · · ·
Try it now, no install
Paste this into Claude to use the skill without installing anything.
Read the instructions in this file and follow them to help me: https://raw.githubusercontent.com/tzachbon/smart-ralph/HEAD/.agents/skills/Hook Development/SKILL.md What I want: (describe your task here)
If Claude can't open the link, open it yourself and paste the contents instead.
↓ If it works for you, download the ZIP below and install it. Then it runs on its own — no pasting each time.
Install in the Claude app (no terminal)
- Download the ZIP with the button below.
- In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
- Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Install in Claude Code
Let Claude do it — paste this into Claude Code
Install the skill I found on Claude Skill Mart. Copy the .agents/skills/Hook Development folder from the GitHub repo tzachbon/smart-ralph into my ~/.claude/skills/hook-development/. When it's done, tell me in one line what this skill can do.
Install with a command instead
git clone https://github.com/tzachbon/smart-ralph.git && mkdir -p ~/.claude/skills && cp -r "smart-ralph/.agents/skills/Hook Development" ~/.claude/skills/hook-development⚠ This is a third-party skill. Check the source repository before installing.
- Open a terminal in the folder where you keep repos.
- Clone the repository:
git clone https://github.com/tzachbon/smart-ralph.git - Create the skills directory:
mkdir -p ~/.claude/skills - Copy the whole skill folder (the bundled references/, examples/, and scripts/ are needed):
cp -r "smart-ralph/.agents/skills/Hook Development" ~/.claude/skills/hook-development - Verify
~/.claude/skills/hook-development/SKILL.mdand its subfolders exist. - Make sure
jqis installed (jq --version; macOS:brew install jq, Ubuntu:sudo apt install jq). - Restart Claude Code and try a prompt like "create a PreToolUse hook to block dangerous commands".
- Remember: hook config loads at session start, so exit and relaunch Claude Code after any change, and use
claude --debugto inspect load and execution logs.
View source on GitHub ↗License: MIT