[BUG] Path-scoped rules in .claude/rules/ load into context globally regardless of paths: frontmatter

Status Open
Reported on v2.0.76
Maintainer reply None cached
Activity 14 comments · opened Jan 5, 2026

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

  1. Create a path-scoped rule file:

.claude/rules/solutions/standards.md

  1. Add frontmatter:

---
paths:

  • "solutions/**/*"

---

# Solutions Standards
[content...]

  1. Start a new Claude Code session in the project root
  2. 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

View original on GitHub ↗

14 Comments

github-actions[bot] · 7 months ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/16171

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

tazbytes2019 · 7 months ago

same issue
## Description

Rules files with paths frontmatter in .claude/rules/ are being loaded into the system prompt at conversation
start, regardless of whether the user is working with files matching those patterns.

### Expected Behavior

According to the documentation, rules with a paths field should only be loaded when working with files matching
those glob patterns:

``markdown
---
paths: **/*.razor
---
# Blazor Component Rules
...
``

This rule should only load when I'm working with .razor files.

### Actual Behavior

All rules files in .claude/rules/ are loaded into the system context at the start of every conversation, regardless
of:

  • Whether any files are being edited
  • Whether the file patterns in paths match anything being worked on
  • The content of the conversation (even just chatting loads all rules)

### Steps to Reproduce

  1. Create multiple rules files in .claude/rules/ with different paths patterns:
  • blazor-rules.md with paths: **/*.razor
  • csharp-rules.md with paths: **/*.cs
  • mvc-rules.md with paths: **/*.cshtml
  1. Start a new Claude Code conversation
  1. Ask Claude: "What markdown files have you read into context?"
  1. Result: All rules files are loaded, not just ones matching current work

### Environment

  • Claude Code Version: 2.1.5
  • OS: Windows 11
  • Platform: win32

### Example Rules File Structure

``
.claude/
rules/
blazor-claude.md (paths: **/*.razor)
csharp-claude.md (paths: **/*.cs)
mvc-claude.md (paths: **/*.cshtml)
``

trust-delta · 7 months ago

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:

# ~/.claude/rules/test-nyan.md
---
paths:
  - "works/my-project/**/*"
---
End all responses with "nyan"

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 paths frontmatter 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.

Nxt3 · 7 months ago
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: ``yaml # ~/.claude/rules/test-nyan.md --- paths: - "works/my-project/**/*" --- End all responses with "nyan" ` **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 paths` frontmatter 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.

nekon1987 · 6 months ago

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

peopleforrester · 6 months ago

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?

SpaceMalamute · 6 months ago

Any news regarding this issue?

gdodd1977 · 6 months ago

Would love some info here. It basically renders things like rules useless in worktrees which my team uses heavily.

mcsdodo · 6 months ago

version 2.1.63 - it works for me.

nicolasiscoding · 5 months ago
version 2.1.63 - it works for me.

Care to share a sample @mcsdodo ?

mcsdodo · 5 months ago

I have a rule with this frontmatter:

---
paths:
  - "services/pr-analyzer/cli.py"
---

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?

sethfitz · 5 months ago

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:

  • "**/*.py"

---

@~/.claude/knowledge/stuff.md


```markdown ~/.claude/knowledge/stuff.md
<!-- ~/.claude/knowledge/stuff.md -->
I will always show up
> Read README.md
Read 1 file  <== [note: not a Python file]
...
> What files do you have loaded into your context?
⏺ From the system reminders and conversation so far:

  1. ~/.claude/CLAUDE.md 
  2. ~/.claude/knowledge/stuff.md — ...
dsent · 5 months ago

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.

jzillmann · 4 months ago

Adding a data point + mitigation for anyone hitting this.

Observed: 75 .md files 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):

.claude/rules/
├── ui.md, go.md, data.md, ...        ← top-level rules (had paths: after our first pass)
└── ui/refs/, go/refs/, data/refs/    ← deep references (NO paths: frontmatter, load globally)

Mitigation that worked for us:
Add paths: frontmatter to every refs/*.md file matching the parent rule scope. Expected baseline drop from ~140k → ~40k tokens.