Skip to content
Agent Engineering / Tool Use

Use hooks for deterministic control, not as the only guardrail

  • BP-0021
  • v1.0.0
  • draft
  • guideline
  • role: any
  • role: orchestrator
  • stage: plan
  • stage: build
  • stage: operate
  • updated 2026-11-24
  • reviewed 2026-11-24
  • next review 2027-05-24
  1. MUST use a hook (or a permission rule) — not an instruction file or skill — for anything that must always or never happen. Instructions are context the agent reads; hooks run every time the event fires.
  2. SHOULD use hooks for work that must follow an event every time: format or lint after an edit, run the affected tests, add an audit log entry, notify a person, inject current context at session start, or stop the agent finishing while checks fail.
  3. MUST keep hard allow and deny decisions in the harness’s permission system (deny rules, managed settings), and use hooks to add checks on top. In Claude Code the hook if filter is best-effort; permission rules are the enforcement layer.
  4. MUST NOT rely on a hook alone for a control whose failure would be serious. Combine it with least privilege for the agent’s credentials and sandboxing (BP-0013 rules 17–19, BP-0005).
  1. MUST put each hook at the right scope: personal (~/.claude/settings.json), project shared (.claude/settings.json, committed and reviewed), project personal (.claude/settings.local.json), organisation (managed settings), or plugin.
  2. MUST review hooks that come with a project, plugin, skill or sub-agent before enabling them. Hooks run arbitrary commands with your permissions.
  3. SHOULD, in managed environments, enforce organisation hooks centrally and restrict others (in Claude Code, managed settings such as allowManagedHooksOnly, and allow-lists for HTTP hook URLs and variables).
  1. SHOULD list and review configured hooks regularly (Claude Code /hooks shows every hook, its source and its command), and remove ones no longer needed.
  2. SHOULD check the debug log when a hook seems not to run or not to block, before changing it (Claude Code --debug).
  3. SHOULD tell the agent, in its instruction file, which hooks exist and what they enforce, so it does not fight them or retry blocked actions in a loop.
  4. MAY temporarily disable hooks for a single diagnostic run only with the owner’s agreement, never as a way around a block.

Any agent harness that supports hooks. Choosing between mechanisms:

Need Mechanism
Must never happen (delete prod data, push to main, read .env) Permission deny rule / managed setting, plus a PreToolUse hook for richer checks
Must happen after an event (format, test, log) Hook (PostToolUse, Stop, SessionStart …)
A convention the agent should follow Instruction file (BP-0016)
A procedure used for some tasks Skill (BP-0019)
Event Hook Effect
PreToolUse on Edit|Write Protect generated, vendored and secret paths Blocks with a reason (BP-0020)
PostToolUse on Edit|Write Run the formatter on the changed file Code always formatted
Stop Run bun test; block finishing on failure Agent cannot report “done” with failing tests
SessionStart Add current branch and open issue to context Agent starts oriented
Notification Desktop or phone notification Person knows the agent is waiting
  • “Never run rm -rf” in CLAUDE.md with no deny rule or hook.
  • Committing a project hook nobody reviewed, or enabling a plugin’s hooks unread.
  • A Stop hook that blocks forever because the check can never pass.
  • Disabling all hooks to get past a block.
  • Musts and must-nots enforced by permissions and hooks, not prose
  • Each hook at the right scope; project and plugin hooks reviewed
  • Hooks listed in the instruction file
  • Hooks reviewed periodically; debug log checked before changes