PostToolUse agent hook fails with "Messages are required for agent hooks. This is a bug."

Resolved 💬 3 comments Opened Apr 23, 2026 by nicksalvemini-edb Closed Apr 23, 2026

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

View original on GitHub ↗

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