Hooks
IntermediatePro41 minupdated 2026-10-28
Hooks are automated scripts that execute in response to specific events during Claude Code sessions. They enable automation, validation, permission management, and custom workflows.
Overview
Hooks are automated actions (shell commands, HTTP webhooks, LLM prompts, MCP tool calls, or subagent evaluations) that execute automatically when specific events occur in Claude Code. They receive JSON input and communicate results via exit codes and JSON output.
Key features:
- Event-driven automation
- JSON-based input/output
- Support for
command,http,mcp_tool,prompt, andagenthook types - Pattern matching for tool-specific hooks
Configuration
Hooks are configured in settings files with a specific structure:
~/.claude/settings.json- User settings (all projects).claude/settings.json- Project settings (shareable, committed).claude/settings.local.json- Local project settings (not committed)- Managed policy - Organization-wide settings
- Plugin
hooks/hooks.json- Plugin-scoped hooks - Skill/Agent frontmatter - Component lifetime hooks
Basic Configuration Structure
{
"hooks": {
"EventName": [
{
"matcher": "ToolPattern",
"hooks": [
{
"type": "command",
"command": "your-command-here",
"timeout": 60
}
]
}
]
}
}Key fields:
| Field | Description | Example |
|---|---|---|
matcher | Pattern to match tool names (case-sensitive) | "Write", "Edit|Write", "*" |
hooks | Array of hook definitions | [{ "type": "command", ... }] |
type | Hook type: "command" (bash), "prompt" (LLM), "http" (webhook), "mcp_tool" (MCP tool invocation, v2.1.118+), or "agent" (subagent) | "command" |
command | Shell command to execute | "$CLAUDE_PROJECT_DIR/.claude/hooks/format.sh" |
timeout | Optional timeout in seconds. Defaults: 600 for command/http/mcp_tool, 30 for prompt, 60 for agent. | 30 |
once | If true, the hook is removed after its first successful run (failed/blocked/timed-out runs keep it). Skill frontmatter only; ignored in settings and agent frontmatter | true |
async | If true, runs in the background without blocking | true |
asyncRewake | If true, runs in the background and wakes Claude on exit code 2. Implies async. | true |
This guide continues on the Pro plan
You have seen the introduction and the first example. With Pro you unlock this guide and every other one - updated every day, with ready-to-copy examples.
In this guide (Pro): Hook Types · Hook Events · Component-Scoped Hooks · PermissionRequest Event · Hook Input and Output · Environment Variables · Prompt-Based Hooks · Examples · Plugin Hooks · MCP Tool Hooks · Security Considerations · Debugging · Complete Configuration Example · Hook Execution Details · Troubleshooting · Installation · Related Concepts · Additional Resources
€7.99/month · No commitment · Cancel anytime
Open-source community guide (MIT) · curated and maintained by Doutor AI.
Need a tailor-made solution?
Not sure where to start with AI in your business? Get a free assessment and a tailored plan - no commitment.
Save hours every week with AI, no hassle
Doutor AI gives you 1,859 ready-to-copy AI prompts, by industry and in plain English - plus a complete technical library for those who want to go further.