Skip to content
Last Dictionary

hook

nounAlso: hooks, lifecycle hook, agent hook, PreToolUse hook

In plain wordsA user-supplied script or check that runs automatically at set moments in an AI agent's work — before a command, after a file edit, when it tries to stop — enforcing rules the AI cannot skip.

  1. 1

    Agents

    A handler supplied by the user — usually a shell command, sometimes an HTTP request, a tool call or a prompt to another model — that an agent harnessharness, n.: The software around an AI model that gives it instructions and tools, carries out its actions and decides when it stops. The model is the engine; the harness is the rest of the car. triggers by itself at fixed points in a session: when a session starts, when the user submits a prompt, before or after a tool calltool call, n.: A single request from an AI model to use one of its tools — naming the tool and filling in the details — which the surrounding software then carries out and reports back on., when a subagentsubagent, n.: A helper AI agent that a main agent starts to handle one piece of a job; it works in its own separate workspace and reports back a short summary when it is done. finishes, before context compactioncompaction, n.: Like replacing a stack of rough notes with a one-page digest: when an AI's conversation grows too long for its memory, the history is condensed into a summary and the work continues from there., or when the agent tries to end its turn. The harness passes the hook structured data about the event; the hook can log it, add context for the model, alter inputs, or block the action and return a reason that the model reads — refusing an edit to a protected file, say, or forbidding the agent to stop while tests fail. Unlike instructions in a prompt or agent instruction fileagent instruction file, n.: A plain-text file kept in a software project that tells AI coding agents how the project works — how to build and test it, which conventions to follow, what to avoid — read at the start of every session., which the model may ignore, a hook always runs, so it can enforce a rule. Because they execute arbitrary code with the user's privileges, hooks arriving in shared repositories or plugins must be reviewed before they are trusted.

    A PreToolUse hook blocks any command that touches the production database, whatever the agent decides.

  2. 2

    Programming (general)

    A point in a program where outside code can be attached to observe or alter its behavior — editor hooks, event handlers, git hooks that run before a commit, framework callbacks. The agent sense borrows both the idea and the name.

Origin

'Hook' has meant an attachment point for custom code since at least the 1980s (Emacs Lisp hooks) and gained wide use with git hooks (2005). Anthropic added lifecycle hooks to Claude Code on 30 June 2025 (version 1.0.38), and other coding agents introduced similar mechanisms.

Usage note

Hooks enforce; prompts persuade. A hook that fails open — letting the action through when the hook itself crashes — gives a weaker guarantee than one configured to fail closed.

Related

See also
  • harnessharness, n.: The software around an AI model that gives it instructions and tools, carries out its actions and decides when it stops. The model is the engine; the harness is the rest of the car.
  • permission systempermission system, n.: The rules that decide what an AI agent may do on its own, what it must ask a person about first, and what it may never do — like a phone's settings for which apps can use the camera.
  • tool calltool call, n.: A single request from an AI model to use one of its tools — naming the tool and filling in the details — which the surrounding software then carries out and reports back on.
  • stop conditionstop condition, n.: The rule that tells an AI agent when to stop working — because the task is done, a time or cost limit has been reached, or something has gone wrong.
  • agent instruction fileagent instruction file, n.: A plain-text file kept in a software project that tells AI coding agents how the project works — how to build and test it, which conventions to follow, what to avoid — read at the start of every session.
  • guardrailsguardrails, n.: Safety checks built around an AI system — filters on what goes in and comes out, and limits on what it may do — to keep it from producing harmful or off-topic content or leaking data.
Contrast with
  • system promptsystem prompt, n.: Background instructions given to a chatbot before the conversation starts, setting its role, rules, tone and tools. Users usually never see it, but it shapes every reply.

Sources

  1. Anthropic. Hooks reference. Claude Code documentation. code.claude.com/docs/en/hooks

Mentioned in

agent instruction fileagent instruction file, n.: A plain-text file kept in a software project that tells AI coding agents how the project works — how to build and test it, which conventions to follow, what to avoid — read at the start of every session., Claude CodeClaude Code, prop. n.: A coding assistant from Anthropic that works as an agent: given a programming task, it explores the project, changes the code and runs programs to check its work, from the web, a desktop app, an editor or a terminal., permission systempermission system, n.: The rules that decide what an AI agent may do on its own, what it must ask a person about first, and what it may never do — like a phone's settings for which apps can use the camera., tool calltool call, n.: A single request from an AI model to use one of its tools — naming the tool and filling in the details — which the surrounding software then carries out and reports back on., ChatGPT pluginsChatGPT plugins, prop. n.: Add-ons, launched in 2023 and retired in 2024, that let ChatGPT use outside services — web browsing, a code runner, travel booking or shopping sites — while answering a user., stop conditionstop condition, n.: The rule that tells an AI agent when to stop working — because the task is done, a time or cost limit has been reached, or something has gone wrong.