From skills-toolkit
Creates, validates, and refines Claude Code plugin hooks for workflow automation. Supports command hooks (shell scripts), prompt hooks (LLM decisions), event matching, decision schemas, and production safety validation.
npx claudepluginhub full-stack-biz/claude-skills-toolkit --plugin skills-toolkitThis skill is limited to using the following tools:
**Dual purpose:** Create hooks right the first time OR elevate existing hooks to best practices.
references/advanced-patterns.mdreferences/checklist.mdreferences/command-hook-input-parsing.mdreferences/component-scoped-hooks.mdreferences/decision-schemas.mdreferences/event-reference.mdreferences/exit-code-behavior.mdreferences/how-hooks-work.mdreferences/mcp-tools.mdreferences/templates.mdreferences/validation-workflow.mdGuides creation and configuration of Claude Code plugin hooks for events like PreToolUse, PostToolUse, Stop, and SessionStart using prompt-based and command types.
Mandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
Dual purpose: Create hooks right the first time OR elevate existing hooks to best practices.
Use AskUserQuestion with predefined options:
questions: [
{
question: "What would you like to do?",
header: "Action",
options: [
{
label: "Create a new hook",
description: "Build a hook from scratch with proper configuration and validation"
},
{
label: "Validate existing hooks",
description: "Check hooks against best practices and production standards"
},
{
label: "Refine/improve hooks",
description: "Enhance existing hooks for clarity, efficiency, or reliability"
}
],
multiSelect: false
}
]
Then route to the appropriate workflow section based on their selection.
What to do: Tell hook-creator whether you want to create, validate, or improve a hook.
Then hook-creator will:
hooks/hooks.json (at plugin root).claude/hooks.json (in .claude directory)What this skill does: Ensures hooks trigger reliably, execute safely, and follow production best practices. Wrong events cause missed triggers. Loose matchers waste resources. Poor error handling breaks plugins. This skill prevents all of that.
NOT for: Debugging specific hook failures in running plugins, or writing hook scripts directly.
Most common hook mistake: Placing hooks in .claude-plugin/hooks.json (WRONG)
✅ CORRECT locations:
.claude-plugin/plugin.json): Create hooks/hooks.json at plugin root.claude-plugin/): Create .claude/hooks.json in .claude directory❌ WRONG location: .claude-plugin/hooks.json (only plugin.json belongs in .claude-plugin/)
If your hooks aren't firing, check the file location first.
Hook flow: Event fires → Matcher evaluated → If matched: action executes → Decision returned → Claude Code acts
Hook types:
Execution modes:
Matchers (case-sensitive regex):
^(Write|Edit)$ matches exactly Write or Edit\.js$ matches .js files.* (matches everything, performance killer)mcp__<server>__<tool> (e.g., mcp__memory__create_entities)Error handling (CRITICAL - this makes or breaks hooks):
exit 0 = success (no error output)exit 2 = blocking error (stderr shown DIRECTLY TO CLAUDE - he can fix it)exit 1 = non-blocking error (stderr only in verbose mode, Claude never sees it)exit 2. Otherwise use 0 or 1.onError behavior (warn/fail/continue)HOW COMMAND HOOKS RECEIVE DATA (CRITICAL - most common mistake):
"env": {"FILE_PATH": "${arguments.file_path}"}INPUT=$(cat) then parse: jq '.tool_input.file_path'references/command-hook-input-parsing.md for correct patterns and examplesCritical constraints:
shellcheck script.sh)For detailed execution model, event timing, and decision schemas: See references/how-hooks-work.md, references/event-reference.md, and references/decision-schemas.md.
Step 1: Ask what you want to do (create / validate / improve)
Step 2: Scope detection (automatic)
.claude-plugin/plugin.json — If exists, you're in a plugin project; if not, regular projecthooks/hooks.json at plugin root (or inline in plugin.json).claude/hooks.json in project's .claude directory~/.claude/plugins/cache/ or ~/.claude/, refuse—only work with project-scoped hooksStep 3: Route to appropriate workflow below
references/templates.md — pick appropriate template (command vs prompt)references/checklist.md (syntax, event correctness, matcher precision)Step 3b: Correct JSON Structure (CRITICAL)
All hooks must use this structure:
{
"hooks": {
"EventName": [
{
"matcher": {...}, // or omit for SessionStart/SessionEnd/UserPromptSubmit
"hooks": [ // ← REQUIRED: This nesting is mandatory
{
"type": "command",
"command": "...",
"timeout": 5000,
"onError": "warn"
}
]
}
]
}
}
⚠️ CRITICAL MISTAKE TO AVOID: ❌ WRONG (missing nested hooks array):
{
"hooks": {
"SessionStart": [
{
"type": "command", // ← ERROR: No "hooks" wrapper
"command": "..."
}
]
}
}
✅ CORRECT (with hooks wrapper):
{
"hooks": {
"SessionStart": [
{
"hooks": [ // ← REQUIRED wrapper
{
"type": "command",
"command": "..."
}
]
}
]
}
}
hooks/hooks.json at plugin root.claude/hooks.json in .claude directory~/.claude/plugins/cache/ or ~/.claude/)references/validation-workflow.md — follow 7-phase validation (event → matcher → type → error handling → performance → integration → testing)references/checklist.md to verify completeness at each phasereferences/checklist.md for best practices; references/validation-workflow.md for systematic review)Measure success by whether the hook will execute reliably and safely:
✅ Correct event - Hook triggers on the right event; understands event timing ✅ Precise matcher - Matcher correctly identifies when hook should execute (not too broad, not too narrow) ✅ Safe action - Hook action is safe, fast, and doesn't block critical paths ✅ Error handling - Hook fails gracefully; includes validation and error messages ✅ Configuration - Valid JSON/YAML syntax; correct hook.json structure ✅ Testing - Validated with real plugin scenarios; tested both success and failure cases ✅ Documentation - Clear comments explaining matcher logic and failure modes
Event Correctness — Right event = right trigger time (Pre vs Post). Wrong event = missed or wrong-time triggers.
Matcher Precision — Specific enough to avoid false triggers, broad enough to catch intended cases. Overly broad = performance impact; overly narrow = missed triggers.
Safe Execution — Commands must be fast (<1s) and non-blocking. Failed hooks must not crash plugins.
Error Handling — All hooks need timeouts, onError behavior, validation. Production hooks need monitoring/logging.
Step 1: Understand hook architecture
→ Hook flow: event fires → matcher evaluated → action executes → decision returned
→ Hook types: command (shell scripts) vs. prompt (LLM decisions)
→ Execution modes: synchronous (blocking) vs. asynchronous (background)
→ references/how-hooks-work.md for detailed execution model and timing
Step 2: Choose the right template
→ Copy-paste starting points for command hooks and prompt hooks
→ references/templates.md
Step 3: Select event & matcher
→ Event decision tree: PreToolUse, PostToolUse, UserPromptSubmit, PermissionRequest, Stop, SessionStart/End
→ Matcher patterns: precise regex for specific targeting (avoid .* performance killer)
→ references/event-reference.md for all available events
Step 4: Configure command vs. prompt
→ Command: deterministic logic (linting, validation) with proper exit codes
→ Prompt: intelligent decision-making with decision schemas
→ references/decision-schemas.md for schema format and validation
Step 5: Handle errors & edge cases
→ Critical: exit codes (0=success, 2=blocking error), onError behavior (warn/fail/continue)
→ Async vs. sync decision (blocking validators → sync; logging → async)
→ references/command-hook-input-parsing.md for stdin parsing (common mistake: missing input)
Step 6: Validate before deployment
→ 7-phase validation: event → matcher → type → error handling → performance → integration → testing
→ references/validation-workflow.md for systematic validation
→ references/checklist.md for production readiness checklist
→ Run 7-phase validation workflow systematically
→ references/validation-workflow.md for all phases
→ references/checklist.md for quality assessment
→ Identify issues using validation workflow, make targeted improvements, re-validate
→ references/checklist.md for identifying gaps
→ Topic-specific references as needed
→ Conditional execution, fallbacks, rate limiting, monitoring, testing patterns
→ references/advanced-patterns.md for production patterns
⚠️ CRITICAL: Hook JSON Structure
The #1 mistake that breaks hooks: Forgetting the nested "hooks": [...] array.
This causes: "hooks: Expected array, but received undefined" settings error.
✅ CORRECT structure (REQUIRED for all hooks):
{
"hooks": {
"EventName": [{
"matcher": "regex-pattern", // Optional for some events
"hooks": [{ // ← DO NOT FORGET THIS WRAPPER
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/script.sh",
"timeout": 5000,
"onError": "warn"
}]
}]
}
}
❌ WRONG (breaks settings):
{
"hooks": {
"EventName": [{
"type": "command", // ← ERROR: Missing "hooks" array wrapper
"command": "..."
}]
}
}
Every hook action (command, prompt, agent) MUST be inside a "hooks": [...] array. This is non-negotiable.
Event selection decision tree:
Command vs Prompt decision:
Async vs Synchronous execution:
Use async: false (default) when:
Use async: true when:
Naming convention: action-on-event (e.g., format-on-write, validate-on-prompt-submit, backup-on-compact)
For detailed reference: Templates (references/templates.md), validation workflow (references/validation-workflow.md), best practices (references/checklist.md)
Production hooks checklist (summary):
For detailed production patterns: See references/advanced-patterns.md (conditional execution, fallbacks, rate limiting, monitoring, testing).