AI GLOSSARY · CODING AGENTS AND CODING TOOLS
Agent hooks
Definition
Agent hooks are user-defined handlers that an AI agent's harness runs automatically at set points in its work, such as before a tool call. In Claude Code they can be shell commands, HTTP endpoints, MCP tool calls, prompts or subagents.
Also called: Claude Code hooks, AI agent hooks, coding agent hooks.
In plain language
Hooks are small automatic checks you attach to an AI coding tool, so something runs every time a certain moment arrives, for example before the agent runs a shell command or after it edits a file. Think of a smoke alarm rather than a note on the fridge: it fires whether or not anyone remembers it. A hook can run a formatter or stop a dangerous command. The limits are that a hook only helps if it is registered and written correctly, and that it is code, so read any hook you did not write. Claude Code's documentation also says some hook conditions are best-effort and points to the permission system for hard rules.
Technical definition
In Claude Code a hook configuration has three levels: an event, a matcher group that filters when it fires, and one or more handlers. Events include SessionStart, UserPromptSubmit, PreToolUse, PostToolUse and Stop. A handler is one of five types: command, http, mcp_tool, prompt or agent. A command hook receives JSON about the event on stdin. Exit code 0 means success, exit code 2 is a blocking error whose effect depends on the event, such as blocking the tool call on PreToolUse, and any other code is a non-blocking error. Hooks are registered in settings files, plugin hooks/hooks.json or skill and subagent frontmatter.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Guide · Illustrative, not executed
Claude Code Hooks: Setup, One Example, and Failure Modes
- What you see
- How to add a Claude Code hook in settings.json, read its JSON input, block a tool call with exit code 2, and debug a hook that does not fire.
- Why it exercises the concept
- It walks through the definition above end to end: an event, a matcher, a handler and the exit code that blocks.
Skill by Skill Almanac · Illustrative, not executed
agent-hooks-authoring 47/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Write, install, test and debug coding-agent hooks that are proven by firing them with sample input.
- Why it exercises the concept
- A hook is code that runs without you watching, so proving it with sample input before relying on it is the core habit.
Skill by Skill Almanac · Illustrative, not executed
coding-agent-guardrails 60/100 · grade CScored · Method v0.2 · How we score
- What you see
- A pre-action checklist for coding agents plus a read-only audit of a repo's guardrail setup.
- Why it exercises the concept
- Hooks are one way to enforce a guardrail outside the model. The skill audits what a repository has set up.
Coding tool · Illustrative, not executed
Claude Code
- What to try
/hooks- What you see
- Claude Code's commands reference lists /hooks as the command that views hook configurations.
- Why it exercises the concept
- It is the quick check that a hook you added is registered where you expect.
How it shows up when you use agents
Hooks sit in the agent harness, the program around the model, not in the model. You add them to a settings file, and the harness runs them at the event you chose. Because the harness runs them, they do not depend on the model remembering an instruction. That makes them a way to build a guardrail, such as stopping a command before it runs.
What breaks when hooks are misunderstood. The Claude Code documentation says that for a policy-enforcing hook you should use exit code 2, since exit code 1 is a non-blocking error and the action proceeds. People who write exit 1 believe they have a block and do not. Another failure is a hook that was never registered, so nothing fires.
Next action: add one hook for one event, then prove it. Ask the agent to run something that should match, confirm the block or the effect, then run something harmless and confirm it passes. The Claude Code hooks explained guide gives the steps, and /hooks shows what is registered. Hooks can also arrive inside an agent plugin, so check plugins for them.
Common confusions
- Hook versus instruction file. An instruction file asks the model to behave. A hook is code the harness runs at an event.
- Hook versus permission rule. The documentation says a hook's
ifcondition is best-effort and to use the permission system for hard allow or deny rules. - Pre versus post. A PreToolUse hook can block the call. For PostToolUse the documentation says the tool already ran, so stderr is shown to Claude instead.
- Agent hooks versus Git hooks. Git hooks run on Git events. Agent hooks run on the agent's own lifecycle events.
Related terms
Terms that mention Agent hooks
3 terms mention this one
Guides that mention Agent hooks
More in Coding agents and coding tools
Sources
- Hooks reference, Anthropic (Claude Code Docs) (accessed 2026-11-24)
- Commands, Anthropic (Claude Code Docs) (accessed 2026-11-24)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-24. Wikipedia is never the only source.
Review record
Last verified
Drafted by claude-sonnet-5-5; sources and example targets checked by claude-haiku-5-5 source check; claude-sonnet-5-5 editor pass on 2026-11-24. Last verified .
This entry is still in review, so it is not listed in search engines yet.
Change log (2)
- : First version.
- : Verifier pass: applied verifier corrections to unsourced or over-stated claims.