/hook-creator
Expert guidance for creating, configuring, and using Claude Code hooks for event-driven automation.
The /hook-creator skill teaches you how to create and configure Claude Code hooks for event-driven automation.
What are Hooks?
Hooks are shell commands or LLM-evaluated prompts that execute in response to Claude Code events. They provide programmatic control over Claude's behavior without modifying core code.
Quick Start Workflow
- Create hooks config file:
- Project:
.claude/hooks.json - User:
~/.claude/hooks.json
- Project:
- Choose hook event (when it fires)
- Choose hook type (command or prompt)
- Configure matcher (which tools trigger it)
- Test with
claude --debug
Example: Log All Bash Commands
.claude/hooks.json:
JSON
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.command' >> ~/.claude/bash-log.txt"
}
]
}
]
}
}This hook:
- Fires before (
PreToolUse) everyBashtool use - Executes a
command(not an LLM prompt) - Logs the command to a file
Hook Types
| Event | When it Fires | Can Block? |
|---|---|---|
| PreToolUse | Before tool execution | Yes |
| PostToolUse | After tool execution | No |
| UserPromptSubmit | User submits a prompt | Yes |
| Stop | Claude attempts to stop | Yes |
| SubagentStop | Subagent attempts to stop | Yes |
| SessionStart | Session begins | No |
| SessionEnd | Session ends | No |
| PreCompact | Before context compaction | Yes |
| Notification | Claude needs input | No |
Hook Types
Command Hooks
Execute shell commands:
JSON
{
"type": "command",
"command": "echo 'Tool used' >> log.txt"
}Prompt Hooks
Use LLM to evaluate:
JSON
{
"type": "prompt",
"prompt": "Is this command safe to run?"
}Blocking Hooks
Blocking hooks can return "decision": "block" to prevent actions:
JSON
{
"type": "command",
"command": "if [[ \"$COMMAND\" == *\"rm -rf\"* ]]; then echo '{\"decision\": \"block\", \"reason\": \"Dangerous command\"}'; fi"
}Use Cases
- Logging - Track all tool usage
- Validation - Block dangerous commands
- Notifications - Alert on specific events
- Context injection - Add information before tools run
- Workflow automation - Trigger actions after completion