agent_hooks

agent_hooks is an agent for coding agents from the-teacher/active_harness. It costs 0 tokens per session (833 once invoked), scanned A, original, MIT.

A system for running code before and after agent actions, or when an agent retries. Hooks are small pieces of code attached to named events.

In plain words
What is it for?
It helps normalize input, change input or context before a request, inspect successful results, and respond to retry errors.
Why use it?
It lets developers add setup, input-changing, result-handling, and retry behaviour in one place without modifying the main call flow.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/the-teacher/active_harness/agent_hooks
Clone the repo
git clone --depth 1 https://github.com/the-teacher/active_harness

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for agent_hooks

README.md
[![agentmods](https://agentmods.dev/badge/agents/the-teacher/active_harness/agent_hooks.svg)](https://agentmods.dev/agents/the-teacher/active_harness/agent_hooks)
Your own site
<a href="https://agentmods.dev/agents/the-teacher/active_harness/agent_hooks"><img src="https://agentmods.dev/badge/agents/the-teacher/active_harness/agent_hooks.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 833 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00833
Opus 5 $0.00000 $0.00417
Sonnet 5 $0.00000 $0.00167
Haiku 4.5 $0.00000 $0.00083

Measured 3d ago against content hash ee4a0f8fa74e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

agent_hooks scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/agents/agent_hooks.md · 65 lines

How it starts

The opening of the file, as written. The whole thing — 65 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Agent Hooks

All hooks are registered with on, before, after, or callback at the class or instance level.

class MyAgent < ActiveHarness::Agent
  on       :setup          do ... end
  before   :call           do ... end
  after    :call           do |result| ... end
  callback :retry          do |entry, error| ... end
end

Hooks are only registered at the class level. There is no instance-level hook API — agent.on(...) does not exist on an Agent instance and raises NoMethodError. Multiple class-level registrations for the same event accumulate (they don't override each other); all fire in the order they were registered, including hooks contributed by included modules.


Events

Event Alias Block arguments When it fires
:setup callback :setup Before anything else. Runs once per call. Use to normalize @input.
:before_call before :call After setup, before the first HTTP request is made. Use to modify @input or @context.
:after_call after :call result After a successful response. result is a Result object.
:retry callback :retry entry, error After each failed model attempt before trying the next fallback. entry is the model hash {provider:, model:, ...}, error is the exception.
:failure callback :failure attempts After all models in the chain have failed. attempts is an array of flat hashes {provider:, model:, error:, error_code:, execution_time:} (one per attempt).
:before_system_prompt before :system_prompt Before the prompt class call is invoked. Use to mutate @context before the prompt reads it.
:after_system_prompt after :system_prompt prompt After the prompt string is built. Return value is ignored — use before_system_prompt to mutate context, or a prompt class for full control.
:before_parse before :parse raw Before the raw LLM string is parsed (e.g. JSON). Transform hook — the block's return value replaces raw.
:after_parse after :parse parsed After successful parsing. Transform hook — the block's return value replaces parsed.
:parse_error callback :parse_error raw, error When parsing fails. The block's return value is used as the fallback parsed value.

Read the full file on GitHub · 65 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 65 lines · 0 tokens per session scan A ee4a0f8fa74e

Subscribe to this mod's changes

agent_hooks is an agent published in the GitHub repository the-teacher/active_harness (89 stars, last pushed 24d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 833 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.