Claude Code Hooks Knowledge Bank
Expert guidance for Claude Code hooks -- event lifecycle, hook types (command, prompt, agent), configuration, community patterns, best practices, and troubleshooting.
Community Intel (Shared HALT Workflow)
This skill delegates all community-intel behavior to shared files. Keep this block minimal and consistent across skills.
- Read
../../shared/community-intel.adapter.json (relative to this file).
- If the adapter file is missing or unreadable:
- tell the user: "Community intel is unavailable right now. Answering from reference files only."
- continue to Step 2 with no HALT status line.
- Check whether
../../shared/community-intel-workflow.md exists.
- If the workflow file is missing:
- tell the user: "Community intel is unavailable right now. Answering from reference files only."
- continue to Step 2 with no HALT status line.
- If the workflow file exists:
- read it and execute Step 0 + Step 1 using adapter values
- if
--upgrade was passed, follow workflow sync-report behavior and stop
- otherwise return here and continue to Step 2
Step 2: Classify the Question
Parse the user's question into one or more categories. If you already classified in Step 1b, reuse that classification.
If a question spans multiple categories, identify the primary concern and secondary categories. Address primary first, then connect to secondary categories with separate headed sections.
| Category |
Keywords / Signals |
Reference File |
| Events & Lifecycle |
event, lifecycle, SessionStart, PreToolUse, PostToolUse, Stop, when fires, matcher, SubagentStart, SubagentStop, PreCompact, SessionEnd |
event-reference.md |
| Types & Config |
settings.json, command hook, prompt hook, agent hook, matcher, config, location, /hooks menu, async, timeout |
hook-types-and-config.md |
| Decision & Control |
block, allow, deny, exit code, output, permission, modify input, decision, hookSpecificOutput, context injection |
decision-control.md |
| Recipes & Patterns |
auto-format, guard, firewall, notify, checkpoint, how do I, example, recipe, pattern |
community-patterns.md |
| Best Practices |
best practice, performance, architecture, should I, anti-pattern, when to use, security |
best-practices.md |
| Troubleshooting |
not working, not firing, isn't firing, isnt firing, debug, error, broken, help, infinite loop, JSON failed |
troubleshooting.md |
| Plugins & Skills |
plugin hook, skill hook, hooks.json, CLAUDE_PLUGIN_ROOT, agent hook lifecycle, frontmatter, managed policy |
hooks-in-plugins.md |
Step 3: Read Reference Files
Read the relevant reference files based on the classification. Always read the primary reference file for the category. Verified intel was already loaded in Step 1d.
For multi-category questions, read all relevant files.
Step 4: Synthesize Answer
Universal Response Structure
Every response should follow this structure:
- One-line answer -- direct, no preamble
- Key details -- tables, steps, bullets as appropriate
- Configuration -- settings.json snippets, copy-paste ready
- Scripts -- if applicable, fenced code blocks with shell scripts
- Gotchas -- bold warnings for common pitfalls
- Sources -- reference files cited
For Event Questions
- State when the event fires and what it matches on
- Show the JSON input schema
- Show the decision control options
- Include a minimal working example
- Note any limitations (can't block, no matcher support, etc.)
For Configuration Questions
- Show the settings.json structure
- Specify where to put it (user, project, local, plugin)
- Explain matcher patterns with examples
- Note the hook type and its specific fields
For Recipe/Pattern Questions
- Provide the complete settings.json config
- If a script is needed, provide the full script
- Explain what each piece does
- Note any gotchas (async can't return decisions, format-on-edit noise, etc.)
For Troubleshooting Questions
- Match symptoms to the troubleshooting table
- Provide debug steps in order of likelihood
- Check verified-intel.md for recently accepted community findings
- Include the exact debug commands (
claude --debug, Ctrl+O, /hooks)
For Decision Control Questions
- Identify which event they're working with
- Show the correct decision pattern (top-level vs hookSpecificOutput)
- Provide a complete JSON output example
- Warn about the exit code vs JSON choice (pick one, not both)
For Plugin/Skill Hook Questions
- Show the correct file format (hooks.json vs frontmatter)
- Explain the scoping (when plugin is enabled vs while skill is active)
- Note the known issue with plugin skill frontmatter hooks
- Show path variable usage (
${CLAUDE_PLUGIN_ROOT})
Response Guidelines
- Always cite the reference file you're drawing from
- Provide complete configs -- users should be able to copy/paste settings.json snippets
- Include scripts -- full, executable shell scripts when recipes need them
- Warn about pitfalls -- especially async decision limitations, stop_hook_active, shell profile JSON issues
- Include verified intel -- if verified-intel.md has relevant accepted findings, mention them
- Be direct -- answer the question first, then provide context
- Tables for comparisons -- use tables when comparing event types, hook types, or decision patterns
- JSON schemas -- show the exact JSON structure for inputs and outputs
- HALT status line -- if
HALT_STATUS_LINE is set by the shared workflow, place it at the top of the response before the answer
- Inline attribution -- when a claim is informed by verified intel, cite it inline as
(from community intel, MMM YYYY)
Examples
Example 1: Recipe Question
User: How do I auto-format code when Claude edits a file?
Skill: [Reads community-patterns.md]
Use a PostToolUse hook with an Edit|Write matcher. Add this to .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
}
]
}
]
}
}
For Biome: replace with `jq -r '.tool_input.file_path' | xargs npx biome check --write`
**Gotcha:** Formatting on every edit adds context window noise.
Consider formatting on commit instead, or use `async: true`
so it doesn't block Claude's flow.
Example 2: Block Dangerous Commands
User: Block dangerous git commands like force push
Skill: [Reads community-patterns.md + decision-control.md]
Use a PreToolUse hook that checks Bash commands against dangerous patterns.
Exit code 2 blocks the command, and stderr tells Claude why.
Add to .claude/settings.json:
[provides settings.json config + block-dangerous.sh script]
The matcher "Bash" ensures it only fires on shell commands.
PreToolUse fires before execution, so the command never runs.
Example 3: Troubleshooting
User: My hook isn't firing
Skill: [Detects Troubleshooting intent -> force refresh]
Skill: "Refreshing community intel - this takes about 60 seconds."
Skill: [Reads troubleshooting.md + hook-types-and-config.md + verified-intel.md]
Common causes in order of likelihood:
1. **Wrong matcher** -- matchers are case-sensitive regex.
Check: `/hooks` menu, verify it appears under the correct event.
2. **Wrong event** -- PreToolUse fires before execution,
PostToolUse fires after.
3. **Script not executable** -- `chmod +x ./my-hook.sh`
4. **PermissionRequest in -p mode** -- not supported in
non-interactive mode. Use PreToolUse instead.
Debug: `claude --debug` shows which hooks matched and their output.
Toggle verbose mode with `Ctrl+O`.
[Includes relevant verified intel findings]
Community intel synced: auto-promoted 1 new finding across 1 topic.
*(from community intel, Jan 2026)*
Example 4: Optional manual sync report
User: /hooks --upgrade
Skill: [Detects --upgrade flag, runs shared workflow in sync-report mode]
Skill: [Refreshes + auto-promotes findings]
Skill: "Community intel sync complete for /hooks. Auto-promoted 2 findings across 2 topics."
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: nathanvale-side-quest-plugins-hooks3description: Claude Code Hooks Knowledge Bank4---56# Claude Code Hooks Knowledge Bank78Expert guidance for Claude Code hooks -- event lifecycle, hook types (command, prompt, agent), configuration, community patterns, best practices, and troubleshooting.910## Community Intel (Shared HALT Workflow)1112This skill delegates all community-intel behavior to shared files. Keep this block minimal and consistent across skills.13141. Read `../../shared/community-intel.adapter.json` (relative to this file).152. If the adapter file is missing or unreadable:16 - tell the user: "Community intel is unavailable right now. Answering from reference files only."17 - continue to Step 2 with no HALT status line.183. Check whether `../../shared/community-intel-workflow.md` exists.194. If the workflow file is missing:20 - tell the user: "Community intel is unavailable right now. Answering from reference files only."21 - continue to Step 2 with no HALT status line.225. If the workflow file exists:23 - read it and execute Step 0 + Step 1 using adapter values24 - if `--upgrade` was passed, follow workflow sync-report behavior and stop25 - otherwise return here and continue to Step 22627## Step 2: Classify the Question2829Parse the user's question into one or more categories. If you already classified in Step 1b, reuse that classification.3031If a question spans multiple categories, identify the primary concern and secondary categories. Address primary first, then connect to secondary categories with separate headed sections.3233| Category | Keywords / Signals | Reference File |34|----------|-------------------|----------------|35| **Events & Lifecycle** | event, lifecycle, SessionStart, PreToolUse, PostToolUse, Stop, when fires, matcher, SubagentStart, SubagentStop, PreCompact, SessionEnd | [event-reference.md](references/event-reference.md) |36| **Types & Config** | settings.json, command hook, prompt hook, agent hook, matcher, config, location, /hooks menu, async, timeout | [hook-types-and-config.md](references/hook-types-and-config.md) |37| **Decision & Control** | block, allow, deny, exit code, output, permission, modify input, decision, hookSpecificOutput, context injection | [decision-control.md](references/decision-control.md) |38| **Recipes & Patterns** | auto-format, guard, firewall, notify, checkpoint, how do I, example, recipe, pattern | [community-patterns.md](references/community-patterns.md) |39| **Best Practices** | best practice, performance, architecture, should I, anti-pattern, when to use, security | [best-practices.md](references/best-practices.md) |40| **Troubleshooting** | not working, not firing, isn't firing, isnt firing, debug, error, broken, help, infinite loop, JSON failed | [troubleshooting.md](references/troubleshooting.md) |41| **Plugins & Skills** | plugin hook, skill hook, hooks.json, CLAUDE_PLUGIN_ROOT, agent hook lifecycle, frontmatter, managed policy | [hooks-in-plugins.md](references/hooks-in-plugins.md) |4243## Step 3: Read Reference Files4445Read the relevant reference files based on the classification. Always read the primary reference file for the category. Verified intel was already loaded in Step 1d.4647For multi-category questions, read all relevant files.4849## Step 4: Synthesize Answer5051### Universal Response Structure5253Every response should follow this structure:54551. **One-line answer** -- direct, no preamble562. **Key details** -- tables, steps, bullets as appropriate573. **Configuration** -- settings.json snippets, copy-paste ready584. **Scripts** -- if applicable, fenced code blocks with shell scripts595. **Gotchas** -- bold warnings for common pitfalls606. **Sources** -- reference files cited6162### For Event Questions63641. State when the event fires and what it matches on652. Show the JSON input schema663. Show the decision control options674. Include a minimal working example685. Note any limitations (can't block, no matcher support, etc.)6970### For Configuration Questions71721. Show the settings.json structure732. Specify where to put it (user, project, local, plugin)743. Explain matcher patterns with examples754. Note the hook type and its specific fields7677### For Recipe/Pattern Questions78791. Provide the complete settings.json config802. If a script is needed, provide the full script813. Explain what each piece does824. Note any gotchas (async can't return decisions, format-on-edit noise, etc.)8384### For Troubleshooting Questions85861. Match symptoms to the troubleshooting table872. Provide debug steps in order of likelihood883. Check verified-intel.md for recently accepted community findings894. Include the exact debug commands (`claude --debug`, `Ctrl+O`, `/hooks`)9091### For Decision Control Questions92931. Identify which event they're working with942. Show the correct decision pattern (top-level vs hookSpecificOutput)953. Provide a complete JSON output example964. Warn about the exit code vs JSON choice (pick one, not both)9798### For Plugin/Skill Hook Questions991001. Show the correct file format (hooks.json vs frontmatter)1012. Explain the scoping (when plugin is enabled vs while skill is active)1023. Note the known issue with plugin skill frontmatter hooks1034. Show path variable usage (`${CLAUDE_PLUGIN_ROOT}`)104105## Response Guidelines106107- **Always cite the reference file** you're drawing from108- **Provide complete configs** -- users should be able to copy/paste settings.json snippets109- **Include scripts** -- full, executable shell scripts when recipes need them110- **Warn about pitfalls** -- especially async decision limitations, stop_hook_active, shell profile JSON issues111- **Include verified intel** -- if verified-intel.md has relevant accepted findings, mention them112- **Be direct** -- answer the question first, then provide context113- **Tables for comparisons** -- use tables when comparing event types, hook types, or decision patterns114- **JSON schemas** -- show the exact JSON structure for inputs and outputs115- **HALT status line** -- if `HALT_STATUS_LINE` is set by the shared workflow, place it at the top of the response before the answer116- **Inline attribution** -- when a claim is informed by verified intel, cite it inline as `(from community intel, MMM YYYY)`117118## Examples119120### Example 1: Recipe Question121122```text123User: How do I auto-format code when Claude edits a file?124125Skill: [Reads community-patterns.md]126127Use a PostToolUse hook with an Edit|Write matcher. Add this to .claude/settings.json:128129{130 "hooks": {131 "PostToolUse": [132 {133 "matcher": "Edit|Write",134 "hooks": [135 {136 "type": "command",137 "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"138 }139 ]140 }141 ]142 }143}144145For Biome: replace with `jq -r '.tool_input.file_path' | xargs npx biome check --write`146147**Gotcha:** Formatting on every edit adds context window noise.148Consider formatting on commit instead, or use `async: true`149so it doesn't block Claude's flow.150```151152### Example 2: Block Dangerous Commands153154```text155User: Block dangerous git commands like force push156157Skill: [Reads community-patterns.md + decision-control.md]158159Use a PreToolUse hook that checks Bash commands against dangerous patterns.160Exit code 2 blocks the command, and stderr tells Claude why.161162Add to .claude/settings.json:163[provides settings.json config + block-dangerous.sh script]164165The matcher "Bash" ensures it only fires on shell commands.166PreToolUse fires before execution, so the command never runs.167```168169### Example 3: Troubleshooting170171```text172User: My hook isn't firing173174Skill: [Detects Troubleshooting intent -> force refresh]175Skill: "Refreshing community intel - this takes about 60 seconds."176Skill: [Reads troubleshooting.md + hook-types-and-config.md + verified-intel.md]177178Common causes in order of likelihood:1791801. **Wrong matcher** -- matchers are case-sensitive regex.181 Check: `/hooks` menu, verify it appears under the correct event.1821832. **Wrong event** -- PreToolUse fires before execution,184 PostToolUse fires after.1851863. **Script not executable** -- `chmod +x ./my-hook.sh`1871884. **PermissionRequest in -p mode** -- not supported in189 non-interactive mode. Use PreToolUse instead.190191Debug: `claude --debug` shows which hooks matched and their output.192Toggle verbose mode with `Ctrl+O`.193194[Includes relevant verified intel findings]195196Community intel synced: auto-promoted 1 new finding across 1 topic.197*(from community intel, Jan 2026)*198```199200### Example 4: Optional manual sync report201202```text203User: /hooks --upgrade204205Skill: [Detects --upgrade flag, runs shared workflow in sync-report mode]206Skill: [Refreshes + auto-promotes findings]207Skill: "Community intel sync complete for /hooks. Auto-promoted 2 findings across 2 topics."208```209210---211> Converted and distributed by [TomeVault](https://tomevault.io/claim/nathanvale) — claim your Tome and manage your conversions.212<!-- tomevault:4.0:skill_md:2026-04-15 -->