Hook

Hook

Also called: 钩子 · Lifecycle hook

User code that runs automatically at fixed points in an agent's lifecycle (e.g. before/after a tool call), used to audit, block, or rewrite actions.

beforetool callHOOK(audit / block)toolrunsdeterministic, not model-mediated
Schematic (simplified)

How it works

The runtime calls back your registered code/command at predefined event points. For "before a tool call," a hook can: log the call (audit), check whether arguments are out of bounds and block execution (intercept), or modify arguments and let it through (rewrite). Hooks run deterministically in the runtime, not via model judgement, so they are the right place for "must always happen / must never happen" rules.

Typical uses

  • Write every tool call to a log for later review.
  • Block dangerous commands (dropping a database, exfiltrating data) outright.
  • Auto-run a formatter/lint after a file is saved.
  • Collect usage stats at session end.

Asking the prompt to "please remember to…" is not reliable for these; a hook is.

Common misconceptions

  • A hook is a runtime mechanism, not "the model remembering to do something" — the latter is unreliable.
  • Hooks can rewrite/block tool calls, but they do not understand semantics; you must write the rules carefully.

Related terms

Sources

  1. Anthropic — Claude Docs: Claude Code hooks

Compiled 2026-08-29 · This glossary is compiled from public papers, official specifications, and common industry definitions, and is updated as the field evolves. Corrections welcome.