PostToolUse hooks fail in agent context with 'Messages are required for agent hooks'
Resolved 💬 3 comments Opened Apr 15, 2026 by chris-sloan Closed Apr 19, 2026
Description
PostToolUse hooks throw an error when triggered from within an agent/subagent context (spawned via the Agent tool). The hook fails to run but the underlying tool call succeeds.
Error message
PostToolUse:Write hook error
Failed to run: Messages are required for agent hooks. This is a bug.
PostToolUse:Edit hook error
Failed to run: Messages are required for agent hooks. This is a bug.
Steps to reproduce
- Have a
PostToolUsehook configured insettings.json - Spawn a subagent using the
Agenttool - The subagent uses the
WriteorEdittool - Hook errors appear in the UI
Expected behaviour
PostToolUse hooks should either run correctly in agent contexts, or be silently skipped. The error message itself says "This is a bug."
Actual behaviour
The hook fails with the above error. The tool call itself succeeds — only the hook execution fails.
Environment
- Claude Code CLI
- macOS Darwin 25.3.0
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗