Skip to content
BENIBIX Learn

Hook Matcher

AI⌨️ Claude CodeConfiguration

Also known as matcher

The field that picks which tools or events a hook runs on.

Think of it like

It is like a sign on a door. It says who may come in.

Example

Jack wrote Edit.* to match edits. His hook also ran on NotebookEdit. He changes it to ^Edit$ and it stops.

Why it matters

It is the main way to keep a hook from running on everything.

Definition

A hook matcher is the matcher field that picks which events a hook group runs on. An empty matcher or * matches all. A value of only letters, digits, _, - and | is an exact name or list, such as Edit|Write. Anything else is a regular expression that can match part of a name, so Edit.* also matches NotebookEdit. Each event matches a different field, such as the tool name.

Example code

json
{
  "hooks": {
    "PostToolUse": [
      { "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "npm run lint" }] }
    ]
  }
}
Run only after Edit or Write.
Three ways a matcher is read.

Common mistake

Using a pattern that matches part of a name. Wrap it in ^ and $ for a whole match.

Key takeaways

  1. 1
    Empty matches all. Or a star.
  2. 2
    Plain is exact. Edit|Write.
  3. 3
    Else a pattern. Part match.

Compare