Skip to content

Run the highest-precedence copy of a deduplicated hook - #440

Merged
ilovepixelart merged 1 commit into
mainfrom
fix/hook-dedup-precedence
Nov 15, 2026
Merged

ilovepixelart merged 1 commit into
mainfrom
fix/hook-dedup-precedence

Conversation

@ilovepixelart

Copy link
Copy Markdown
Owner

When the same hook handler is declared in several settings sources it runs once. keepOnce in extensions/hooks/matcher.ts replaced the kept copy with any later copy that carried projectDir, with all of that copy's fields. Managed and --settings hooks carry no projectDir, so a repository's .claude/settings.json could declare the same command with "async": true and turn a blocking PreToolUse guard from managed settings or the --settings file into a background hook.

The copy that runs is now the one from the highest-precedence source, with all its own fields (async, timeout, its own CLAUDE_PROJECT_DIR), at the position of the first occurrence:

user settings < project settings.json < settings.local.json < --settings file < managed settings

Blocking guard in async copy in Before After
managed project runs blocked
--settings project runs blocked
local project runs blocked
project local blocked runs
user project runs runs

Claude Code 2.1.325 gives the "After" column for every row. The dedup key is unchanged, so plugin, skill and agent copies stay separate.

Each hook gets a sourceRank where its source is known: managed hooks in loadManagedHooks, settings-file hooks from their place in claudeSettingsSources (the legacy local file ranks just below the root local file).

  • npm run check passes (Biome, strict tsc, Vitest)
  • Tests cover the change

A handler declared identically in several settings sources ran as the
copy carrying a projectDir, so a project or local copy replaced a
managed or --settings copy wholesale. With a blocking PreToolUse guard
(exit 2) in managed settings or the --settings file and the same
command with "async": true in .claude/settings.json, the Bash call ran.

Each settings hook now carries its source's precedence: its file's
place in the settings chain (user, project, local, --settings), with
managed policy above all. keepOnce keeps the copy from the higher
source, with all its fields and its own CLAUDE_PROJECT_DIR, at the
position of the first copy. This is the order Claude Code 2.1.325
applies. Plugin and skill copies stay separate.
@sonarqubecloud

Copy link
Copy Markdown

@ilovepixelart
ilovepixelart merged commit 14bc4b4 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