claude-code - 💡(How to fix) Fix PostToolUse hooks fail in agent context with 'Messages are required for agent hooks' [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48779Fetched 2026-04-16 06:51:12
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

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.

Root Cause

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.

Code Example

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.
RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

The PostToolUse hook error in agent/subagent contexts may be resolvable by modifying the hook configuration to handle agent contexts or waiting for a fix, as the error message indicates it's a known bug.

Guidance

  • Verify that the PostToolUse hook is correctly configured in settings.json to handle messages for agent hooks, if possible.
  • Check if there are any open issues or pull requests related to this bug in the Claude Code CLI repository, as the error message suggests it's a known issue.
  • Consider reaching out to the developers or community of Claude Code CLI for a potential workaround or fix, given the explicit mention of "This is a bug" in the error message.
  • If the hook is not critical for the subagent's functionality, consider silently skipping it in agent contexts as a temporary workaround, aligning with the expected behavior.

Example

No code snippet is provided due to the lack of specific implementation details in the issue.

Notes

The provided error message clearly states that the issue is a bug, suggesting that a fix might be necessary from the developers of the Claude Code CLI. The guidance provided is based on the information given and aims to help mitigate or understand the issue rather than providing a definitive fix.

Recommendation

Apply workaround: Given the error message indicates a known bug, applying a workaround, such as modifying the hook configuration or skipping the hook in agent contexts if possible, seems to be the most viable immediate solution until a fixed version is available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix PostToolUse hooks fail in agent context with 'Messages are required for agent hooks' [1 comments, 2 participants]