Skip to content

Run a handler once when a monitor call selects it as Monitor and as Bash - #450

Merged
ilovepixelart merged 1 commit into
mainfrom
fix/monitor-hook-runs-once
Nov 15, 2026
Merged

ilovepixelart merged 1 commit into
mainfrom
fix/monitor-hook-runs-once

Conversation

@ilovepixelart

Copy link
Copy Markdown
Owner

A monitor call runs the PreToolUse groups whose matcher meets Monitor and, as a Bash call, the groups whose matcher meets Bash only. Handlers were deduplicated within each of the two passes, not across them.

PreToolUse hook runs for one monitor call, with audit declared under Bash|Monitor and again under Bash:

Runs of audit
Before 2 (Monitor payload, Bash payload)
After 1 (Monitor payload)
Claude Code 2.1.325 1 (Monitor payload)
  • oncePerCall in extensions/hooks/decisions.ts drops from the Bash pass a handler the Monitor pass already selected.

  • Where the Bash-pass copy has the higher sourceRank, it runs and the Monitor-pass copy is dropped, so a lower-precedence async copy under * does not replace a managed or --settings blocking guard under Bash.

  • handlerKey in extensions/hooks/matcher.ts is the dedup key keepOnce already used, now shared.

  • npm run check passes (Biome, strict tsc, Vitest)

  • Tests cover the change

A monitor call runs the PreToolUse groups that meet Monitor and, as a
Bash call, the groups that meet Bash only. Handlers were deduplicated
within each pass, so a command declared under "Bash|Monitor" (or "*")
and again under "Bash" ran twice on one monitor call, once with each
payload. Claude Code 2.1.325 runs it once, with the Monitor payload.

A handler both passes select now runs once, as the Monitor call. The
Bash-pass copy runs instead where it comes from a higher-precedence
settings source, so a project's async copy under "*" does not replace a
managed blocking guard under "Bash".
@sonarqubecloud

Copy link
Copy Markdown

@ilovepixelart
ilovepixelart merged commit 3c93489 into main Nov 15, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant