Agent frontmatter hooks
Fire in a fork (skill hooks don't); portable middleware.
Agent frontmatter hooks are middleware directives scoped to an agent definition that fire in forked execution contexts, whereas skill-level hooks fire only in the main thread.
How They Work
Agent hooks are defined in .claude/agents/{name}.md frontmatter under a hooks key. Each hook specifies a trigger event (currently PreToolUse, PostToolUse, Stop), a tool matcher, and a command to execute. When an agent runs in any context, including forked subagent runs, its hooks traverse with the agent and fire according to the matched conditions.
hooks:
PostToolUse:
- matcher: "Read"
hooks:
- type: command
command: "echo 'AGENT-HOOK-FIRED' >> /tmp/agent-hook-log.txt"
The Critical Distinction: Forks
A runtime test (2026-01-07) compared hook fire behaviour across skill-level and agent-level definitions. When a skill invoked an agent in a forked context, skill hooks did not fire, but agent hooks did. This creates a hard rule: agent hooks are portable middleware; skill hooks are main-thread-only middleware.
The test defined hooked-researcher with a PostToolUse hook on Read, created a skill that used this agent with context: fork, and verified the hook fired by observing a log file written during forked execution.
Why It Matters
Forked workflows need access to instrumentation. Logging, audit trails, validation before tool calls, and side effects that must run regardless of execution context now have a natural primitive. Agent hooks solve a scope problem: you cannot attach main-thread-only middleware to code that runs elsewhere.
Caveats
- Hooks defined at skill level do not cross fork boundaries
- Hook fire depends on tool matcher precision; a
Readmatcher fires only onReadtools - Command hooks execute synchronously; the result does not block the tool call
- commit55c9d8a ↗
primitive_9e1c19497b68554e51be7c11ed255199b87705613b1e2fd064d57fa75a6b679d2856ceafad6b1daa8f982493871b6dd5e718eb273e90be8913543d3533f1d518edbdb9bcc8ef0978f4ad5d97bad7a62c58609a50fefdabc48e59c152f0382b46099d4e8454c5b50cc33bcf1cad99506Signed with an ed25519 key held off the repo. Anyone can verify against the published public key; nobody without the secret key can forge it. Click verify: it recomputes the signature in your browser. The signature proves integrity and authorship of this exact content — not a third-party timestamp or that the underlying claim is objectively true. signedAt is when the @f3/attest pipeline ran, not when the work happened; the evidence refs carry the source dates.
- instance-of Event Interposition Class
- introduces (in) Claude Code 2.1.0 (Night Zero) Release
- verifies (in) Agent frontmatter hooks — runtime test Test