Creates, analyzes, updates, and improves Claude Code hooks including configuration, scripts, and security validation. Use when user asks how hooks work, explaining hook concepts, understanding hook types and event lifecycle, describing hook configuration, creating new hooks, analyzing existing hooks for improvements, validating hook security, debugging hook activation, updating hook configurations, or when user mentions "hook", "PreToolUse", "PostToolUse", "SessionStart", or other hook event types. Handles both command hooks and prompt-based hooks across all 9 event types.
Creates, analyzes, updates, and validates Claude Code hooks across all 9 event types. Activates when you mention hooks, specific event types (PreToolUse, SessionStart, etc.), or request hook creation, analysis, security validation, or debugging.
/plugin marketplace add thoeltig/claude-code-toolkit/plugin install claude-code-capabilities@claude-code-toolkitThis skill inherits all available tools. When active, it can use any tool Claude has access to.
configuration-guide.mddebugging-guide.mdhook-schemas-reference.mdhook-types-reference.mdofficial-response-schema.mdplugin-hooks-guide.mdprompt-hooks-guide.mdreal-world-examples/mcp-tool-targeting.jsonreal-world-examples/plugin-hook-example.jsonreal-world-examples/prompt-based-stop-hook.jsonscript-examples.mdsecurity-checklist.mdtemplates/bash-hook-template.shtemplates/hook-config-template.jsontemplates/python-hook-template.pyComprehensive management of Claude Code hooks including creation, analysis, updates, and security validation.
Activate this skill when:
Hooks are automated shell commands that execute at specific Claude Code lifecycle points, providing deterministic control over behavior.
Key Characteristics:
Hook Locations:
~/.claude/settings.json.claude/settings.json.claude/settings.local.jsonFirst, identify which hook event type is appropriate:
Tool-Based Events (require matcher):
Lifecycle Events (no matcher needed):
Agent Events:
Context Events:
Ask user:
Load hook-types-reference.md now for detailed specifications on each event type.
Define the hook's logic:
Input Processing:
Decision Logic:
Output Requirements:
Load official-response-schema.md for complete schema details and structured JSON guidance.
Security Considerations:
Load security-checklist.md now for comprehensive security validation requirements.
Build the hooks configuration structure:
For Tool-Based Hooks:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/script-name.sh",
"timeout": 60000
}
]
}
]
}
}
For Lifecycle Hooks:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
}
]
}
]
}
}
Matcher Patterns:
"Bash" or "Write""Bash|Write|Edit""mcp__memory__.*" (all memory server tools)"mcp__.*__write.*" (all write tools across MCP servers)Load configuration-guide.md for detailed JSON structure guidance and advanced patterns.
For advanced decision-making, use LLM-based hooks instead of shell commands:
When to Use Prompt Hooks:
Basic Configuration:
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "prompt",
"prompt": "Should Claude continue? Check: all tasks complete? errors resolved? follow-up work needed? Respond: {\"decision\": \"approve\"|\"block\", \"reason\": \"...\"}",
"timeout": 30
}
]
}
]
}
}
Key Differences from Command Hooks:
type: "prompt" instead of commandResponse Schema: LLM returns JSON with decision (approve/block), reason, optional continue (false to stop), stopReason, systemMessage.
Load prompt-hooks-guide.md for complete documentation on prompt-based hooks including response schema, examples, and decision patterns.
Choose script language (bash or python) and implement:
Bash Script Template:
#!/bin/bash
set -e
# Read JSON input from stdin
INPUT=$(cat)
# Parse required fields (use jq if available, or basic parsing)
TOOL_NAME=$(echo "$INPUT" | grep -o '"tool_name":"[^"]*"' | cut -d'"' -f4)
# Implement hook logic here
# Exit with appropriate code
exit 0 # Success
# exit 2 # Block operation
Python Script Template:
#!/usr/bin/env python3
import json
import sys
# Read input from stdin
input_data = json.load(sys.stdin)
tool_name = input_data.get("tool_name", "")
tool_input = input_data.get("tool_input", {})
# Implement hook logic here
# Exit appropriately
sys.exit(0) # Success
# sys.exit(2) # Block operation
Script Requirements:
chmod +x script-name.shLoad script-examples.md for complete examples from Claude cookbooks including audit logging, safety checks, and validation patterns.
Critical Security Checks:
✅ Input Validation:
../, absolute paths)✅ Command Safety:
"$VARIABLE" not $VARIABLEeval or dynamic command construction✅ Data Protection:
✅ Path Security:
../../../etc/passwd✅ Error Handling:
Load security-checklist.md now for detailed validation requirements before deploying any hook.
Testing Steps:
/hooks commandclaude --debug for detailed logsValidation:
/hooks outputDeployment:
~/.claude/settings.json and ~/.claude/hooks/.claude/settings.json and .claude/hooks/ (commit to git)Load debugging-guide.md for troubleshooting common issues.
Read the hooks configuration from settings files:
Use Read tool on settings files:
~/.claude/settings.json.claude/settings.json.claude/settings.local.jsonParse hooks structure:
List hook scripts:
**/*.sh and **/*.py in .claude/hooks/Analyze each hook script for:
Functionality:
Code Quality:
Best Practices:
Efficiency:
Apply security checklist to each hook:
Input Validation:
Command Safety:
Data Protection:
Configuration Security:
Load security-checklist.md for comprehensive assessment criteria.
Categorize findings:
Critical Issues (must fix):
Major Improvements (should fix):
Minor Enhancements (nice to have):
Provide specific recommendations:
Determine what needs updating:
Outdated Patterns:
New Features:
Bug Fixes:
Design the update strategy:
Preserve Functionality:
Update Approach:
Risk Assessment:
Execute the update:
Configuration Updates:
Script Updates:
Testing:
Ensure updates are successful:
/hooks)Plugin hooks enable distributed hook composition across installed plugins.
Locations:
plugin-root/hooks/hooks.json or custom path${CLAUDE_PLUGIN_ROOT}: Absolute path to plugin directory${CLAUDE_PROJECT_DIR}: Project root directoryKey Differences from Project/User Hooks:
${CLAUDE_PLUGIN_ROOT}{
"description": "Plugin hook description",
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/format.sh",
"timeout": 30
}
]
}
]
}
}
When multiple hooks match an event:
Load plugin-hooks-guide.md for comprehensive coverage including plugin hook composition patterns, multi-plugin scenarios, and integration examples.
When evaluating whether current logic should become a hook:
Evaluation Criteria:
Good Hook Candidates:
Poor Hook Candidates:
If appropriate, explain:
Then offer to create the hook using Workflow 1.
Load these files when detailed guidance is needed:
Core References:
Advanced Topics:
Implementation & Examples:
Environment Variables:
$CLAUDE_PROJECT_DIR: Project root path$CLAUDE_ENV_FILE: Environment persistence file (SessionStart only)$CLAUDE_CODE_REMOTE: Remote execution indicator${CLAUDE_PLUGIN_ROOT}: Plugin directoryExit Codes:
0: Success, allow operation2: Block operation (behavior varies by event)Common Matchers:
"Bash" or "Write""Bash|Write|Edit""mcp__server-name__.*""mcp__server__tool-name"Security Red Flags:
eval or dynamic commandsBefore deploying any hook:
Configuration:
$CLAUDE_PROJECT_DIR if neededScript:
chmod +x)Security:
Testing:
Pre-Write Safety Hook (Command):
Post-Tool Audit Hook (Command):
Session Setup Hook (Command):
Bash Command Safety Hook (Command):
Intelligent Stop Decision (Prompt):
Context-Aware Permission (Prompt):
See prompt-hooks-guide.md for detailed prompt-based patterns with examples.
When completing hook management tasks: