Repository navigation
Run Bash-matched PreToolUse hooks on monitor commands - #439
Merged
Merged
Conversation
A PreToolUse group with `"matcher": "Bash"` did not run for a monitor
call, so a Bash guard that exits 2 blocked `bash({command: "rm -rf x"})`
and let `monitor({command: "rm -rf x"})` start the command. Only the
`if: "Bash(...)"` filter covered monitor; the group matcher saw the
names `monitor` and `Monitor` alone.
A monitor call is now also offered to the groups whose matcher meets
Bash and not Monitor, as Claude Code does:
- The hook receives a Bash call: `tool_name` is `Bash` and `tool_input`
holds `command` and `description`.
- Its `if` is judged as a Bash call, so `Bash(echo *)` filters on the
command and a hook whose `if` names Monitor does not run.
- A block (exit 2, `permissionDecision: "deny"`, `decision: "block"`)
blocks the monitor call. `updatedInput` is not applied to the monitor
input, and `allow` changes nothing.
- A group whose matcher meets Monitor itself (`Monitor`, `Bash|Monitor`,
`*`, no matcher) runs once, with the Monitor payload, as before.
PostToolUse is unchanged: a Bash matcher does not run for monitor.
Other tools are unchanged.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



A PreToolUse hook group with a
Bashmatcher did not run for amonitorcall, so a Bash guard did not see a shell command started throughmonitor. Under{"matcher": "Bash", "hooks": [{"command": "guard.sh"}]}with a guard that exits 2, abashcall was blocked andmonitor({command: ...})ran its command.A monitor call is now also offered, as a Bash call, to the PreToolUse groups whose matcher meets Bash but not Monitor:
tool_name: "Bash"withtool_input: {command, description}.Bash|Read,^Bash$andBash.*count as Bash matchers. A group whose matcher meets Monitor itself (Monitor,Bash|Monitor,*, no matcher) runs once, with the Monitor payload, as before.updatedInputis not applied to the monitor input.ifnames Monitor does not run.This is the behaviour of Claude Code 2.1.325 for the same thirteen hook configurations on one Monitor call;
tests/hooks-monitor-bash.test.tsholds the table.Hooks from the Bash pass run after the hooks matched as Monitor. An identical handler placed in both a
Bashgroup and aMonitorgroup runs once per payload.npm run checkpasses (Biome, strict tsc, Vitest)