[BUG]

Resolved 💬 8 comments Opened Feb 2, 2026 by kthrams Closed Apr 23, 2026

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

  1. 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
          }
        ]
      }
    ]
  }
}
  1. Run any Bash command through Claude Code (e.g., git push origin master)
  2. 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.

View original on GitHub ↗

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