Open PluginsSupported Agents

For Plugin Builders

For Agent Builders

Hooks

Event handlers that respond to lifecycle events in the agent tool.

Hooks are event handlers that respond to lifecycle events in the agent tool. They enable plugins to automate actions like formatting code after edits, running linters, validating outputs, or enforcing policies.

Configuration Format

Hooks are configured in hooks/hooks.json at the plugin root.

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "${PLUGIN_ROOT}/scripts/format-code.sh"
          }
        ]
      }
    ]
  }
}

Hook Rules

A hook rule matches events and dispatches to one or more hook actions.

FieldRequiredTypeDescription
matcherNostringRegex pattern to filter events. Matches all if omitted.
hooksYesHookAction[]Actions to execute when the rule matches.

The matcher tests against event-specific context: tool name for tool events, file path for file events, command string for shell events.

Core Events

EventWhen It FiresMatcher Context
PreToolUseBefore the agent uses a toolTool name
PostToolUseAfter a tool is used successfullyTool name
PostToolUseFailureAfter a tool use failsTool name
SessionStartAt the beginning of a session
SessionEndAt the end of a session

Extended Events

EventWhen It FiresMatcher Context
BeforeReadFileBefore reading a fileFile path
AfterFileEditAfter a file is written or editedFile path
BeforeShellExecutionBefore executing a shell commandCommand string
AfterShellExecutionAfter a shell command completesCommand string
UserPromptSubmitWhen the user submits a prompt
StopWhen the agent attempts to stop
SubagentStart / SubagentStopSub-agent lifecycle

Tools MUST ignore event names they do not recognize.

Hook Action Types

command

{ "type": "command", "command": "${PLUGIN_ROOT}/scripts/lint.sh" }

Receives event context as JSON on stdin. Exit code 0 = success.

prompt

{ "type": "prompt", "prompt": "Review the following change for security issues: $ARGUMENTS" }

Sends the prompt to the LLM. $ARGUMENTS is replaced with event context.

agent

{ "type": "agent", "prompt": "Verify the code changes follow the style guide." }

Like prompt, but with tool access for multi-step verification.

Script Requirements

Hook scripts MUST be executable, include a shebang line, and use ${PLUGIN_ROOT} for internal paths. Exit 0 on success, write errors to stderr.

Execution Model

  • Multiple rules MAY match the same event. All are executed.
  • Within a rule, hooks execute in array order.
  • Tools SHOULD enforce timeouts. Failures MUST NOT crash the host tool.