[BUG]
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Agent-type hooks in PreToolUse fail to execute with the error: Failed to run: Messages are required for agent hooks. This is a bug.
When configuring an agent hook to run before Bash commands (specifically to check documentation before git push), the hook is matched correctly but fails to execute because it doesn't receive the required messages/context.
What Should Happen?
Agent hooks configured in PreToolUse should receive the conversation context and execute successfully, allowing the agent to analyze the command and return {ok: true} or {ok: false, reason: "..."}.
Error Messages/Logs
2026-02-02T20:00:39.160Z [DEBUG] Getting matching hook commands for PreToolUse with query: Bash
2026-02-02T20:00:39.160Z [DEBUG] Found 1 hook matchers in settings
2026-02-02T20:00:39.160Z [DEBUG] Matched 1 unique hooks for query "Bash" (1 before deduplication)
2026-02-02T20:00:39.161Z [DEBUG] Hook PreToolUse:Bash (PreToolUse) error:
Failed to run: Messages are required for agent hooks. This is a bug.
Steps to Reproduce
- Create .claude/settings.json with an agent hook:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "agent",
"prompt": "Check if this is a git push command. If not, return {\"ok\": true}. If it is, verify documentation is up to date.",
"timeout": 90
}
]
}
]
}
}
- Run any Bash command through Claude Code (e.g.,
git push origin master) - Observe the hook error in debug logs
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.29
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
The hook matcher works correctly (logs show it matched 1 hook for "Bash"), but the agent execution fails because messages aren't being passed to the agent context. Command-type hooks may work as a workaround, but agent-type hooks appear fundamentally broken for PreToolUse.
8 Comments
We are running into the same issue, but on
PostToolUse.Version: 2.1.37, macOS, Anthropic API
Error:
Failed to run: Messages are required for agent hooks. This is a bug.Also hitting this with
PermissionRequesthooks usingtype: "agent".Use case: I have an Opus-based "Permissions Gatekeeper" agent configured to evaluate Bash commands for safety — classifying them as SAFE (auto-approve) or RISKY (auto-block) before execution. This would allow running in
acceptEditsmode while still catching destructive commands likerm -rf,git reset --hard,git push --forceto main,DROP TABLE, etc.Configuration (in
~/.claude/settings.json):What happens: The hook is completely bypassed — the standard permission dialog appears instead of the agent evaluation. The
statusMessagenever shows.Key observations:
type: "command"hooks on other events (Stop,SessionStart) work finetype: "agent"hooks appear brokenOriginally filed as #23370 (auto-closed as duplicate of this issue).
Root Cause Identified: Settings serialization drops
promptfieldAfter further investigation with backup history analysis, I've identified the root cause of this bug:
Claude Code silently drops the
promptfield fromtype: "agent"hooks when re-serializingsettings.json.Reproduction Steps
PermissionRequesthook withtype: "agent"and apromptfield to~/.claude/settings.jsonpermissions.allow)settings.json— thepromptfield is gone, while all other fields (type,timeout,model,statusMessage) are preservedEvidence from Backup History
I have automated daily backups of
settings.json. Timeline:| Date |
promptfield | What changed ||------|----------------|--------------|
| Feb 4 | ✅ Present | Initial setup |
| Feb 8 | ❌ Gone | Permissions list modified in same write |
| Feb 9 | ✅ Present | Manually restored |
| Feb 11-12 | ✅ Present | No settings changes |
| Feb 15 | ❌ Gone |
skipDangerousModePermissionPromptadded + permissions cleaned |Diagnostic Output
When the
promptfield is missing, Claude Code shows this validation error on startup:Impact
This explains why:
Expected Behavior
Claude Code should round-trip all hook handler fields when re-serializing
settings.json, including thepromptfield.---
Version: Claude Code 2.1.42 (native install), macOS
I found that when Claude Code needs to make changes to
settings.json, such as add permission mode, it drops thepromptfield.But that is not the only issue. I manually added all the settings required into
settings.jsonso that re-serialization does not get triggered andpromptis preserved. Butagenttype hooks do not passmessagesto the agent hook runner and it silently fails.Also facing this
This issue was fixed as of version 2.1.118.
Still reproducing on Claude Code 2.1.111 (macOS 25.2.0), 3 months after this was closed as stale.
Error (from transcript
hook_non_blocking_errorattachment):durationMs: 1confirms it fails at config-dispatch time, before any model call.Minimal repro in
.claude/settings.local.json:Then run any
git commit. The agent hook crashes instantly while the siblingtype: commandhook fires fine.Contradiction: the settings validator requires
prompt(string) and rejectsmessageswithadditionalProperties: false. The runtime rejects what the validator accepts — there's no schema that satisfies both.~12 new duplicates have been filed and closed since this issue went stale. Worth reopening.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.