Hook Development

Create and validate event-driven hooks for Claude Code plugin automation.

1|Updated Mar 5, 2026
One-click install
npx skills add https://github.com/Clay-HHK/claude-skills --skill hook-development-clay-hhk
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Hook Development
Source: https://github.com/Clay-HHK/claude-skills/tree/main/hook-development
Command: npx skills add https://github.com/Clay-HHK/claude-skills --skill hook-development-clay-hhk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jq, and includes scripts (resource) and references (resource) components.

What problem does it solve? Building Claude Code plugin hooks requires understanding event types, JSON configuration formats, input/output schemas, and security practices, and mistakes can silently break workflows or introduce injection vulnerabilities. ## Core Features & Use Cases - Hook Implementation Guidance: Covers all hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification) with both prompt-based and command-based hook patterns. - Validation and Testing Scripts: Includes validate-hook-schema.sh for hooks.json structure checks, test-hook.sh for running hooks against sample input, and hook-linter.sh for catching security and best-practice issues. - Use Case: When adding a PreToolUse hook to block dangerous bash commands in a plugin, use this Skill to write the hooks.json entry, lint the validation script, test it with sample input, and verify behavior with claude --debug. ## Quick Start Create a PreToolUse prompt-based hook that validates file writes for path traversal and sensitive files in my plugin's hooks.json.

Frequently Asked Questions about Hook Development

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a PreToolUse hook in Claude Code?▼

Add a PreToolUse entry in your plugin's hooks/hooks.json with a matcher for the tool name and a hooks array containing either a prompt hook for LLM-based validation or a command hook running a bash script. Use ${CLAUDE_PLUGIN_ROOT} for portable script paths.

What is the difference between prompt hooks and command hooks?▼

Prompt hooks use LLM reasoning for context-aware decisions and work on Stop, SubagentStop, UserPromptSubmit, and PreToolUse events. Command hooks execute bash scripts for fast deterministic checks, file operations, and external tool integration.

Why are my hook changes not taking effect in Claude Code?▼

Hooks load only at session start, so editing hooks.json or hook scripts does not affect the current session. Exit Claude Code and restart with claude, then verify loaded hooks using the /hooks command or claude --debug.

How do I test a hook script before deploying it?▼

Use the test-hook.sh script with a sample JSON input file to run the hook locally with proper environment variables. It shows exit codes, execution time, and parsed JSON output so you can verify behavior before adding it to hooks.json.

What exit codes should a Claude Code hook script return?▼

Hook scripts should exit with 0 for success, where stdout appears in the transcript, or 2 for a blocking error, where stderr is fed back to Claude. Other exit codes are treated as non-blocking errors.