[BUG] Agent frontmatter hooks (PreToolUse, PostToolUse, Stop) not executing

Resolved 💬 2 comments Opened Jan 19, 2026 by shayangd Closed Jan 19, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Hooks defined in agent frontmatter (PreToolUse, PostToolUse, Stop) are not being executed when the agent runs. The hooks are defined according to the documented syntax but the commands are never triggered.

The changelog for v2.1.0 states: "Added hooks support to agent frontmatter, allowing agents to define PreToolUse, PostToolUse, and Stop hooks scoped to the agent's lifecycle"

However, when an agent with frontmatter hooks is invoked via the Task tool, the hooks do not execute. Only the main session hooks (SubagentStart, SubagentStop from settings.json) fire - the agent's own frontmatter hooks are completely ignored.

What Should Happen?

When an agent with frontmatter hooks is invoked, the hooks should execute:

  • PreToolUse hook should run before each tool call within the agent
  • - PostToolUse hook should run after each tool call within the agent
  • - - Stop hook should run when the agent completes

The hook commands should receive the standard hook data via stdin (hook_event_name, tool_name, tool_input, etc.)

Error Messages/Logs

No error messages - the hooks simply do not execute. 

Hook log (hooks-log.jsonl) shows only main session hooks firing:
- SubagentStart (from settings.json)
- SubagentStop (from settings.json)

No log entries from agent frontmatter hooks appear, indicating they are never triggered.

Steps to Reproduce

  1. Create an agent file at .claude/agents/test-agent.md:
---
name: test-agent
description: Test agent with hooks
hooks:
  PreToolUse:
    - matcher: ".*"
    -       hooks:
    -         - type: command
    -           command: echo "PreToolUse hook fired" >> /tmp/agent-hooks.log
    -           timeout: 5000
    -   PostToolUse:
    -     - matcher: ".*"
    -       hooks:
    -         - type: command
    -           command: echo "PostToolUse hook fired" >> /tmp/agent-hooks.log
    -           timeout: 5000
    -   Stop:
    -     - hooks:
    -         - type: command
    -           command: echo "Stop hook fired" >> /tmp/agent-hooks.log
    -           timeout: 5000
    - ---
You are a test agent. Use WebSearch to find any information.
  1. Invoke the agent: @test-agent search for weather
  2. Check /tmp/agent-hooks.log - file is empty or doesn't exist
  3. Expected: The log file should contain entries for PreToolUse, PostToolUse, and Stop

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.12 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

  • Documentation at https://code.claude.com/docs/en/hooks confirms agent frontmatter hooks should work
  • - CHANGELOG for v2.1.0 explicitly states this feature was added
  • - - Main session hooks (SubagentStart, SubagentStop) from settings.json work correctly
  • - - - Only agent frontmatter-defined hooks fail to execute
  • - - - - Tested with both simple and matcher-based hook configurations

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗