Module 4 · Claude Code configuration and workflows · Chapter 13
CLAUDE.md hierarchy and path-specific rules: where team rules belong
- Rules live at levels: your user file for personal defaults, the project root file for team rules, nested files for one subtree.
- Team rules belong in the repo, committed and reviewed. Personal preferences stay in your user file, off the team's screen.
- Path-scoped rules in
.claude/rules/load only for matching paths, so the always-on context stays small.
The picture: a house has house rules on the fridge, room rules on the room door, and your own habits in your head. Each rule sits where it applies.
Domain 3, Claude Code Configuration and Workflows (20 percent of the exam). Organise project configuration and path-specific rules. You should be able to:
- Name the CLAUDE.md levels and say what belongs at each one.
- Use
@importto pull a shared file into a CLAUDE.md. - Predict which rule wins when two files conflict.
- Scope a rule with
pathsfrontmatter so it loads only where it applies.
harbor-web monorepo, and their rules are in the wrong homes:
- "Run the full test suite before a pull request" sits in Kavish's personal user file. His teammates never see it. Two pull requests merge untested in one week.
- The project CLAUDE.md carries Kavish's own taste: "no comments in code". Teammates delete helpful comments to comply, then argue in review.
- "Amounts are integer cents" is a payments rule in the root file. It fires during marketing page work, and Claude keeps "fixing" display prices into cents.
- The three CLAUDE.md levels, and what belongs at each.
@importand conflicts: the nearer file wins.- Path-scoped rules in
.claude/rules/. - A worked example: what always-on rules cost a team.
- A lab: sort a messy pile of rules into the right homes.
Next: the three levels.
Step 1: Three levels, three audiences
Why this step: most exam questions here ask one thing: which file should hold this rule?
- User level (
~/.claude/CLAUDE.md): your personal defaults. Only your machine loads it. Answer style, habits, shortcuts. - Project level (
CLAUDE.mdat the repo root): the team's rules. Committed to the repo, so everyone gets them and review can debate them. - Nested (a
CLAUDE.mdinside a folder, saysrc/payments/): rules for that subtree only, loaded for work there.
The house picture again: fridge rules bind everyone, room rules bind the room, habits bind only you.
Where the picture breaks down:
- A room rule never reaches the kitchen. A nested file still sits under the root file, and both can load together.
- Your habits stay in your head. A user file is real text on one machine, so a teammate's machine never has it. That is the cold-open bug.
- House rules get argued at the door. Project rules get argued in pull requests, exactly where you want the argument.
The test for any rule: who needs it? Only you: user file. The team: project file. One folder: nested file or path rule (Step 3).
Quick check: where does a team rule belong?
Next: sharing files with @import, and what happens when rules disagree.
Step 2: Import shared files, and nearer wins
Why this step: teams outgrow one file, and files disagree.
A CLAUDE.md can pull in another file with an @import line:
# harbor-web project rules (illustrative)
@import ../shared/team-standards.md
## This repo
- API handlers use the repository pattern.
- Test files sit next to the code they test.
- Use imports for standards shared across repos, so one edit updates every project importing the file.
- An import is still team configuration. Keep the shared file in version control, where review sees changes.
- Do not import your personal file into the project file. That publishes your preferences as team law.
Conflicts: when two loaded files disagree, the nearer file wins. A rule in src/payments/CLAUDE.md beats the root file for work in src/payments, because it is closer to the work.
So fix a conflict at the level that is wrong. If the root rule should hold everywhere, remove the nested exception. If the exception is right, narrow the root rule.
Do this: pick your answer, then press the button.
The nearer file wins for its subtree. The root rule still governs the rest of the repo. If that split is an accident, delete one of the two rules instead of adding a third.
Next: the picture, then rules that load only on matching paths.
- Personal defaults from
~/.claude/CLAUDE.md. Only your machine has it, so nothing in it can be a team rule. - The root CLAUDE.md is committed with the code. Clone the repo and you have the rules. Change them in a pull request.
- An
@importline pulls shared standards into the project file, so several repos follow one source. - A CLAUDE.md inside
src/paymentsspeaks for that folder. On conflict with the root file, the nearer file wins. - Files in
.claude/rules/withpathsfrontmatter join only when work touches matching paths. - The session context is the sum of what loaded. A rule in the wrong home is missing for its audience or noise for everyone else.
Next: path rules in detail.
Step 3: Path rules load only where they match
Why this step: some rules are too narrow for a folder file, too noisy for the root file.
Files in .claude/rules/ can carry paths frontmatter. The rule loads only when the work touches a matching path:
---
paths:
- "src/**"
---
# Test conventions (illustrative)
- Name each test after the behaviour it checks.
- One assertion focus per test.
- Test files sit next to the code: Button.test.tsx beside Button.tsx.
- Test conventions scoped to
src/**stay out of sessions that only edit docs or config. - Migration rules scoped to
db/**load for database work only. - A rule file with no
pathsapplies everywhere. Sometimes right for a true global rule, but scope deliberately, never by accident. - Nested file or path rule? A nested file fits one folder's whole way of working. A path rule fits a pattern spanning folders, like every test file.
Exact load timing and glob behaviour are version-dependent: check the current docs.
Quick check: the unscoped rule.
Next: what the always-on pile costs.
Step 4: Worked example, the price of loading everything
Why this step: scoping buys back context on every session.
Made-up token counts for the harbor-web rule set:
- Project core rules: 600 tokens. User file: 150 tokens.
- Test conventions: 500. Migration rules: 450. Payments rules: 400.
Worked example (all numbers made-up):
1. Everything in the root file: 600 + 500 + 450 + 400 = 1,950 tokens, plus the 150 user tokens, so 2,100 tokens load at every session start.
2. Scoped: every session loads 600 + 150 = 750. A src session adds the test rules: 1,250. A db session: 1,200. A payments session: 1,150.
3. Team week, made-up mix: 240 sessions. 96 in src, 48 in db, 36 in payments, 60 at root level only.
4. Always-on total: 240 × 2,100 = 504,000 tokens a week.
5. Scoped total: 96 × 1,250 = 120,000; 48 × 1,200 = 57,600; 36 × 1,150 = 41,400; 60 × 750 = 45,000. Sum: 264,000 tokens.
6. Saving: 504,000 - 264,000 = 240,000 tokens a week, about 48 percent. At a made-up price of $3 per million input tokens, that is about $0.72 a week.
The money is trivial, and saying so matters. The real win is 850 to 1,350 tokens of context room per session, plus fewer irrelevant rules competing for Claude's attention. New to context budgets? See Tokens and context windows in the AI engineering course.
Next: sort the rule pile yourself.
Step 5: Hands-on lab, sort the rule pile
Why this exercise: the exam gives you a rule and four candidate homes. This is that question, eight times, on harbor-web.
Lab: Harbor and Pine's harbor-web rules started in the wrong files: a team rule sat in Kavish's personal file where nobody else loaded it, and a payments rule sat in the root file where it fired on marketing work. This lab runs in your browser and needs JavaScript enabled.
Teams that treat the project CLAUDE.md like code, short, reviewed, pruned when a rule stops earning its tokens, tend to keep it trusted. A root file that grows unchecked gets ignored, like an ignored linter. This is common practice, not a measured statistic.
The Deployed Lab jobs page (snapshot 15 Nov 2026) lists 367 open roles at 10 companies, median posted base about $243K (base pay only).
Mix-ups to avoid
- "I wrote it, so the team has it." A user file loads on your machine only. Team rules go in the committed project file.
- Personal taste in the project file. Your preferences become team law and start arguments. Keep them at user level.
- No paths means folder-only. The opposite: a rule with no
pathsapplies everywhere. Scope on purpose. - Fixing a conflict by adding a third rule. The nearer file wins. Edit or delete the rule at the wrong level.
- One giant root file is simpler. It taxes every session with rules for other work. Scope the narrow ones.
Chapter quiz
Five questions. Score 70% or more to mark this chapter complete.
Review this chapter in 5 minutes
Watch the whole chapter recapped: the three CLAUDE.md levels, nearer file wins on conflict, @import for shared standards, and path-scoped rules.
- Three levels: user file for personal defaults, project root file for committed team rules, nested files for one subtree.
- Team rules belong in the repo, where every machine loads them and review sees them. Personal preferences stay at user level.
@importpulls a shared file into a CLAUDE.md, so several repos follow one source.- On conflict, the nearer file wins. Fix conflicts at the level that is wrong.
- Path rules in
.claude/rules/load only forpathsmatches. Nopathsmeans everywhere. - Made-up worked example: scoping cut a team's weekly rule load from 504,000 to 264,000 tokens, about 48 percent.
Decision rule: for every rule, ask who needs it and where it applies. The answers pick the file. If you cannot answer both, the rule is not ready to write.
Independent exam preparation. Not affiliated with or endorsed by Anthropic.
Review
Glossary
- User-level CLAUDE.md
- Your personal configuration file at
~/.claude/CLAUDE.md. Example: "keep my summaries short". - Project CLAUDE.md
- The team file at the repo root, committed with the code. Example: "run the full test suite before a pull request".
- Nested CLAUDE.md
- A CLAUDE.md inside a folder, holding rules for that subtree. Example: payments rules in
src/payments/CLAUDE.md. - @import
- A line in a CLAUDE.md that pulls in another file's contents. Example: importing shared team standards.
- Precedence
- Which rule wins on a conflict: the nearer file. Example: the payments indent rule beats the root indent rule inside payments.
- .claude/rules/
- A folder of rule files that can be scoped to paths. Example: a migrations rule file for
db/**. - paths frontmatter
- Metadata at the top of a rule file listing the paths it applies to. Example:
paths: ["src/**"]. - Path-scoped rule
- A rule that loads only when work touches matching paths. Example: test conventions under
src/**. - Always-on context
- Content loaded into every session whether or not it is relevant. Example: migration rules during front-end work.
- Subtree
- A folder and everything under it. Example:
src/paymentsand all its files.
Next: "Slash commands and skills: share workflows with the whole team".