By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Your root CLAUDE.md has grown into a policy document. Line 14 says the API layer never imports the ORM directly. Line 15 says React components use named exports. Line 16 says migrations need two reviewers. All three are true. None of them is universal.
Every request to Claude Code now loads all of it, including the lines that cannot apply to the file in front of you. A path-specific rule fixes that. It is a markdown file in .claude/rules/ whose frontmatter names the file paths it governs, so it loads only when a matching file is in scope.
No. No matching file is in scope, so the rule adds nothing and costs nothing. That is the whole benefit: the context stays small and every loaded rule is relevant to the file being edited.
---
paths:
- "src/api/**/*.py"
---
# API layer rules
- Never import the ORM module directly. Call the functions in `src/api/repo.py`.
- Raise `HTTPException` with a status code on every error branch.
- A new endpoint needs a test under `tests/api/` before you report it done.The ** segment matches any number of directories, so this rule reaches every Python file under src/api/, however deep. One file per concern is easier to reason about than one large file with three glob sets inside it.
The file's own location decides nothing. A rule stored at .claude/rules/api.md that declares a web/ glob governs the web folder. The glob is the contract, and the filename is a label for humans.
This matters when you move code. Rename src/api/ to src/services/ and the old glob stops matching, so the rule stops loading. Nothing warns you. Grep your rule files whenever you move a directory.
There is a quieter benefit too: a rule is a reviewable unit. When a convention changes, you edit one short file and the diff shows exactly what changed. A 200-line CLAUDE.md hides the same change inside a rewrite, and the reviewer cannot tell which line moved.
Four habits keep a rule set small enough to trust. Apply them when you first write the file, not after it has grown for a year.
src/api/**/*.py beats **/* for the same reason a folder file beats the root file.CLAUDE.md.Applies to src/api/**/*.py saves the next reader a guess.A rule that never matches is the easiest mistake to miss, because silence looks like success. Keep the glob list short enough that you can name every path it covers. Delete a rule the first time you cannot remember why it exists.
CLAUDE.md is longer than 40 lines.Definition of done: the root file is shorter, and for each new rule you can say which paths it covers and name a path it does not cover.
Key takeaways
A path-specific rule is a file in .claude/rules/ with globs in its frontmatter.
The glob decides loading; the rule's own folder does not.
A rule that matches nothing costs nothing, which is the point.
Narrow, single-concern rules stay honest as the tree changes.
Overlapping globs create the contradictions that rules were meant to remove.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.