claude-code - 💡(How to fix) Fix * wildcard in hook `if` pattern doesn't match strings containing spaces

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…

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.

Root Cause

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.

Fix Action

Workaround

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

Code Example

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

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 *).

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…

FAQ

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.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING