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

  1. Have a PostToolUse hook configured in settings.json
  2. Spawn a subagent using the Agent tool
  3. The subagent uses the Write or Edit tool
  4. 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

View original on GitHub ↗

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