Skip to main content

Module hooks

Module hooks 

Source
Expand description

Hook system for apr code — mirrors Claude Code’s hook events.

Hooks let a user intercept the agent loop at well-defined moments and run an external command. The exit code of the command decides what happens next:

  • 0 → allow (hook did nothing interesting, or approved the action)
  • 1 → warn (hook emitted a message; agent continues)
  • 2 → block (hook vetoed the action; agent aborts that step)

This matches Claude Code’s settings.json[[hooks]] surface 1:1.

PMAT-CODE-HOOKS-001. This file introduces the event enum, the config struct that deserializes from manifest.toml’s [[hooks]] table, and the registry + runner used by the agent loop. Runtime integration ships incrementally:

  • SessionStart — wired from cmd_code (see agent/code.rs)
  • PreToolUse / PostToolUse / UserPromptSubmit / Stop / SubagentStop — surface ships now; call sites land in PMAT-CODE-HOOKS-RUNTIME-001.

Structs§

HookConfig
A single hook entry deserialized from manifest.hooks[].
HookRegistry
Indexed collection of hooks keyed by event.

Enums§

HookDecision
Decision returned by a hook, derived from the command’s exit code.
HookEvent
Canonical hook events mirroring Claude Code.