Path-scoped rules injected twice when a plugin is installed and its source repo is the working directory
Path-scoped rules injected twice when a plugin is installed and its source repo is the working directory
Summary
When a Claude Code plugin ships rules under .claude/rules/ and the
working directory is that plugin's own source repo (which contains the
same .claude/rules/), path-scoped rule bodies are injected twice
per tool result — once from the installed plugin, once from the project —
because the identical rule file exists in two active roots. For plugin
authors dogfooding in their own repo, every path-scoped rule's full body
is duplicated in context.
Environment
- Claude Code (Cowork / desktop), macOS
- Plugin
attune-aiinstalled via marketplace, and working inside
the attune-ai source repo (a git worktree of it)
What I observed
Editing a docs/** file, a single tool result carried the same rule's
full body twice, under two different path labels — e.g. forplugin-reference-validation.md:
/Users/<me>/.claude/rules/attune/plugin-reference-validation.md
— this path does not exist on disk (apparently a normalized/virtual
path for the installed plugin's rules)
/Users/<me>/attune-ai/.claude/worktrees/<slug>/.claude/rules/attune/plugin-reference-validation.md
— the real project copy
On disk the rule physically lives in two active roots:
- installed plugin:
~/.claude/plugins/marketplaces/attune-ai/.claude/rules/attune/… - project checkout:
<repo>/.claude/rules/attune/…
(~/.claude/rules/ itself is empty.)
These are path-scoped rules (YAML paths: frontmatter → the full
body auto-loads when a matching file is read/edited). Several were
duplicated in one turn (e.g. a ~1.3k-token doc-cleanup rule and a
~1.9k-token grammar rule), so a single docs edit doubled multiple full
bodies at once.
Impact
Wasted context / tokens on every path-scoped rule injection, for the
(common, for plugin authors) case of working in a plugin's own repo with
that plugin installed. Multiplied per rule per matching tool call.
Proposed fix
Dedupe rule bodies across roots before injection — by rule identity
(path relative to .claude/rules/) or by content hash — and inject
once. A rule present in both an installed plugin and the project should
surface a single time.
Note
This is observed from inside a session; the exact injection-sourcing
(and why the installed-plugin copy is labeled ~/.claude/rules/…, a
path that doesn't exist on disk) is visible to the Claude Code team, not
to me. The cross-root dedup fix stands regardless of that labeling
detail.