Skip to content

Hooks and Extensibility in Agent Harnesses

Using hooks to run your own code at points in the agent loop: validating actions, formatting code and enforcing policy.

Editorial team 1 min read

Hooks let you run custom code at defined points in an agent's lifecycle, adding behaviour without changing the harness itself.

Common Hook Points

  • Before a tool call runs.
  • After a tool call completes.
  • When the user submits a prompt.
  • When a session starts or ends.
  • When the agent stops.

Uses

  • Policy enforcement: block commands matching dangerous patterns, or edits to protected files.
  • Automatic formatting: run a formatter after every file edit.
  • Validation: run tests or linters and feed results back.
  • Logging and audit: record actions to an external system.
  • Context injection: add up-to-date information at session start.
  • Notifications: alert people when an agent needs attention.

Why Hooks Beat Prompt Instructions

Instructions in prompts can be forgotten or ignored. Hooks run deterministically every time. Use them for rules that must always hold.

Care Required

Hooks run with your system's permissions. Review them like any other code, keep them fast, and handle their errors so they don't break the agent.

More in Agent harnesses

All Agent harnesses guides →
Agent harnesses Guide · 2 min

What Is an Agent Harness?

The software around a language model that turns it into an agent: the loop, tools, context, permissions and memory.

Agent harnesses 2 min read 27 Sep 2025

Agent harnesses Guide · 1 min

The Agent Loop Explained

The core cycle every agent runs: think, call a tool, observe the result, repeat — and how the loop knows when to stop.

Agent harnesses 1 min read 26 Sep 2025

Agent harnesses Guide · 1 min

Designing Tools for AI Agents

How to write tools agents use well: clear names, precise descriptions, sensible inputs and informative outputs.

Agent harnesses 1 min read 25 Sep 2025

Agent harnesses Guide · 1 min

Context Management in Agent Harnesses

How agents stay effective over long tasks: what to keep in context, what to summarise, and what to store outside.

Agent harnesses 1 min read 24 Sep 2025