claude-code - 💡(How to fix) Fix PostToolUse agent hook fails with "Messages are required for agent hooks. This is a bug." [2 comments, 3 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#52590Fetched 2026-04-24 06:03:04
View on GitHub
Comments
2
Participants
3
Timeline
7
Reactions
0
Timeline (top)
labeled ×4commented ×2closed ×1

A PostToolUse hook with "type": "agent" fails to run. The if matcher fires correctly, but the agent runner errors out before the subagent starts, with a non-blocking stderr message that itself says "This is a bug."

Error Message

hookName: PostToolUse:Bash
hookEvent: PostToolUse
stderr:   Failed to run: Messages are required for agent hooks. This is a bug.
stdout:   (empty)
exitCode: non-zero

Root Cause

A PostToolUse hook with "type": "agent" fails to run. The if matcher fires correctly, but the agent runner errors out before the subagent starts, with a non-blocking stderr message that itself says "This is a bug."

Fix Action

Fix / Workaround

Per the hooks docs, "prompt" is the documented field for agent hooks. The stderr reference to "Messages" suggests the runtime is looking for a different field name than the schema documents, or the prompt string isn't being wrapped into the messages array before dispatch.

Code Example

hookName: PostToolUse:Bash
hookEvent: PostToolUse
stderr:   Failed to run: Messages are required for agent hooks. This is a bug.
stdout:   (empty)
exitCode: non-zero

---

"hooks": {
  "PostToolUse": [
    {
      "matcher": "Bash",
      "hooks": [
        {
          "type": "agent",
          "if": "Bash(gh pr create*)",
          "prompt": "A pull request was just created. Extract the PR URL from the command's stdout and post it to Slack via the slack_send_message MCP tool.",
          "timeout": 90,
          "statusMessage": "Posting PR to Slack"
        }
      ]
    }
  ]
}
RAW_BUFFERClick to expand / collapse

Summary

A PostToolUse hook with "type": "agent" fails to run. The if matcher fires correctly, but the agent runner errors out before the subagent starts, with a non-blocking stderr message that itself says "This is a bug."

Error

hookName: PostToolUse:Bash
hookEvent: PostToolUse
stderr:   Failed to run: Messages are required for agent hooks. This is a bug.
stdout:   (empty)
exitCode: non-zero

Reproduction

Add the following to ~/.claude/settings.json and run any matching Bash command (e.g. gh pr create ...):

"hooks": {
  "PostToolUse": [
    {
      "matcher": "Bash",
      "hooks": [
        {
          "type": "agent",
          "if": "Bash(gh pr create*)",
          "prompt": "A pull request was just created. Extract the PR URL from the command's stdout and post it to Slack via the slack_send_message MCP tool.",
          "timeout": 90,
          "statusMessage": "Posting PR to Slack"
        }
      ]
    }
  ]
}

Per the hooks docs, "prompt" is the documented field for agent hooks. The stderr reference to "Messages" suggests the runtime is looking for a different field name than the schema documents, or the prompt string isn't being wrapped into the messages array before dispatch.

Environment

  • Claude Code: 2.1.94
  • Platform: macOS (Darwin 25.4.0)
  • Shell: zsh

extent analysis

TL;DR

The PostToolUse hook with an agent type may require a "messages" field instead of or in addition to the "prompt" field to run successfully.

Guidance

  • Verify the documentation for agent hooks to confirm the required fields, as there might be a discrepancy between the documented "prompt" field and the runtime error referencing "messages".
  • Check if adding a "messages" field to the hook configuration resolves the issue, potentially wrapping the "prompt" string into an array.
  • Test the hook with both "prompt" and "messages" fields to see if one or both are necessary for successful execution.
  • Consider reporting the discrepancy between the documentation and the runtime error as a bug to ensure clarity for future users.

Example

"hooks": {
  "PostToolUse": [
    {
      "matcher": "Bash",
      "hooks": [
        {
          "type": "agent",
          "if": "Bash(gh pr create*)",
          "prompt": "A pull request was just created. Extract the PR URL from the command's stdout and post it to Slack via the slack_send_message MCP tool.",
          "messages": ["A pull request was just created. Extract the PR URL from the command's stdout and post it to Slack via the slack_send_message MCP tool."],
          "timeout": 90,
          "statusMessage": "Posting PR to Slack"
        }
      ]
    }
  ]
}

Notes

The solution assumes that the error message indicating a requirement for "messages" is accurate and that the documentation might be outdated or incorrect regarding the "prompt" field for agent hooks.

Recommendation

Apply workaround: Add a "messages" field to the hook configuration, as shown in the example, to potentially resolve the issue until the documentation discrepancy is addressed.

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