3.3 Apply path-specific rules for conditional convention loading
Use .claude/rules/ files with YAML `paths` frontmatter so conventions load only when Claude works on matching files, and choose glob rules over directory CLAUDE.md files when a convention spans directories.
Key points
- 1
A rule is any
.mdfile under.claude/rules/(discovered recursively). Scope it with YAML frontmatter between---markers:paths:followed by a list of globs such as["terraform/**/*"]or["**/*.test.tsx"].pathsis the only frontmatter field a rule reads. - 2
Rules without a
pathsfield load unconditionally in every session. A scope written as a heading or prose inside the rule does nothing; only the frontmatter counts. Malformed YAML is ignored and the rule loads as unconditional. - 3
Path-scoped rules load when Claude reads files matching the pattern, which reduces irrelevant context and token usage in sessions that never touch that area. Splitting into
@imports does not have this effect because imports load at launch. - 4
Glob cheat sheet:
**/*.tsmatches every TypeScript file anywhere;src/**/*everything undersrc/;*.mdonly root-level Markdown;src/components/*.tsxone directory. Brace expansion (**/*.{test,spec}.ts) covers several extensions in one pattern; a rule may list several patterns. - 5
Choose a glob rule over subdirectory CLAUDE.md files when the convention follows a file type spread across the codebase (colocated
*.test.tsxfiles,*.sqlmigrations in many folders). Directory CLAUDE.md files are directory-bound and cannot follow a naming pattern. - 6
Choose a subdirectory CLAUDE.md when the convention is confined to one directory, especially when that directory's maintainers should own the file without editing the shared
.claude/folder. - 7
Over-broad globs are a common diagnosis:
**/api/**also matchesdocs/api/and fixtures. Tighten to the real roots and extension (src/api/**/*.ts,services/*/api/**/*.ts) rather than adding prose caveats. - 8
Personal rules go in
~/.claude/rules/and apply to every project on that machine; they load before project rules but do not override them, so keep the two consistent. - 9
Distractors the exam uses: consolidating every convention in the root CLAUDE.md and relying on inference, a CLAUDE.md in every folder, skills that must be invoked, and permission settings, none of which give deterministic path-based loading.
Test yourself on 3.3 Apply path-specific rules for conditional convention loading
Ten questions, with the answer and explanation after each one.