Documentation/Feature: paths frontmatter in .claude/rules/ does not enable lazy loading
Summary
The documentation for .claude/rules/ suggests that the paths: frontmatter field enables conditional loading, but in practice all files are loaded at startup regardless of the paths field.
Documentation Quote
From Manage Claude's Memory:
"Rules can be scoped to specific files using YAML frontmatter with thepathsfield. These conditional rules only apply when Claude is working with files matching the specified patterns." "Rules without apathsfield are loaded unconditionally and apply to all files."
The second quote implies rules WITH a paths field should load conditionally. However, all .claude/rules/*.md files consume context tokens at startup.
Steps to Reproduce
- Create
.claude/rules/test-rule.mdwith paths frontmatter:
```yaml
---
paths:
- src/some-specific-dir/**/*
---
# Test Rule
This content should only load when working in src/some-specific-dir/
```
- Start a new Claude Code session
- Run
/contextto see memory usage - Observe: The test-rule.md is listed under "Memory files" and consumes tokens, even though no files in
src/some-specific-dir/have been accessed
Expected Behavior
Files with paths: frontmatter should:
- NOT be loaded into context at startup
- Only load when Claude accesses files matching the specified paths (true lazy loading)
This is how nested CLAUDE.md files work (they lazy-load when accessing files in their subtree).
Actual Behavior
All .claude/rules/*.md files are loaded at startup, regardless of paths: frontmatter. The paths: field only affects when rules apply, not when they load.
Impact
For projects with many rules files, this causes significant context bloat at startup. In my case, ~10k tokens were consumed by rules files before any work began.
Workaround
Use nested CLAUDE.md files in source directories instead of .claude/rules/:
src/modules/CLAUDE.md
src/modules/<domain>/CLAUDE.md
This achieves true lazy loading but scatters rules across the codebase.
Request
- Clarify documentation: If current behavior is intentional, update docs to say "paths controls when rules apply, not when they load"
- Or implement lazy loading: Make
paths:frontmatter enable true lazy loading (files not loaded until paths match)
Environment
- Claude Code version: 2.0.76
- OS: Linux (Arch)
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗