DictionaryAgents
Agent Hooks
Scripts that always run at set moments in an AI session, like a doorbell that rings every time someone enters.
Definition
Deterministic shell commands that run at key lifecycle points during agent sessions. Claude Code's hooks reference lists over 30 events, including PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest, UserPromptSubmit, Stop, SubagentStart, SubagentStop, PreCompact, PostCompact, SessionStart, and SessionEnd. Unlike instructions that guide behavior, hooks execute code with guaranteed outcomes, which is useful for enforcing security policies, automating code quality checks, or creating audit trails.
Example
A PostToolUse hook runs the project formatter after every file edit, and a PreToolUse hook blocks any rm -rf command.