hooks-authoring-reference
Comprehensive quick-reference for authoring Claude Code hooks. Use when creating new hooks for settings, plugins, or skill/agent frontmatter. Covers all 26 event types, four handler types (command/http/prompt/agent), JSON input/output formats, matcher semantics, decision control, exit codes, async hooks, environment variables, and troubleshooting patterns. Trigger when user says "create a hook", "add a hook", "hook reference", "what hooks are available", "how do hooks work", "hook schema", "hook events", or is authoring hooks.json for a plugin or settings file.
What this skill does
# Claude Code Hooks Authoring Reference
Use this reference when creating, editing, or debugging Claude Code hooks. This is a distilled quick-reference from the official documentation.
## Hook Locations
| Location | Scope | Shareable |
|----------|-------|-----------|
| `~/.claude/settings.json` | All projects | No |
| `.claude/settings.json` | Single project | Yes (commit to repo) |
| `.claude/settings.local.json` | Single project | No (gitignored) |
| Managed policy settings | Organization-wide | Yes (admin-controlled) |
| Plugin `hooks/hooks.json` | When plugin enabled | Yes (bundled) |
| Skill/agent frontmatter | While component active | Yes (in component file) |
## Schema Formats
### Settings Format (settings.json)
Event types directly under the `hooks` key:
```json
{
"hooks": {
"<EventName>": [
{
"matcher": "<regex|*|empty>",
"hooks": [
{ "type": "command", "command": "...", "timeout": 60 }
]
}
]
}
}
```
### Plugin Format (hooks/hooks.json)
Wrapper object with required `hooks` key and optional `description`:
```json
{
"description": "Optional description",
"hooks": {
"<EventName>": [
{
"matcher": "<regex|*|empty>",
"hooks": [
{ "type": "command", "command": "...", "timeout": 60 }
]
}
]
}
}
```
**Critical**: `hooks/hooks.json` is auto-discovered. Do NOT add `"hooks": "./hooks/hooks.json"` to `plugin.json` — it causes "Duplicate hooks file detected".
### Skill/Agent Frontmatter Format
```yaml
---
name: my-skill
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate.sh"
---
```
For subagents, `Stop` hooks are automatically converted to `SubagentStop`.
## All 26 Hook Events
### Session Lifecycle
| Event | When | Can Block? | Matcher Filters | Supported Types |
|-------|------|------------|-----------------|-----------------|
| `SessionStart` | Session begins/resumes | No | `startup`, `resume`, `clear`, `compact` | `command` only |
| `SessionEnd` | Session terminates | No | `clear`, `resume`, `logout`, `prompt_input_exit`, `bypass_permissions_disabled`, `other` | `command`, `http` |
| `InstructionsLoaded` | CLAUDE.md or rules loaded | No | `session_start`, `nested_traversal`, `path_glob_match`, `include`, `compact` | `command`, `http` |
| `ConfigChange` | Config file changes | Yes | `user_settings`, `project_settings`, `local_settings`, `policy_settings`, `skills` | `command`, `http` |
### Agentic Loop
| Event | When | Can Block? | Matcher Filters | Supported Types |
|-------|------|------------|-----------------|-----------------|
| `UserPromptSubmit` | User submits prompt | Yes | No matcher support | All four |
| `PreToolUse` | Before tool executes | Yes | Tool name (`Bash`, `Edit\|Write`, `mcp__.*`) | All four |
| `PermissionRequest` | Permission dialog shown | Yes | Tool name | All four |
| `PermissionDenied` | Auto mode denies tool | No (but can retry) | Tool name | `command`, `http` |
| `PostToolUse` | After tool succeeds | No (tool already ran) | Tool name | All four |
| `PostToolUseFailure` | After tool fails | No | Tool name | All four |
| `Stop` | Claude finishes responding | Yes | No matcher support | All four |
| `StopFailure` | Turn ends due to API error | No | `rate_limit`, `authentication_failed`, `billing_error`, `invalid_request`, `server_error`, `max_output_tokens`, `unknown` | `command`, `http` |
### Subagents & Tasks
| Event | When | Can Block? | Matcher Filters | Supported Types |
|-------|------|------------|-----------------|-----------------|
| `SubagentStart` | Subagent spawned | No | Agent type (`Bash`, `Explore`, `Plan`, custom) | `command`, `http` |
| `SubagentStop` | Subagent finishes | Yes | Agent type | All four |
| `TaskCreated` | Task being created | Yes | No matcher support | All four |
| `TaskCompleted` | Task being completed | Yes | No matcher support | All four |
| `TeammateIdle` | Teammate going idle | Yes | No matcher support | `command`, `http` |
### Context & Compaction
| Event | When | Can Block? | Matcher Filters | Supported Types |
|-------|------|------------|-----------------|-----------------|
| `PreCompact` | Before compaction | No | `manual`, `auto` | `command`, `http` |
| `PostCompact` | After compaction | No | `manual`, `auto` | `command`, `http` |
### File & Directory
| Event | When | Can Block? | Matcher Filters | Supported Types |
|-------|------|------------|-----------------|-----------------|
| `CwdChanged` | Working directory changes | No | No matcher support | `command` only |
| `FileChanged` | Watched file changes | No | Filename basename (`.envrc`, `.env`) | `command` only |
| `Notification` | Claude sends notification | No | `permission_prompt`, `idle_prompt`, `auth_success`, `elicitation_dialog` | `command`, `http` |
### Worktrees
| Event | When | Can Block? | Matcher Filters | Supported Types |
|-------|------|------------|-----------------|-----------------|
| `WorktreeCreate` | Worktree being created | Yes (any non-zero) | No matcher support | `command`, `http` |
| `WorktreeRemove` | Worktree being removed | No | No matcher support | `command`, `http` |
### MCP Elicitation
| Event | When | Can Block? | Matcher Filters | Supported Types |
|-------|------|------------|-----------------|-----------------|
| `Elicitation` | MCP requests user input | Yes | MCP server name | `command`, `http` |
| `ElicitationResult` | User responds to elicitation | Yes | MCP server name | `command`, `http` |
## Four Handler Types
### Command (`type: "command"`)
```json
{ "type": "command", "command": "bash script.sh", "timeout": 60, "async": false, "shell": "bash" }
```
- Receives JSON on **stdin**, returns via **stdout/stderr + exit code**
- `async: true` runs in background, results delivered next turn
- `shell: "powershell"` for Windows PowerShell
### HTTP (`type: "http"`)
```json
{
"type": "http",
"url": "http://localhost:8080/hooks/event",
"headers": { "Authorization": "Bearer $MY_TOKEN" },
"allowedEnvVars": ["MY_TOKEN"],
"timeout": 30
}
```
- POST with JSON body (same as command stdin)
- Response body uses same JSON output format as command hooks
- Non-2xx = non-blocking error. To block, return 2xx with decision JSON
### Prompt (`type: "prompt"`)
```json
{ "type": "prompt", "prompt": "Evaluate if safe: $ARGUMENTS", "model": "haiku", "timeout": 30 }
```
- Single-turn LLM evaluation. Returns `{"ok": true}` or `{"ok": false, "reason": "..."}`
- `$ARGUMENTS` placeholder for hook input JSON
- Not supported on: `SessionStart`, `CwdChanged`, `FileChanged`, and other command-only events
### Agent (`type: "agent"`)
```json
{ "type": "agent", "prompt": "Verify tests pass. $ARGUMENTS", "model": "haiku", "timeout": 60 }
```
- Multi-turn subagent with tool access (Read, Grep, Glob, etc.)
- Up to 50 turns. Same `{ok, reason}` response format
- Use when verification requires inspecting files or running commands
## Exit Codes (Command Hooks)
| Exit Code | Effect |
|-----------|--------|
| **0** | Success. Stdout parsed for JSON output. For `UserPromptSubmit`/`SessionStart`, stdout added as context |
| **2** | **Blocking error**. Stderr fed to Claude. JSON on stdout ignored |
| **Other** | Non-blocking error. Stderr logged in verbose mode (`Ctrl+O`). Execution continues |
**Important**: Only exit code 2 blocks. Exit code 1 is non-blocking (unlike typical Unix convention).
## Decision Control Per Event
| Events | Pattern | Key Fields |
|--------|---------|------------|
| `UserPromptSubmit`, `PostToolUse`, `PostToolUseFailure`, `Stop`, `SubagentStop`, `ConfigChange` | Top-level `decision` | `decision: "block"`, `reason` |
| `TeammateIdle`, `TaskCreated`, `TaskCompleted` | Exit code or `continue: false` | Exit 2 blocks with stderr feedback |
| `PreToolUse` | `hookSpecificOutput` | `permissionDecision` (allow/deny/ask/defer), `permissionDecisionReason`, `updatedInput`, `additionalContexRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.