PreToolUse agent hook fails with "Messages are required for agent hooks. This is a bug."
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
- 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..."
}
]
}
]
}
}
- Open \
/hooks\(or restart) to reload the config. - Ask Claude to run a \
git commit\. - 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
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗