UserPromptSubmit agent hooks fail: "Messages are required for agent hooks"

Resolved 💬 7 comments Opened Feb 18, 2026 by dennismysh Closed Apr 22, 2026

Description

Agent-type hooks on UserPromptSubmit always fail with the error:

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

The error message is from the source itself — the throw statement includes "This is a bug."

Version: 2.1.45

Steps to reproduce

  1. Add an agent hook for UserPromptSubmit in ~/.claude/settings.json:
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "agent",
            "prompt": "Check if the user prompt mentions testing."
          }
        ]
      }
    ]
  }
}
  1. Start a session and submit any prompt.
  2. Observe UserPromptSubmit hook error.

Debug output

(claude --debug):

[DEBUG] Getting matching hook commands for UserPromptSubmit with query: undefined
[DEBUG] Found 1 hook matchers in settings
[DEBUG] Matched 1 unique hooks for query "no match query" (1 before deduplication)
[DEBUG] Hook UserPromptSubmit (UserPromptSubmit) error:
Failed to run: Messages are required for agent hooks. This is a bug.

Root cause

The UserPromptSubmit handler calls the main hook executor without passing the messages parameter. Inside the executor, the agent hook branch requires messages and throws when it's undefined.

The Stop hook handler passes messages correctly — UserPromptSubmit just needs the same treatment.

Pseudocode diff:

 // UserPromptSubmit handler
-async function* handleUserPromptSubmit(prompt, context, toolUseContext) {
+async function* handleUserPromptSubmit(prompt, context, toolUseContext, messages) {
     let hookInput = {...baseInput, hook_event_name: "UserPromptSubmit", prompt};
     yield* executeHooks({
         hookInput,
         signal: toolUseContext.abortController.signal,
         toolUseContext,
+        messages,
     });
 }

Workaround

Use command type hooks for UserPromptSubmit instead of agent type.

View original on GitHub ↗

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