~/blog/tag/hooks
Hooks
The difference between asking the agent and making it so. What a hook is, when it beats a prompt, and where it bites back.
What I write about here
A hook is a script the harness runs at a fixed point in the agent's loop. Before a tool call, after an edit, when a session starts, when the model tries to stop. It runs whether or not the model was paying attention, and its exit code can refuse the thing that was about to happen.
That last part is the whole reason the tag exists. Almost everything else you can put in front of an agent is advice. A CLAUDE.md file is advice. A skill is advice with better packaging. A carefully worded instruction is advice you spent longer on. All of it is weighed by the model against everything else in the context, and any of it can lose.
A hook does not get weighed. This is the cheapest correctness win available in an agent setup, and it is the one people reach for last, usually after the third time the same rule got ignored on a long session.
The posts here cover both halves. What hooks are good for: enforcing a format, blocking a path, refusing a commit, keeping a check honest when the model would rather move on. And where they bite: a Stop hook that always blocks is an infinite loop, hooks over a certain size are silently skipped on some hosts, and a hook that runs on every tool call is a tax you pay all day.
If you are working out which mechanism fits a problem, the Agentic coding guide puts hooks next to skills, subagents and slash commands. What a hook may actually stop is a permissions question.
best entry points
- Claude Code hooks: deterministic control over AI workflows
The reference piece. Every event, what fires when, and the exit codes that decide whether the agent gets to continue.
- Stop asking your agent nicely
The argument for reaching for one at all. Instructions in a prompt are suggestions the model can drop; a hook is not.
- Skill, subagent, hook, or slash command? Pick the right one
The same task built four ways. Read this if you are not yet sure a hook is the right mechanism for what you want.
Your Claude Code session has no clock
Claude Code shows no timestamps and no elapsed time, so nobody can say how long a turn actually took. Here is a plugin that adds both, and what the numbers turn out to be worth.
read →Skill, subagent, hook, or slash command? Pick the right one
Claude Code now gives you seven ways to steer it, and most people reach for the wrong one. The same task built four ways, and a decision tree you can actually follow.
The agent is just a loop
An agent is a loop around a model with tools. If you use Claude Code you are already inside one, and you can drive it with hooks and slash commands, no SDK required.
Stop asking your agent nicely
Your CLAUDE.md is a suggestion. Hooks are a wall. ADRs and custom lint rules are the missing layer between them, the difference between hoping your agent obeys and making it impossible to disobey.
Claude Code hooks: deterministic control over AI workflows
While claude.md instructions are treated as suggestions, Hooks provide deterministic guarantees. Learn how to use pre- and post-tool hooks to enforce formatting, block dangerous commands, and standardize your team's workflow.