⌨️Hook if Condition
Also known as if field
A field that runs a hook only when the call matches one rule.
Think of it like
It is like a guard who only checks red bags.
Example
Lucy's hook only cares about git push. She adds an if rule for it, and the hook stops running on every other command.
Why it matters
It saves a script start on every call the hook would just ignore.
Definition
Example code
json
{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash", "hooks": [{ "type": "command", "if": "Bash(git push *)", "command": "./check-branch.sh" }] }
]
}
}Common mistake
Key takeaways
- 1One permission rule. Like Bash(git *).
- 2Finer than matcher. Looks at input.
- 3Checks each part. Of a Bash line.