claude-code - 💡(How to fix) Fix [BUG] `type: "agent"` hooks broken on PreToolUse— "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#46926Fetched 2026-04-12 13:29:32
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Timeline (top)
labeled ×5closed ×1commented ×1renamed ×1

Error Message

Error Messages/Logs

PreToolUse:Edit hook error PreToolUse:Write hook error The error fires on every Edit and Write tool call. The edit/write still goes through — the agent hook silently never executes.

Root Cause

The root cause is that the PreToolUse call sites in the hook executor do not pass the messages (conversation history) parameter, which agent hooks require to spawn a sub-agent. The assertion fails and the hook is skipped.

Code Example

PreToolUse:Edit hook error
Failed to run: Messages are required for agent hooks. This is a bug.



PreToolUse:Write hook error
Failed to run: Messages are required for agent hooks. This is a bug.


The error fires on every `Edit` and `Write` tool call. The edit/write still goes through — the agent hook silently never executes.

---

{
     "hooks": {
       "PreToolUse": [
         {
           "matcher": "Edit|Write",
           "hooks": [
             {
               "type": "agent",
               "prompt": "Review this edit. The hook input JSON is in $ARGUMENTS.",
               "timeout": 300
             }
           ]
         }
       ]
     }
   }
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?

type: "agent" hooks on PreToolUse immediately throw "Failed to run: Messages are required for agent hooks. This is a bug." and never execute. The sub-agent is never spawned, so no review happens. The edit/write proceeds as if the hook didn't exist.

The root cause is that the PreToolUse call sites in the hook executor do not pass the messages (conversation history) parameter, which agent hooks require to spawn a sub-agent. The assertion fails and the hook is skipped.

What Should Happen?

type: "agent" hooks on PreToolUse should spawn a sub-agent that reviews the tool call and returns a JSON decision ({"ok": true} or {"ok": false, "reason": "..."}), as documented at https://code.claude.com/docs/en/hooks. The edit/write should only proceed after the agent hook completes successfully.

Error Messages/Logs

PreToolUse:Edit hook error
Failed to run: Messages are required for agent hooks. This is a bug.



PreToolUse:Write hook error
Failed to run: Messages are required for agent hooks. This is a bug.


The error fires on every `Edit` and `Write` tool call. The edit/write still goes through — the agent hook silently never executes.

Steps to Reproduce

  1. Add this to any project's .claude/settings.json:
    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Edit|Write",
            "hooks": [
              {
                "type": "agent",
                "prompt": "Review this edit. The hook input JSON is in $ARGUMENTS.",
                "timeout": 300
              }
            ]
          }
        ]
      }
    }
  2. Start a Claude Code session in that project
  3. Ask Claude to edit or create any file (e.g. "add a docstring to main.py")
  4. The hook fires and immediately fails with: Failed to run: Messages are required for agent hooks. This is a bug.
  5. The edit proceeds anyway — the agent hook never ran

Reproduces on every Edit and Write, regardless of file type (.py, .csv, .md, etc.).

type: "agent" hooks may have never worked on PreToolUse/PostToolUse. The internal hook development skill guide (plugins/plugin-dev/skills/hook-development/SKILL.md) only documents prompt and command types, suggesting agent was added later and may not have been fully wired up.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.104

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

Passing the messages parameter to PreToolUse call sites in the hook executor is likely necessary to fix the issue with type: "agent" hooks.

Guidance

  • Review the hook executor code to ensure it passes the messages parameter to PreToolUse call sites, as required by agent hooks.
  • Verify that the messages parameter is correctly populated with the conversation history before passing it to the hook executor.
  • Check the internal hook development skill guide (plugins/plugin-dev/skills/hook-development/SKILL.md) for any updates or documentation on type: "agent" hooks, as they may have been added later and not fully implemented.
  • Test the fix by reproducing the steps outlined in the issue and verifying that the agent hook executes successfully and returns a JSON decision.

Example

No code snippet is provided, as the issue does not include specific code that needs to be modified.

Notes

The issue may be related to a regression or incomplete implementation of type: "agent" hooks in the PreToolUse and PostToolUse events. Further investigation is needed to determine the root cause and develop a comprehensive fix.

Recommendation

Apply a workaround by modifying the hook executor to pass the messages parameter to PreToolUse call sites, as this is likely the cause of the issue. This change should allow type: "agent" hooks to execute correctly and return a JSON decision.

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