[BUG] Path-scoped rules in .claude/rules/ load into context globally regardless of paths: frontmatter
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Rules placed in .claude/rules/ with paths: frontmatter are loaded into the conversation context at session start, even when the working directory doesn't match the specified paths.
What Should Happen?
Expected behavior:
Rules with paths: frontmatter should only load into context when working with files matching those paths.
Actual behavior:
All .md files in .claude/rules/ are loaded into context at session start, regardless of paths: configuration.
Error Messages/Logs
Steps to Reproduce
- Create a path-scoped rule file:
.claude/rules/solutions/standards.md
- Add frontmatter:
---
paths:
- "solutions/**/*"
---
# Solutions Standards
[content...]
- Start a new Claude Code session in the project root
- Observe that the rule content appears in the loaded context
Environment:
- Claude Code CLI
- macOS
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.76
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Cursor
Additional Information
Impact:
Projects with multiple directory-specific rules experience significant context bloat. In my case, 28 rules load at session start when only ~5 should be global.
Workaround:
None found. Removing alwaysApply: false (which isn't documented anyway) had no
14 Comments
Found 1 possible duplicate issue:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
same issue
## Description
Rules files with
pathsfrontmatter in.claude/rules/are being loaded into the system prompt at conversationstart, regardless of whether the user is working with files matching those patterns.
### Expected Behavior
According to the documentation, rules with a
pathsfield should only be loaded when working with files matchingthose glob patterns:
``
markdown
``---
paths: **/*.razor
---
# Blazor Component Rules
...
This rule should only load when I'm working with
.razorfiles.### Actual Behavior
All rules files in
.claude/rules/are loaded into the system context at the start of every conversation, regardlessof:
pathsmatch anything being worked on### Steps to Reproduce
.claude/rules/with differentpathspatterns:blazor-rules.mdwithpaths: **/*.razorcsharp-rules.mdwithpaths: **/*.csmvc-rules.mdwithpaths: **/*.cshtml### Environment
### Example Rules File Structure
``
``.claude/
rules/
blazor-claude.md (paths: **/*.razor)
csharp-claude.md (paths: **/*.cs)
mvc-claude.md (paths: **/*.cshtml)
Additional finding: Rules never "scope out" once loaded
I can confirm this issue and want to add an important observation:
Once a path-scoped rule is loaded into context, it remains active for the entire session even after navigating away from the matching paths.
Test setup:
Results:
| Step | Expected | Actual |
|------|----------|--------|
| Start session at
~/| No "nyan" | No "nyan" ✓ || Edit file in
~/works/my-project/| "nyan" | "nyan" ✓ || Return to edit file at
~/| No "nyan" | "nyan" ✗ |Conclusion:
The
pathsfrontmatter acts as a "load trigger" rather than an "application scope". Rules accumulate throughout the session and never deactivate, even when working outside the specified paths.I don't think anyone expected the context to load out. Once it's loaded it's there for the session.
I would advise opening a separate defect for this.
any progress on this one? I have a large set of rules for backend/frontend repo and its not ideal to have all my rules always loaded
Just checking in. I'm running into the same problem. Any progress on this? I have a large set of rules. It would be great if they didn't always load globally upon initialization. I think the idea was to have them lazy load as needed, no?
Any news regarding this issue?
Would love some info here. It basically renders things like rules useless in worktrees which my team uses heavily.
version 2.1.63 - it works for me.
Care to share a sample @mcsdodo ?
I have a rule with this frontmatter:
and when loading the specific file I can see it loads the rule. Doesn't if I load anything else (asked it to show md files loaded to context).
<img width="468" height="176" alt="Image" src="https://github.com/user-attachments/assets/d47c38d8-f2d8-45a2-ab9f-f04927fe52d8" />
currently on version 2.1.74. Might be issue with asterisk paths only?
In addition to the above, I've found that @-referencing files within a rule (to avoid duplication, for example) causes referenced files to be included in context even if the rule didn't match. It won't display
⎿ Loaded <path>, but the content will be included in the context and Claude will show the filename + overview if you ask "What files do you have loaded into your context?"```markdown ~/.claude/rules/test.md
---
~/.claude/rules/test.md
paths:
---
@~/.claude/knowledge/stuff.md
I second the issue reported by @mojodna: all @-imports are loaded unconditionally, even when the scoped rules referencing them are not triggered and not loaded. I believe this is not an intended behavior.
I use @-imports extensively to avoid duplication and rule sync issues, but with the current implementation it's kinda useless.
Adding a data point + mitigation for anyone hitting this.
Observed: 75
.mdfiles under.claude/rules/**/refs/subdirectories in our repo were all auto-loaded globally despite being intended as progressive-disclosure deep references linked from parent rule files. Baseline context bloated to 139.5k tokens (14% of 1M) at session start with no files opened. Confirmed via/context.Structure (each subdirectory mirrors a parent rule file):
Mitigation that worked for us:
Add
paths:frontmatter to everyrefs/*.mdfile matching the parent rule scope. Expected baseline drop from ~140k → ~40k tokens.