Hooks (agent hooks)

Also called hooks, lifecycle hooks, PreToolUse

Scripts a coding agent runs automatically at set points, such as before a tool runs or after a file is edited, every time.

An instructions file asks; a hook acts. The agent weighs a line like "always run the formatter" alongside everything else it's doing, and sometimes skips it. A hook is a script the agent itself triggers at a fixed moment, so it runs whether the model remembers or not.

The 2 common uses are cleaning up after an edit (formatting, linting the changed file) and checking before an action (blocking writes to protected files, refusing a risky command). When a hook blocks something, it can pass its reason back, so the agent changes course instead of retrying.

For example

A hook checks every edit's path and blocks anything under legacy/migrations/, telling the agent why, so it looks for another way.

WITH PLUS

Put it to use

Where you'll meet hooks (agent hooks) in ChatGPT, Gemini and Claude, how to use it there, and the mix-up most people make.

Daily Bytes Plus is in the Android app.