What you need to know
A rule file in .claude/rules/ can declare which files it applies to, using glob patterns in YAML frontmatter. The rule loads only when Claude is working on a matching file.
---
paths: ["**/*.test.tsx", "**/*.test.ts", "**/*.spec.*"]
---
# Testing conventions
- Use the fixtures in test/fixtures; never build test data inline.
- One behaviour per test; name tests "does X when Y".
- Use React Testing Library queries by role, not by class name.
---
paths: ["infra/**/*.tf"]
---
# Terraform conventions
- Modules only; no inline resources.
- Every resource carries the owner and cost-centre tags.
Why scope rules to paths
- Less irrelevant context. Terraform rules do not load while someone edits React components.
- Fewer tokens in every session that does not touch those files.
- Conventions that follow file type, not folder. Test files sit next to the code they test, all over the tree. A directory-level CLAUDE.md cannot reach them all without being copied into every folder; one glob,
**/*.test.tsx, does.
Directory CLAUDE.md or path rule?
| Situation | Choose |
|---|---|
Conventions for one self-contained folder (infra/) | Either works; a path rule keeps all rules in one place |
| Conventions for a file type spread across many folders (tests, migrations, stories) | Path-specific rule with a glob |
| Conventions every session needs | Unscoped rule or project CLAUDE.md |
In the exam
Questions usually describe a convention for test files, migrations or infrastructure files and ask how to apply it only where relevant. Look for "spread throughout the codebase" (glob rule) and "load only when editing" (paths frontmatter).
Check your understanding
Test files sit beside their source files in every package. You want testing conventions applied to all of them and nowhere else. What do you create?
Show answer
Answer: D. A glob such as **/*.test.* matches test files wherever they live, and the rule loads only when those files are being edited.
What is the main benefit of a paths field on a rule file?
Show answer
Answer: B. Path scoping is about when a rule loads: only for matching files, which saves context and keeps irrelevant rules out of the session.
Which situation is the best fit for a path-specific rule rather than a directory CLAUDE.md?
Show answer
Answer: A. Migrations spread across many folders share a convention by file type; a glob covers them in one rule. A single folder can use either; personal preferences are user scope; universal guidance needs no path.
Apply it: Harbor Lane's path rules
Write Harbor Lane's path-scoped rules.
- Write a testing rule whose globs cover every test file in
web/,api/andshared/. - Write a Terraform rule that applies only to
infra/. - Decide whether the React conventions should be a path rule or a
web/CLAUDE.md, and justify it. - Estimate the benefit: what no longer loads when an engineer edits an API handler?
Show model answer
1. Testing rule. .claude/rules/testing.md with paths: ["**/*.test.ts", "**/*.test.tsx"], then the fixture, naming and query conventions.
2. Terraform rule. .claude/rules/terraform.md with paths: ["infra/**/*.tf"], then modules-only and tagging rules.
3. React. A path rule with paths: ["web/**/*.tsx"]. Both would work because React lives in one folder, but keeping every convention in .claude/rules/ gives one place to look, and the glob also excludes non-component files in web/.
4. Benefit. Editing api/src/handlers/booking.ts loads the TypeScript and API rules only. The testing rule (until a test file is opened), the React rule and the Terraform rule stay out of context.