PLUGIN brewcode / Agents

Hook Creator

inherit 33 events · 5 handler types

Quick reference

FieldValue
Agentbrewcode:hook-creator
Triggerscreate hook, PreToolUse hook, debug hook
Modelinherit: uses the session model
ToolsRead, Write, Edit, Glob, Grep, Bash, WebFetch, WebSearch
OutputHook 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

  1. 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.

  2. Choose event and handler

    Handler support and blocking differ per event; a nonzero exit does not guarantee a block.

  3. Implement the contract

    Emit the event’s output shape; pick fail-open advisory or fail-closed gate on purpose.

  4. 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 #
TypePurpose and limits
commandDeterministic executable or shell handler; event-specific stdout and exit behavior
httpSend hook input to an endpoint and interpret its supported response
mcp_toolInvoke a configured MCP tool; connection and event support constrain execution
promptLLM decision handler with ok/reason output; supported events only
agentLLM 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 #
GoalDeclare 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 offManaged settings, with onFailure: "block"
Behavior shipped with a pluginPlugin hooks/hooks.json, exec form
Guard that must hold from a skill’s first use to session endSkill frontmatter hooks: (once: true = one-shot)
Guard only while one project or user agent runsAgent frontmatter hooks: (plugin agents ignore it; declare plugin-agent hooks in hooks/hooks.json)
UI, in-process tool gate, effort or model rewriteNot 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 #
GoalCorrect contract
Add context on a supported eventhookSpecificOutput.additionalContext; on PreToolUse send only hookEventName and additionalContext (permissionDecision: "allow" silently auto-approves the call)
Deny a tool before executionPreToolUse permissionDecision=deny
Modify tool parametersSupported updatedInput; one owner only
Stop feedback or continue workStop/SubagentStop context or decision=block with reason
Report after a tool runsPostToolUse context; prior side effects remain
Replace a visible tool resultPostToolUse updatedToolOutput
User-facing statusTop-level systemMessage, where supported
Custom worktreeWorktreeCreate 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 command or http: set onFailure: "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; only onFailure: "block" covers a crash. One if rule per tool; test-fire each path.
  • Async handlers never gate; asyncRewake reports 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.

Brewcode overview

Agents, skills, and project setup tools.

Brewcode hooks

The two registered plugin handlers and their channels.

Skill Creator

Build skill workflows and resource contracts.

Mod Creator

Build Claude Code mods with a reference pack and drift check.

GitHub source

Authoring policy, event selection, and verification requirements.

Update: /brewtools:plugin-update, /reload-plugins, then /brewcode:setup-status upgrade - FAQ