Add and configure Claude Code hooks for event-driven automation. Use when setting up hooks, creating hook scripts, or automating tool-related workflows.
Configures event-driven hooks to automate tool execution and workflow triggers.
npx claudepluginhub kkhys/claude-code-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/events.mdreferences/json-output.mdreferences/scripts.mdFirst, ask the user where to add hooks:
~/.claude/settings.json - User-scoped (personal, all projects).claude/settings.json - Project-scoped (shared via git).claude/settings.local.json - Local project (not committed)hooks/hooks.json - Plugin-bundled hooks{
"hooks": {
"EventName": [
{
"matcher": "ToolPattern",
"hooks": [
{
"type": "command",
"command": "your-command-here",
"timeout": 60
}
]
}
]
}
}
| Event | When | Common Use |
|---|---|---|
PreToolUse | Before tool execution | Validation, blocking |
PostToolUse | After tool completion | Formatting, logging |
PermissionRequest | Permission dialog shown | Auto-approve/deny |
UserPromptSubmit | User sends prompt | Context injection |
Stop | Agent finishes | Task completion check |
SubagentStop | Subagent finishes | Subagent validation |
SessionStart | Session begins | Environment setup |
SessionEnd | Session ends | Cleanup tasks |
Notification | Notification sent | Alerts |
PreCompact | Before compact | Custom summarization |
See events.md for detailed event documentation.
For PreToolUse, PostToolUse, PermissionRequest:
"Write" - matches Write tool only"Edit|Write" - matches Edit or Write"*" or "" or omit matcher"mcp__server__tool" patternCase-sensitive: Write ≠ write
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/scripts/check.sh",
"timeout": 30
}
{
"type": "prompt",
"prompt": "Evaluate if Claude should stop: $ARGUMENTS. Check if all tasks complete.",
"timeout": 30
}
Supported for: Stop, SubagentStop, UserPromptSubmit, PreToolUse, PermissionRequest
| Code | Meaning | Behavior |
|---|---|---|
| 0 | Success | Continue execution |
| 2 | Block | Block tool/prompt, show stderr to Claude |
| Other | Non-blocking error | Show stderr, continue |
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/scripts/format.sh"
}
]
}
]
}
}
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/scripts/validate-bash.sh"
}
]
}
]
}
}
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "echo \"Current time: $(date)\""
}
]
}
]
}
}
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/scripts/protect-files.sh"
}
]
}
]
}
}
#!/usr/bin/env bash
set -euo pipefail
# Read JSON input from stdin
input=$(cat)
# Parse fields with jq
tool_name=$(echo "$input" | jq -r '.tool_name // empty')
tool_input=$(echo "$input" | jq -r '.tool_input // empty')
# Validation logic here
# Exit 0: success, Exit 2: block with stderr message
exit 0
See scripts.md for script examples.
For structured control, output JSON to stdout (exit code 0):
{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "allow",
"permissionDecisionReason": "Auto-approved"
}
}
See json-output.md for complete schema.
| Variable | Description |
|---|---|
CLAUDE_PROJECT_DIR | Project root directory |
CLAUDE_PLUGIN_ROOT | Plugin directory (plugins only) |
CLAUDE_ENV_FILE | Env file path (SessionStart only) |
CLAUDE_CODE_REMOTE | "true" if remote environment |
"$VAR" not $VAR.. in paths.env, .git/, keys# Check registered hooks
/hooks
# Debug mode for execution details
claude --debug
Common issues:
\"Write not writechmod +x script.shSearch, retrieve, and install Agent Skills from the prompts.chat registry using MCP tools. Use when the user asks to find skills, browse skill catalogs, install a skill for Claude, or extend Claude's capabilities with reusable AI agent components.
Activates when the user asks about AI prompts, needs prompt templates, wants to search for prompts, or mentions prompts.chat. Use for discovering, retrieving, and improving prompts.
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). **PROACTIVE ACTIVATION**: Use this skill automatically when working in Next.js projects that have `cacheComponents: true` in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. **DETECTION**: At the start of a session in a Next.js project, check for `cacheComponents: true` in next.config. If enabled, this skill's patterns should guide all component authoring, data fetching, and caching decisions. **USE CASES**: Implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, debugging cache issues, and reviewing Cache Component implementations.