§03 · Tools & Environment

Hooks

Also called Lifecycle hooks · Pre-tool hook · Post-tool hook

Commands you configure the harness to run at fixed moments, such as before or after a tool call, regardless of what the model wants.

Hooks are commands you configure the harness to run at fixed points in the loop: before a tool call, after one, when the session starts or ends, when the agent is about to stop, or when it needs your attention. They are plain shell commands or scripts, and they run whether or not the model would have chosen to. A hook can also block: a pre-tool hook that exits with an error prevents the call from happening at all.

The reason hooks exist is that instructions are advisory. You can write 'always run the formatter after editing' in AGENTS.md and the agent will do it most of the time; on a long turn deep in the dumb zone, it will forget. A post-edit hook that runs Prettier never forgets. The same goes for guardrails: a hook that rejects any command containing rm -rf or a push to main is a rule the agent literally cannot talk its way past.

Use hooks for the things that must happen every time and are cheap to check mechanically: formatting, linting, running the affected tests, blocking dangerous commands, logging every call for audit. Keep them fast; a slow hook taxes every tool call. And keep the nuanced judgment in instructions and skills where the model can weigh it, because a hook has no judgment at all, which is exactly its value.

In the tools
  • Claude CodeHooks are configured in settings under events such as PreToolUse, PostToolUse, Stop and Notification, with matchers for specific tools.
  • Most toolsWhere a harness has no hook system, a git pre-commit hook or a CI check gives you the after-the-fact half of the same protection.
In conversation

It committed unformatted code again, even though CLAUDE.md says to format first.

Stop asking. Add a post-edit hook that runs the formatter on the changed file, and the question goes away.

And a pre-commit hook that fails if the tests don't pass?

Related terms
Learn it in the school
Words are the easy part

Course 01 puts every one of these terms to work: you install Claude Code, run the loop, and ship a real project — permission modes, compaction, hooks and all.

Start Course 01 →