Duplicate .claude/rules loading in worktrees nested inside .claude/
Summary
When using worktrees created inside .claude/worktrees/, rules from .claude/rules/ are loaded twice — once from the worktree's own copy and once from the parent repo's .claude/rules/ (discovered via ancestor directory traversal).
Steps to reproduce
- Have a project with
.claude/rules/containing rule files - Enter a worktree (created at
.claude/worktrees/<name>/) - Observe that rules are loaded twice:
Loaded ../../rules/pagination.md
Loaded ../../rules/security.md
Loaded ../../rules/viewsets.md
Loaded .claude/rules/pagination.md
Loaded .claude/rules/security.md
Loaded .claude/rules/viewsets.md
Expected behavior
Each rule file should be loaded only once. When operating inside a worktree, the rule discovery should deduplicate rules that resolve to the same file content/origin, or skip ancestor .claude/rules/ directories that belong to the parent repo.
Actual behavior
Rules are loaded twice because:
- The worktree is physically located at
<repo>/.claude/worktrees/<name>/ - The worktree has its own
.claude/rules/(checked into git) - Walking up the filesystem from the worktree also finds
<repo>/.claude/rules/ - Both are loaded, resulting in duplicate context and wasted tokens
Impact
- Duplicate context consumes tokens unnecessarily (each rule file is sent twice)
- With many rule files, this compounds significantly
Suggested fix
During rule discovery, if the current working directory is a worktree nested inside another repo's .claude/, skip ancestor .claude/rules/ directories that belong to the parent repo.
This issue has 9 comments on GitHub. Read the full discussion on GitHub ↗