PLUGIN brewcode / Agents
On this page
Hook Creator
inherit 33 events · 5 handler typesQuick reference
| Field | Value |
|---|---|
| Agent | brewcode:hook-creator |
| Triggers | create hook, PreToolUse hook, debug hook |
| Model | inherit: uses the session model |
| Tools | Read, Write, Edit, Glob, Grep, Bash, WebFetch, WebSearch |
| Output | Hook or handler configuration, registration snippet, verification evidence, limits |
Hook Creator creates, debugs or validates a lifecycle hook against the real event contract. It selects event, handler type, input schema, output channel, matcher and failure policy, following an existing well-built hook and project rules. References are refreshed through Claude Code 2.1.309.
When to use
- Block an action before it runs, with an explicit hard-gate failure policy.
- Add advisory context at a supported lifecycle boundary.
- Fix output that a hook emits but the event ignores.
- Diagnose a stop loop, wrong matcher, or broken registration.
- Choose between command, HTTP, MCP, prompt and agent handlers.
Examples
Create one PreToolUse hook for the project's destructive command policy.
Own its script and registration snippet. Preserve existing hooks, reject unsafe
input explicitly, and test both allowed and denied calls.
Debug my Stop hook: it keeps blocking after the task finishes.
Verify the Stop output contract and stop_hook_active guard.
How it works
- Resolve behavior and ownership
Gating, context, modification, logging or cleanup; settings file, plugin
hooks.json, skill or agent frontmatter, or a mod when the need is not a classic hook. Unrelated registrations stay. - Choose event and handler
Handler support and blocking differ per event; a nonzero exit does not guarantee a block.
- Implement the contract
Emit the event’s output shape; pick fail-open advisory or fail-closed gate on purpose.
- Register and verify
Exact matcher, type, path and timeout; test success, denial, malformed input and failure.
One bounded deliverable per run; larger briefs return a split proposal (scope guard). Questions and approvals stay with the main caller.
Handler types and command exec form #
| Type | Purpose and limits |
|---|---|
command | Deterministic executable or shell handler; event-specific stdout and exit behavior |
http | Send hook input to an endpoint and interpret its supported response |
mcp_tool | Invoke a configured MCP tool; connection and event support constrain execution |
prompt | LLM decision handler with ok/reason output; supported events only |
agent | LLM agent decision handler; supported events only |
Prompt and agent handlers return decisions and do not inject context. SessionStart supports command/MCP handlers, Setup skips MCP, PermissionRequest skips agent handlers and needs its own output shape.
{
"type": "command",
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/hooks/example.mjs"],
"timeout": 5
}Prefer exec form (command plus args, Claude Code 2.1.139+): the command resolves on PATH and runs without shell parsing, and args: [] alone also selects it for a directly executable script. Use shell form only for pipes. args, shell, async and asyncRewake are command-only.
Where to declare a hook #
| Goal | Declare in |
|---|---|
| Rule for every project, one repo, or the team | ~/.claude/settings.json, .claude/settings.local.json, .claude/settings.json |
| Org policy users cannot switch off | Managed settings, with onFailure: "block" |
| Behavior shipped with a plugin | Plugin hooks/hooks.json, exec form |
| Guard that must hold from a skill’s first use to session end | Skill frontmatter hooks: (once: true = one-shot) |
| Guard only while one project or user agent runs | Agent frontmatter hooks: (plugin agents ignore it; declare plugin-agent hooks in hooks/hooks.json) |
| UI, in-process tool gate, effort or model rewrite | Not a classic hook: a mod (Mod Creator) |
Hooks merge across non-managed locations. For managed hooks only the highest-ranked source applies (first wins; managedSourcesBehavior: "merge", 2.1.242+, unions them). With mods installed, non-managed PreToolUse hooks run after the mods call next; a gate that must survive a mod is a managed hook or a permission rule.
Event-specific output #
| Goal | Correct contract |
|---|---|
| Add context on a supported event | hookSpecificOutput.additionalContext; on PreToolUse send only hookEventName and additionalContext (permissionDecision: "allow" silently auto-approves the call) |
| Deny a tool before execution | PreToolUse permissionDecision=deny |
| Modify tool parameters | Supported updatedInput; one owner only |
| Stop feedback or continue work | Stop/SubagentStop context or decision=block with reason |
| Report after a tool runs | PostToolUse context; prior side effects remain |
| Replace a visible tool result | PostToolUse updatedToolOutput |
| User-facing status | Top-level systemMessage, where supported |
| Custom worktree | WorktreeCreate stdout holds only the created absolute path |
UserPromptSubmit cannot rewrite the prompt via updatedInput. Setup discards JSON output. PreCompact and PostCompact have no additionalContext channel. Check the reference matrix before copying another event’s schema.
Exit codes and failure policy #
- Valid JSON takes effect even on a nonzero exit for standard decision events; exit 2 still blocks where supported.
- A failed command is not a denial. A policy gate emits an explicit denial; never reuse an advisory fail-open template for a hard requirement.
- Hard gate on
commandorhttp: setonFailure: "block"(Claude Code 2.1.295+; older versions ignore it). Without it a crash, timeout or unstartable script lets the action through: a working gate denies with exit 2; onlyonFailure: "block"covers a crash. Oneifrule per tool; test-fire each path. - Async handlers never gate;
asyncRewakereports a later result only.
References and validation limits #
References under brewcode/skills/agents/references/ cover all 33 events, handler types, I/O routing, registration, environment variables and templates. Fixtures validate implemented branches only; the final report separates generated files, registration changes, tests run and untested live behavior.
agents/tests/suite-creator-contract.mjs is a 120-check regression suite pinning what hook-creator, agent-creator, skill-creator and mod-creator teach about the hook, subagent and mod API.
Related
Brewcode overview
Brewcode hooks
Skill Creator
Mod Creator
GitHub source
Update: /brewtools:plugin-update, /reload-plugins, then /brewcode:setup-status upgrade - FAQ