* wildcard in hook `if` pattern doesn't match strings containing spaces

Resolved 💬 1 comment Opened May 27, 2026 by ash-rc Closed Jun 27, 2026

Description

The * wildcard in the if condition of hook configurations does not match strings containing spaces. It appears to act as a single-token wildcard rather than matching any sequence of characters.

Expected behavior

Bash(git commit *) would match git commit -m "some message" — i.e. * matches any sequence of characters after the space, including multi-word arguments.

Actual behavior

Bash(git commit *) does not fire for git commit -m "some message". The * only matches a single token (no spaces).

Reproduction

Add this hook to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "if": "Bash(git log *)",
            "command": "echo 'HOOK_FIRED' >> /tmp/hook_test.txt",
            "timeout": 5
          }
        ]
      }
    ]
  }
}

Then run git log --oneline -1. The file /tmp/hook_test.txt is not created — the hook does not fire.

Changing the pattern to Bash(git log*) (no space) or Bash(*git log*) (substring match) both work correctly.

Why this is confusing

The hooks documentation uses Bash(git push *) as an example, which works in the specific case shown (npm test && git push — no arguments after git push). This masks the limitation and implies * behaves like a standard glob or regex .*.

Workaround

Use *pattern* for substring matching, e.g. Bash(*git push*) instead of Bash(git push *).

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗