Automate actions with hooks changedhooks-guide
Nearest release: v2.1.333, published 4 hours before upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 30 Nov 2026 23:59 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 1 Dec 2026 00:07 UTC.
Upstream edited
Recorded here
Lines+11added
Lines−3removed
From line
768
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits67to this page, all time
The whole hunk
from line 768, old and new numbered
/
from line 768
768768
769769The `if` field uses [permission rule syntax](https://code.claude.com/docs/en/permissions.md) to filter hooks by tool name and arguments together.
770770
771For example, this configuration runs a hook only when Claude uses `git` commands rather than all Bash commands:
771Add a pattern in parentheses, such as `Bash(git *)`, after these tool names:
772772
773* **`Bash`, `PowerShell`, [`Monitor`](https://code.claude.com/docs/en/hooks#match-monitor-commands)**: matches the command
774* **`Read`, `Edit`, `Write`, `NotebookEdit`**: matches the file path. To cover `Edit` and `Write`, use two handlers: `"Edit(*.ts)"` and `"Write(*.ts)"`
775* **`Grep`, `Glob`**: matches the call's `pattern` argument
776
777For other tools, use the tool's full name alone and check the input in your script.
778
779The following configuration runs a hook when Claude uses `git` commands:
780
773781```json theme={null}
774782{
775783 "hooks": {
from line 809
801809
802810When Claude Code can't split the Bash input into subcommands, it runs your hook regardless of the pattern. The [Bash matching table](https://code.claude.com/docs/en/hooks.md#bash-if-matching) covers the command shapes Claude Code can and can't narrow by subcommand. Because the filter is best-effort, use the [permission system](https://code.claude.com/docs/en/permissions.md) rather than a hook to enforce a hard allow or deny.
803811
804The `if` field accepts the same patterns as permission rules: `"Bash(git *)"`, `"Edit(*.ts)"`, and so on. To match multiple tool names, use separate handlers each with its own `if` value, or match at the `matcher` level where pipe alternation is supported.
812To match multiple tool names, use separate handlers each with its own `if` value, or match at the `matcher` level where pipe alternation is supported.
805813
806814> [!NOTE]
807815>
from line 841
833841
834842The model's only job is to return its decision as JSON:
835843
836* `"ok": true`: the action proceeds
844* `"ok": true`: the action passes this hook
837845* `"ok": false`: what happens depends on the event:
838846 * `Stop` and `SubagentStop`: the `reason` is fed back to Claude so it keeps working, unless the response also sets `"impossible": true` to mark the condition as one that can never be satisfied, in which case Claude Code allows the stop and the turn ends
839847 * `PreToolUse`: the tool call is denied; by default the turn ends and the deny `reason` appears in the chat as a warning line. Set `continueOnBlock: true` on the hook to instead return the `reason` to Claude as the tool error, so it can adjust and continue
No line in this hunk matches that.