Documentation/Feature: paths frontmatter in .claude/rules/ does not enable lazy loading

Resolved 💬 4 comments Opened Dec 29, 2025 by bengous Closed Dec 29, 2025

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 the paths field. These conditional rules only apply when Claude is working with files matching the specified patterns." "Rules without a paths field 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

  1. Create .claude/rules/test-rule.md with paths frontmatter:

```yaml
---
paths:

  • src/some-specific-dir/**/*

---

# Test Rule
This content should only load when working in src/some-specific-dir/
```

  1. Start a new Claude Code session
  2. Run /context to see memory usage
  3. 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

  1. Clarify documentation: If current behavior is intentional, update docs to say "paths controls when rules apply, not when they load"
  2. 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)

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗