claude-code - 💡(How to fix) Fix [BUG] Agent hook on PreToolUse fails 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#47838Fetched 2026-04-15 06:40:54
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Error Message

Error: Messages are required for agent hooks. This is a bug.

Code Example

Error: `Messages are required for agent hooks. This is a bug.`

---

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "agent",
            "if": "Bash(git commit:*)",
            "timeout": 120,
            "model": "claude-sonnet-4-6",
            "statusMessage": "Checking spec files...",
            "prompt": "Run git diff --cached --name-only and report what files are staged."
          }
        ]
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

An agent type hook configured on PreToolUse fails immediately with an error.

What Should Happen?

The agent hook runs and executes the prompt with tool access.

Error Messages/Logs

Error: `Messages are required for agent hooks. This is a bug.`

Steps to Reproduce

Add this to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "agent",
            "if": "Bash(git commit:*)",
            "timeout": 120,
            "model": "claude-sonnet-4-6",
            "statusMessage": "Checking spec files...",
            "prompt": "Run git diff --cached --name-only and report what files are staged."
          }
        ]
      }
    ]
  }
}

Then trigger a git commit via Claude Code. The hook fires but immediately errors.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.107

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

No response

extent analysis

TL;DR

The agent hook error is likely due to a missing messages field in the hook configuration, which is required for agent hooks.

Guidance

  • Verify that the messages field is present in the hook configuration, as indicated by the error message.
  • Check the documentation for the minimum required fields for an agent hook configuration.
  • Consider adding a messages field to the hook configuration, even if it's just an empty array, to see if it resolves the issue.
  • Review the hook configuration for any other potential issues or missing fields.

Example

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "agent",
            "if": "Bash(git commit:*)",
            "timeout": 120,
            "model": "claude-sonnet-4-6",
            "statusMessage": "Checking spec files...",
            "prompt": "Run git diff --cached --name-only and report what files are staged.",
            "messages": []  // Add this field to the configuration
          }
        ]
      }
    ]
  }
}

Notes

The error message explicitly states that messages are required for agent hooks, suggesting that this is the root cause of the issue. However, without further documentation or context, it's unclear what the messages field should contain or how it should be configured.

Recommendation

Apply workaround: Add a messages field to the hook configuration, as shown in the example above, to see if it resolves the issue. This is a minimal change that can help determine if the error is indeed caused by the missing field.

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 [BUG] Agent hook on PreToolUse fails with "Messages are required for agent hooks" [1 comments, 2 participants]