Hook Creator

Caution

Hooks fail silently when the wrong output channel is used. On Stop and SubagentStop, use hookSpecificOutput.additionalContext to give Claude feedback and keep the turn going — plain additionalContext at the top level is not the correct channel for those events. decision:"block" on PostToolUse is not a valid field. Getting the event-to-channel mapping wrong means the hook runs and produces zero effect, with no error to debug.

Tip

hook-creator knows all 27 events, 5 hook types, and the full routing matrix. Describe what you want in plain language — it picks the right event, output channel, and schema, then delivers a working file with fail-safe error handling included.

Quick reference

FieldValue
Trigger”create hook”, “PreToolUse hook”, “Stop hook”, “hook doesn’t work”, “debug hook”
Modelopus
ToolsRead, Write, Edit, Glob, Grep, Bash, WebFetch, WebSearch
OutputHook file (.sh or .mjs) + config snippet + verification checklist

When to use

  • Create a new hook — you know what you want the hook to do, but not which event or output format to use
  • Debug a broken hook — the hook runs but Claude ignores it, or the session is stuck
  • Validate an existing hook — check routing, schema, fail-safe, and stop_hook_active guard
  • Choose a hook type — unsure whether to use command, http, mcp_tool, prompt, or agent hook
  • Add context injection — inject project rules, mode state, or subagent instructions at session or tool boundaries

Examples

"Create a PreToolUse hook that blocks `rm -rf` commands"
"My Stop hook keeps blocking the session even after the task finishes.
 The hook checks a state file but the session never exits."
"Write a SessionStart hook that injects the contents of .project-rules.md
 into every new session as additionalContext"

Flow

  1. Clarify intent

    Asks which event, which behavior (block / inject / modify / log), and where the hook config should live (project settings, global settings, or plugin hooks.json). Skips questions when intent is unambiguous.

  2. Select event and channel

    Applies the routing matrix — picks the correct event from 27 options and the right output channel (additionalContext, updatedInput, permissionDecision, decision, hookSpecificOutput) for your goal. Wrong channel = silent failure, so this step is non-negotiable.

  3. Generate the hook file

    Writes a .sh (bash) or .mjs (Node.js) file from a production template. Always includes: stdin parsing, try/catch with output({}) fallback, stop_hook_active guard for Stop/SubagentStop hooks, and correct shebang.

  4. Generate the config snippet

    Produces the exact JSON block to paste into your target config file (settings.json, settings.local.json, or hooks.json). Includes matcher, hook type, and command path.

  5. Deliver verification checklist

    Lists what to confirm: shebang, fail-safe catch, schema validity, executable bit, performance (<1s for blocking hooks). For debugging sessions, runs the hook manually with test input and explains what each output field does.

Event catalogue and routing matrix (expand for reference)

Output channel by event

GoalChannelEvent
Inject context for ClaudeadditionalContextSessionStart, PreToolUse, UserPromptSubmit
Inject into subagent promptupdatedInput.promptPreToolUse (matcher: Task)
Block tool executionpermissionDecision:"deny"PreToolUse
Block session stopdecision:"block" + reasonStop
Give Claude feedback at stop (keep turn going)hookSpecificOutput.additionalContextStop, SubagentStop
Post-tool feedbackadditionalContextPostToolUse
Modify tool parametersupdatedInputPreToolUse
Show user warning (Claude does NOT see)systemMessageAny
Auto-allow permissiondecision.behavior:"allow"PermissionRequest
Control teammates{continue, stopReason} JSONTeammateIdle, TaskCompleted, TaskCreated
Re-scan skill dirs on startupreloadSkills: trueSessionStart (CC 2.1.152)
Set session title on startup/resumehookSpecificOutput.sessionTitleSessionStart (CC 2.1.152)

All 27 events

EventBlocking?Key use
SessionStartNoContext injection on start/resume; supports reloadSkills and sessionTitle outputs (CC 2.1.152)
UserPromptSubmitYesGate or modify user prompts
PreToolUseYesAllow / deny / modify tool calls
PermissionRequestYesAuto-allow or auto-deny permission dialogs
PostToolUseNoFeedback after tool completes
PostToolUseFailureNoReact to failed tool call
SubagentStartNoInject into subagent context
SubagentStopYesBlock subagent exit; supports additionalContext to give Claude feedback
StopYesBlock session exit until condition met; supports additionalContext to give Claude feedback (CC 2.1.163)
PreCompactNoWrite handoff before auto-compact
PostCompactNoReact after compact
NotificationNoLog or react to notifications
TeammateIdleYesControl agent team flow
TaskCompletedYesAccept or re-assign tasks
TaskCreatedYesIntercept new tasks
ConfigChangeYesReact to settings file changes
InstructionsLoadedNoTrack CLAUDE.md / rules file loads
FileChangedNoReact to file system changes
CwdChangedNoReact to directory changes
WorktreeCreateYesIntercept worktree creation
WorktreeRemoveNoReact to worktree removal
StopFailureNoReact to rate-limit / API errors
ElicitationYesAuto-fill MCP forms
ElicitationResultYesPost-elicitation hook
SessionEndNoCleanup on session close
PermissionDeniedYesRetry after auto-mode denial (v2.1.89+)
MessageDisplayNoTransform or hide assistant message text as it is displayed to the user (CC 2.1.152)

Hook types

TypeTimeoutDescription
command600sShell/Node script; receives hook JSON on stdin, returns JSON on stdout. Deterministic, file I/O, external tools.
http600sPOSTs the full hook JSON payload to a URL (axios); blocks for response; parses JSON body as hook output (decision / additionalContext). User-prompt field is named prompt in the payload. (v2.1.63+)
mcp_tool600sInvokes a tool on an already-configured MCP server synchronously; returned text parsed exactly like a command hook’s stdout JSON. Config: server (required), tool (required), input (optional; string values support ${...} interpolation from hook input JSON).
prompt30sInline-LLM allow/block gate — evaluates the natural-language text, decides allow vs block+reason. Its text is NOT added to the model’s context.
agent60sLLM-agent allow/block gate, same semantics as prompt (allow or block+reason). NOT a general subagent whose output is injected. Experimental.

prompt/agent = gates only (allow/block). command/http/mcp_tool = can both gate AND inject context.

For agent-type hooks: the spawned subagent inherits the session’s permissionMode. Never configure the parent session with --dangerously-skip-permissions just to avoid hook permission prompts — use a narrow permissionMode: acceptEdits on the hook’s agent definition instead.

Troubleshooting flags and environment variables (expand)

Safe mode and bundled skills

Flag / Env varEffect
--safe-mode or CLAUDE_CODE_SAFE_MODE=1Starts CC with ALL customizations disabled: CLAUDE.md, plugins, skills, hooks, MCP servers. Use to isolate whether a hook is causing a startup problem. (CC 2.1.169)
--disable-bundled-skills or CLAUDE_CODE_DISABLE_BUNDLED_SKILLS=1Hides all bundled skills, workflows, and built-in commands without disabling plugins or hooks. Useful when a bundled skill name collides with a project skill.

Tip

--safe-mode is also the fastest way to verify a hook regression: if the problem disappears in safe mode, the hook is the cause.

Post-session lifecycle hook

A post-session lifecycle hook runs after a session ends and before the workspace is deleted. This is NOT a hooks.json event — do not add it to hooks.json; it will be silently ignored. It is available only on self-hosted runners as a workspace lifecycle callback configured at the runner level. (CC 2.1.169)

📄

Brewcode overview

All brewcode agents and skills — hooks live here in the plugin’s hooks/ directory.

🔗

GitHub source

Agent definition with full routing matrix, templates, and validation checklist.

Updating plugins

Use /brewtools:plugin-update to check and update the brewcode plugin suite in one command. See the FAQ for details.