.claude/rules/ with Frontmatter Paths
Load rules only when editing matching files.
The Monolithic CLAUDE.md Problem
As your project grows, a single CLAUDE.md tends to collect rules for everything: React components, SQL migrations, CI scripts, Terraform. Every one of those rules is loaded into context on every session, even when you are only touching one file type.
That wastes tokens and dilutes attention. The model attends most to the start and end of context (lost-in-the-middle), so a giant rules file can bury the instruction that actually matters for the file you are editing.
.claude/rules/ solves this: split rules into small files that load only when you edit matching files.
How Path-Scoped Rules Work
A rule file lives in .claude/rules/ and starts with a YAML frontmatter block. The key field is paths: a list of glob patterns. The rule body is injected into context only when the files you are working on match one of those patterns.
Think of it as conditional, file-aware instructions. No match means the rule stays out of context entirely, keeping the window lean for the task at hand.
All lessons in this course
- User / Project / Directory Levels
- The @path Import Syntax
- .claude/rules/ with Frontmatter Paths
- Monolith vs Modular Rules