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

Resolved 💬 3 comments Opened Apr 17, 2026 by de3z1e Closed Apr 21, 2026

Summary

A PreToolUse agent hook configured per the documented schema (with a prompt field) fails at runtime with:

Failed to run: Messages are required for agent hooks. This is a bug.

The error message text itself flags this as a bug in Claude Code's runtime.

Reproduction

  1. Configure the following in ~/.claude/settings.json:

``json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "agent",
"prompt": "Audit the staged git diff before this commit...",
"if": "Bash(git commit:*)",
"timeout": 120,
"statusMessage": "Auditing staged diff..."
}
]
}
]
}
}
``

  1. Open \/hooks\ (or restart) to reload the config.
  2. Ask Claude to run a \git commit\.
  3. The hook fires (status message appears) but errors immediately with \Failed to run: Messages are required for agent hooks. This is a bug.\

Expected

The agent hook should spawn with the configured \prompt\ and audit the staged diff.

Observations

  • The settings.json JSON schema documents \prompt\ as \required\ for \type: \"agent\"\ hooks — no \messages\ property exists in the schema.
  • The runtime error \"This is a bug\" suggests the runtime expects a different shape than what the schema validates.
  • \type: \"command\"\ hooks work normally; only \type: \"agent\"\ is affected.

Environment

  • Claude Code 2.1.112
  • macOS 25.4.0 (Darwin)
  • Model: Opus 4.7

View original on GitHub ↗

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