PreToolUse hook: `if` filter on handler silently matches nothing

Resolved 💬 3 comments Opened Apr 17, 2026 by ole15713-blip Closed Apr 17, 2026

Description

Two issues with PreToolUse hook handlers configured in settings.json:

1. if field on hook handler never matches

A command hook with "if": "Bash(*git commit*)" (or "Bash(git commit*)") at the handler level never fires, even though the same hook without if fires correctly on every Bash call.

Steps to reproduce:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "if": "Bash(*git commit*)",
            "command": "echo 'FIRED' >> /tmp/hook_test.log"
          }
        ]
      }
    ]
  }
}
  1. Restart Claude Code
  2. Run a Bash tool call containing git commit
  3. Check /tmp/hook_test.log — file does not exist

Expected: Hook fires when the Bash command contains git commit.

Workaround: Remove if, parse stdin JSON in the command script instead:

jq -r '.tool_input.command' | grep -q 'git commit'

This confirms the tool input is available via stdin and the matcher fires — only the if filter is broken.

2. agent type hook produces no visible output

Replacing "type": "command" with "type": "agent" (and adding prompt, timeout, statusMessage), the hook produces no visible effect: no spinner, no status message, no agent output, no file changes from the agent's review.

{
  "type": "agent",
  "prompt": "Run `git diff --cached` and review for issues.",
  "timeout": 120,
  "statusMessage": "Reviewing staged changes..."
}

This may be related to issue 1 (if the if filter was silently suppressing execution), but we also tested without if on a "matcher": "Bash" group and still saw no statusMessage or agent activity.

Expected: The statusMessage should appear while the agent runs, and the agent's changes (if any) should be visible.

Environment

  • Claude Code CLI (latest as of 2026-04-17)
  • Debian 13 (Trixie), Linux 6.19.6, KDE Wayland
  • Model: claude-opus-4-6
  • Settings location: ~/.claude/settings.json (user-level)

View original on GitHub ↗

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