This skill should be used when the user asks to "create a hook", "write hook config", "add hooks.json", "configure event hooks", "create PreToolUse hook", "add SessionStart hook", "implement hook validation", "set up event-driven automation", needs guidance on hooks.json structure, hook events (PreToolUse, PostToolUse, Stop, SessionStart, SessionEnd, UserPromptSubmit), or wants to automate workflows and implement event-driven behavior in Claude Code plugins.
Inherits all available tools
Additional assets for this skill
This skill inherits all available tools. When active, it can use any tool Claude has access to.
Creates hook configurations that respond to Claude Code events automatically. Hooks enable automation like formatting on save, running tests after edits, or custom session initialization.
When to use: User wants to automate workflows, needs event-driven behavior, or requests hooks for their plugin.
References: Consult
plugins/meta/claude-docs/skills/claude-docs/reference/plugins-reference.md for hook specifications and available
events.
Hooks are defined in hooks/hooks.json with:
${CLAUDE_PLUGIN_ROOT} for plugin-relative pathsFrom official documentation:
PreToolUse - Before Claude uses any toolPostToolUse - After Claude uses any toolUserPromptSubmit - When user submits a promptNotification - When Claude Code sends notificationsStop - When Claude attempts to stopSubagentStop - When subagent attempts to stopSessionStart - At session beginningSessionEnd - At session endPreCompact - Before conversation history compactionAsk the user:
Three hook types:
Structure for hooks/hooks.json:
{
"hooks": {
"EventName": [
{
"matcher": "ToolName1|ToolName2",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/script.sh"
}
]
}
]
}
}
If using command hooks:
scripts/ directorychmod +x scripts/script.sh${CLAUDE_PLUGIN_ROOT} for pathsCheck
plugins/meta/claude-docs/skills/claude-docs/reference/plugins-reference.md for:
${CLAUDE_PLUGIN_ROOT} for portabilityUser: "Auto-format code after I edit files"
Hook configuration:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/format-code.sh"
}
]
}
]
}
}
Creates scripts/format-code.sh that runs formatter on modified files.
User: "Show a message when Claude starts"
Hook configuration:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "echo 'Welcome! Plugin loaded successfully.'"
}
]
}
]
}
}
Simple command hook, no external script needed.
User: "Run tests after I modify test files"
Hook configuration:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/run-tests.sh"
}
]
}
]
}
}
Creates scripts/run-tests.sh that detects test file changes and runs relevant tests.