Skip to content
CCAR-F Prep

Task Statement 3.3·Domain 3 — 20% of exam

Path-Specific Rules for Conditional Convention Loading

Apply path-specific rules for conditional convention loading

Jump to practice →

Official Exam Guide Objectives

The objectives below are quoted from Anthropic's Claude Certified Architect – Foundations exam guide, v1.1. Read the exam guide summary for the full blueprint.

Knowledge of

  • .claude/rules/ files with YAML frontmatter paths fields containing glob patterns for conditional rule activation
  • How path-scoped rules load only when editing matching files, reducing irrelevant context and token usage
  • The advantage of glob-pattern rules over directory-level CLAUDE.md files for conventions that span multiple directories (e.g., test files spread throughout a codebase)

Skills in

  • Creating .claude/rules/ files with YAML frontmatter path scoping (e.g., paths: ["terraform/**/*"]) so rules load only when editing matching files
  • Using glob patterns in path-specific rules to apply conventions to files by type regardless of directory location (e.g., **/*.test.tsx for all test files)
  • Choosing path-specific rules over subdirectory CLAUDE.md files when conventions must apply to files spread across the codebase

What You Need to Know

Path-specific rules make a convention conditional on what you are editing rather than on where you launched Claude. That closes a gap neither root CLAUDE.md nor a directory-level file covers well: a rule that belongs to a file type which happens to be scattered across the whole tree. The one-line mental model: CLAUDE.md scopes by location; path rules scope by pattern. When the thing you want to describe is a file type rather than a place, glob rules are the mechanism.

How Path-Specific Rules Work

The files live in .claude/rules/, and each one opens with YAML frontmatter carrying a paths field of glob patterns. Whatever the file says applies only while you are working on files those globs match.

---
paths: ["terraform/**/*"]
---
# Terraform Conventions

- Resource names in snake_case, no exceptions
- Every resource carries environment and owning-team tags
- AMI IDs come from data sources; a hardcoded one is a review blocker
- A module is incomplete without variables.tf, outputs.tf and a README.md

Open a file matching terraform/**/*, and the rules arrive with it. Open a React component or a request handler, and they do not — they stay out of context entirely until the moment they describe the work in front of you.

What triggers loading

The guide says rules load "when editing matching files"; mechanically, the trigger is Claude working with a matching file, and reading one is enough. Nothing has to be invoked, and Claude does not wait for a write: a rule that only arrived at the edit would be missing while Claude reads the file and plans the change. The reverse also holds — a tool call that touches no matching file loads nothing, so a rule does not fire just because Claude is busy.

When a file matches several rules

Every rule whose globs match loads. Button.test.tsx can match both a React rule scoped to **/*.tsx and a testing rule scoped to **/*.test.*, and Claude gets both. Rules are combined, not selected between: no "most specific glob wins" tiebreak exists, so two matching rules that contradict each other are a conflict for you to remove, not one the tooling settles.

Glob Patterns Match Across the Entire Codebase

This is the property that makes them worth using. **/*.test.tsx reaches every test file in the repository, no matter how deep or how scattered. A typical layout makes the point:

src/
  components/
    Button.tsx
    Button.test.tsx
  api/
    auth.ts
    auth.test.ts
  utils/
    format.ts
    format.test.ts
  pages/
    dashboard/
      Dashboard.tsx
      Dashboard.test.tsx

Every test sits beside the thing it tests, which puts them in four directories here and rather more in a real project. One rule file declaring paths: ["**/*.test.tsx", "**/*.test.ts"] reaches all of them without knowing where any of them are. The exam guide's own preparation exercise writes the same idea as one pattern, paths: ["**/*.test.*"] for testing conventions: any test file, any extension, anywhere.

Reading Glob Patterns at a Glance

Stems put a pattern in front of you and ask whether it covers the files in the story. These are the shapes to read instantly:

PatternMatches
**/*.tsevery .ts file in any directory
src/**/*everything under src/, at any depth
src/**/*.{ts,tsx}both extensions anywhere under src/ (brace expansion)
**/*.test.*any test file, any extension, anywhere
src/components/*.tsx.tsx files directly in that directory only; a single * stops at one level, so subfolders are not matched
*.mdMarkdown files anywhere under the project, not just at the root
/*.mdMarkdown files in the project root only

Two edge cases sit beyond what the guide examines. Each brace group multiplies into several patterns, and the whole paths list shares a budget of 1,000 expanded patterns; a pattern that would exceed it is used unexpanded, and its literal braces then match nothing. And [ opens a bracket expression (one character from a set), so a filename containing a literal [ must be escaped, as in photos \[2024/**, or that pattern matches nothing.

The practical rule that follows from the table: scope a rule to the files as they sit in the repository today, using one paths array to combine shapes. A terraform/ tree plus stray .tf files beside individual services needs ["terraform/**/*", "**/*.tf"] in one rule file.

Why Not Directory-Level CLAUDE.md?

Because it reaches one directory. Covering tests spread across 50-odd directories would mean a CLAUDE.md in each of them, which buys you:

  • 50-odd copies of one set of conventions
  • a new copy to write every time someone adds a directory containing tests
  • 50-odd edits every time a convention changes
  • copies that fall out of step, because eventually one of those edits gets missed

A single glob replaces all of that, and there is nothing to keep in sync because there is only ever one file.

One glob reaches them all — no copies to keep in sync Test files sit beside the code they cover in four different directories: components, api, utils, and pages/dashboard. Covering them with directory-level CLAUDE.md files means one copy of the same conventions in each directory — and when a convention changes, editing one copy while the other three stay unedited is how they fall out of step. A single path-specific rule file in .claude/rules/ with paths matching **/*.test.tsx and **/*.test.ts reaches every one of those test files directly, regardless of which directory it sits in, with nothing to keep in sync because there is only ever one file. Directory-level CLAUDE.md components/ Button.test.tsx api/ auth.test.ts utils/ format.test.ts pages/dashboard/ Dashboard.test.tsx CLAUDE.md CLAUDE.md CLAUDE.md CLAUDE.md one copy per directory ✓ edited ✕ stale a missed edit starts the drift Path-specific rule components/ Button.test.tsx api/ auth.test.ts utils/ format.test.ts pages/dashboard/ Dashboard.test.tsx .claude/rules/testing.md paths: ["**/*.test.tsx", "**/*.test.ts"] ✓ one glob reaches all four, wherever they sit a naming pattern, not a location — that's what globs are for
1 / 6Swipe diagram ↔

One glob reaches them all — no copies to keep in sync, step 1: Four directories, each with a source file and its test

Why Not Root CLAUDE.md?

Because it loads regardless. Terraform conventions in the root file are in context while you edit React components; test conventions are in context while you write request handlers. Neither is doing anything except consuming budget that the current work needs — and on a project with several convention sets, the ones that are irrelevant will usually outnumber the ones that are not.

Only the matching rule loads — not the whole set With every convention parked in root CLAUDE.md, editing format.test.ts loads Testing, API, and Terraform conventions all at once — and switching to src/api/auth.ts changes nothing, the same three still sit in context, most of them irrelevant to the file open. Splitting the same conventions into path-specific rules under .claude/rules/ changes this: editing format.test.ts loads only the testing rule, and switching to src/api/auth.ts brings in the API conventions while Terraform never loads. Path scoping is a context-budget mechanism as much as an organisational one. Editing: format.test.ts src/api/auth.ts format.test.ts src/api/auth.ts everything sits in root CLAUDE.md split into path-specific rules context window Testing Testing Testing ✓ API API API ✓ Terraform Terraform unchanged — budget spent on Terraform while writing a handler only the matching rule loads switching file changes which rule loads .claude/rules/ testing.md api-conventions.md terraform.md each scoped by paths path scoping is a context-budget mechanism, not just an organisational one
1 / 6Swipe diagram ↔

Only the matching rule loads — not the whole set, step 1: Root CLAUDE.md, editing format.test.ts — everything loads

A root file with one header per area has a second weakness beyond cost: it relies on Claude inferring which section applies to the file in front of it. A glob is an explicit match against the file path, so the right conventions arrive by rule rather than by judgement. That is the reason the official sample question gives for rejecting the root-file option, ahead of token cost.

Worked example: what one edit loads

A project keeps 60 lines of universal standards plus five convention sets: React 180 lines, API 160, database 140, testing 150, Terraform 170 (800 lines of conventions in all).

ArrangementEditing a React component (.tsx)Editing Button.test.tsxEditing a request handler
Everything in root CLAUDE.md860 lines860 lines860 lines
Root CLAUDE.md (60) + five path-scoped rules60 + 180 = 24060 + 180 + 150 = 390 (React and testing both match)60 + 160 = 220

The saving is compounded by what it removes: less irrelevant instruction competing for attention, as well as fewer tokens. Instructions that never bear on the current file still sit in context and dilute the ones that do; the current documentation's target for a CLAUDE.md file is under 200 lines.

Practical Rule File Examples

Test conventions across the entire codebase:

---
paths: ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"]
---
# Test Conventions

- describe/it names should read as sentences describing behaviour
- Every file covers at least one success path and one failure path
- Build test data through factory functions rather than inline literals
- Mock at the module boundary; mocking individual functions couples tests to internals
- Assert on what the code does, never on how it does it

API conventions for any route handler:

---
paths: ["src/api/**/*", "**/routes/**/*", "**/*.controller.ts"]
---
# API Conventions

- Every response takes the shape { data, error, metadata }
- Validate with Zod at the handler boundary, before anything else runs
- Error responses carry the request ID
- State rate limits explicitly; inheriting a default is not a decision

Infrastructure-as-code conventions:

---
paths: ["terraform/**/*", "**/*.tf", "infrastructure/**/*"]
---
# Infrastructure Conventions

- State lives in a remote backend; local state is never committed
- Environments are separated by workspace
- Modules are versioned and carry a CHANGELOG

Each example puts several shapes (a directory tree, a nested folder name, a suffix) in one array, so one file covers every location where that kind of file lives and there is one place to edit when a convention changes.

When to Use Each Approach

ScenarioBest approach
Standards every line of code should followRoot CLAUDE.md
Conventions belonging to one package directory, where the team works on that directory as a unitDirectory-level CLAUDE.md
Conventions belonging to a file type wherever it appearsPath-specific rules with glob patterns
Conventions for a whole subsystem that happens to be one directoryEither; a rule with paths: ["subsystem/**/*"] is also legitimate
A procedure someone runs deliberately, now and thenSkills in .claude/skills/
Something that must happen every time, without exceptionA hook (rules and CLAUDE.md are guidance, not enforcement)

The scenario to watch for is tests co-located with the code they cover, across a large tree. It appears repeatedly, and glob-scoped rules are the answer every time — the giveaway is that the files share a naming pattern but no common location.

The subsystem row is the one place both answers are defensible. A rule scoped to packages/api/**/* replicates a directory CLAUDE.md while keeping every convention set side by side in .claude/rules/, where it can be reviewed in one place, and a restructure means editing one pattern rather than moving or copying CLAUDE.md files. So when a stem asks for the "most maintainable" option for a single directory, a path rule is not wrong; it is only required when the files are scattered.

Verifying Which Rules Loaded

A rule file being discovered is not the same as it being loaded. Every .md under .claude/rules/ is found at launch, but one that declares paths stays out of context until a matching file is in play. The exam guide's own preparation exercise asks you to "Test that rules load only when editing matching files": open a file that matches one rule, check what is loaded, then open a file that matches another and check again. A rule whose globs match neither file should appear in neither check.

After /compact

Compaction treats these files differently, which explains instructions that seem to vanish after /compact. The project-root CLAUDE.md is re-read from disk and re-injected after compaction. Nested CLAUDE.md files and paths: rules are not; they load again the next time Claude works with a file they cover. So an instruction that "disappeared after /compact" was either given only in conversation, in a nested CLAUDE.md that has not reloaded yet, or in a path rule whose files Claude has not touched since.

Deep Dive

The paths frontmatter mechanism, precisely

Rules can be scoped to specific files using YAML frontmatter with a paths field: "these conditional rules only apply when Claude is working with files matching the specified patterns." Rules in .claude/rules/ are discovered recursively, so .md files can be organised into subdirectories as a project grows — .claude/rules/frontend/components.md is discovered the same as a flat file.

Sourcecode.claude.com › memoryfetched 2026-07-30

Glob syntax and brace expansion

paths accepts standard glob patterns (**/*.ts for any TypeScript file at any depth) and brace expansion to match multiple extensions in a single pattern, plus multiple patterns in the same array:

---
paths:
  - "src/**/*.{ts,tsx}"
---

Sourcecode.claude.com › memoryfetched 2026-07-30

Rules without paths frontmatter

A rule file that omits paths entirely isn't conditional — it "is loaded at launch with the same priority as .claude/CLAUDE.md." That's the default for a rules file with no frontmatter at all: always-on, just like the earlier project CLAUDE.md.

Sourcecode.claude.com › memoryfetched 2026-07-30

User-level rules and load order

Personal rules in ~/.claude/rules/ apply to every project on your machine, exactly the way ~/.claude/CLAUDE.md does. Load order does not settle conflicts: "Claude Code loads user-level rules before project rules, so a project rule appears later in Claude's context than a user rule. Neither set overrides the other: if a user rule and a project rule conflict, Claude may follow either one." The fix for a genuine conflict is to remove it, not to rely on which file arrived last.

Sourcecode.claude.com › memoryfetched 2026-11-19

No paths field — loaded at launch, same as CLAUDE.md A rule file under .claude/rules/ carrying a paths field only applies once a matching file is opened; a rule file with no frontmatter at all is not conditional — it loads at launch with the same priority as .claude/CLAUDE.md. Separately, personal rules in ~/.claude/rules/ apply to every project on the machine and are loaded before project rules, so a project rule appears later in context than a user rule; neither set overrides the other, and on a genuine conflict Claude may follow either one. terraform.md paths: ["terraform/**/*"] style.md no frontmatter waiting for a match loads every session no paths field — not conditional, same priority as CLAUDE.md load order ~/.claude/rules/ user — loads first .claude/rules/ project — loads later .claude/rules/ neither overrides later in context, yet on a conflict Claude may follow either
1 / 6Swipe diagram ↔

No paths field — loaded at launch, same as CLAUDE.md, step 1: Two rule files — one scoped, one not

Quick Reference

ItemValue / behaviour
Rule file location.claude/rules/*.md, discovered recursively (subdirectories included); symlinks are supported
paths frontmatterYAML array of glob patterns; rule loads only for matching files
What triggers loadingClaude working with (reading is enough) a matching file; no invocation, no write needed
File matching several rulesall matching rules load; no specificity tiebreak
Glob syntaxstandard globs (**/*.ts) plus brace expansion (src/**/*.{ts,tsx})
Any test file, anywhere**/*.test.*
* vs **src/components/*.tsx = that directory only; src/**/*.tsx = any depth
*.md vs /*.md*.md = anywhere under the project; /*.md = project root only
Rule with no pathsloads at launch — same priority as .claude/CLAUDE.md
@ importsload at launch; they organise files but save no context
User-level rules~/.claude/rules/ — every project on the machine
User vs project rule conflictuser rules load first, project rules later; neither overrides, Claude may follow either
Verify what loadedexam answer: /memory; current product: /context all, under Memory files
After /compactroot CLAUDE.md re-injected; nested CLAUDE.md and path rules reload when a matching file is next touched
Directory-level CLAUDE.md vs path rulesdirectory CLAUDE.md = one directory; path rules = one file type, any directory
Root CLAUDE.md vs path rulesroot CLAUDE.md always loads; path rules load only for matching files (token savings)

Exam Traps

More wrong answers, and why each fails

Tempting answerWhy it failsChoose instead
A pattern anchored on one folder, such as src/components/*.test.tsx, when tests live everywhereIt under-matches: tests elsewhere, and in subfolders of that one, are edited with no conventions loadedA suffix glob: **/*.test.tsx or **/*.test.*
Scope to the canonical tree only, because stray files "should be moved there anyway"The strays are edited unguided until the migration landsAdd a second pattern for the strays, such as **/*.tf, in the same array
paths: ["**/*"] with a note in the body telling Claude to apply it only to certain filesIt loads for every file and asks Claude to self-restrict, which is guidance where the frontmatter gives an exact matchName the files in paths
One rule file per location, each with an identical bodyEvery change needs several edits, and the copies driftOne file whose paths array lists every location

How This Is Tested

Stem signalAnswerWrong-answer pattern beside it
A file type scattered across directories, "automatically", "regardless of location".claude/rules/ file with glob pathsA CLAUDE.md per directory; a skill; a root file with per-area headers
"Terraform conventions should only load when someone touches infrastructure"paths: ["terraform/**/*"] (plus **/*.tf if stray files exist)Root CLAUDE.md; a directory CLAUDE.md that misses the strays; a skill
"CLAUDE.md is 800 lines and context is tight"Split into path-scoped rules@ imports; rule files with no paths
"Directory CLAUDE.md or path rule?"Ask whether the convention is bound to a place or to a file typeChoosing by habit; for one self-contained directory either is acceptable
A rule fires for some of the intended files but not othersWiden the glob (* to **, a suffix instead of a folder)Enumerate directories one by one; drop paths so it always loads
User rule and project rule contradict each otherRemove the contradiction"The project rule wins because it loads later"

Official sample question 6, option by option

The stem: "React components use functional style with hooks, API handlers use async/await with specific error handling, and database models follow a repository pattern. Test files are spread throughout the codebase alongside the code they test (e.g., Button.test.tsx next to Button.tsx), and you want all tests to follow the same conventions regardless of location." It asks for "the most maintainable way to ensure Claude automatically applies the correct conventions when generating code".

OptionVerdictThe official explanation
A. "Create rule files in .claude/rules/ with YAML frontmatter specifying glob patterns to conditionally apply conventions based on file paths"CorrectGlob patterns (e.g., **/*.test.tsx) allow "conventions to be automatically applied based on file paths regardless of directory location, essential for test files spread throughout the codebase."
B. "Consolidate all conventions in the root CLAUDE.md file under headers for each area, relying on Claude to infer which section applies"WrongIt "relies on inference rather than explicit matching, making it unreliable."
C. "Create skills in .claude/skills/ for each code type that include the relevant conventions in their SKILL.md files"WrongIt "requires manual skill invocation or relies on Claude choosing to load them, contradicting the need for deterministic "automatic" application based on file paths."
D. "Place a separate CLAUDE.md file in each subdirectory containing that area's specific conventions"WrongIt "can't easily handle files spread across many directories since CLAUDE.md files are directory-bound."

Two phrases in the stem decide it. "Automatically" rules out C, which needs invocation or the model's choice. "Regardless of location" rules out D, which is bound to directories. B fails on reliability, not only on cost: inference is not matching.

Practice Scenario

Your team's test conventions live in .claude/rules/testing.md, scoped to paths: ["src/components/**/*.test.tsx"]. Component tests follow them closely. Reviewers keep flagging inconsistent assertions and mock placement in the tests under src/api/, src/utils/ and src/pages/, each of which sits beside the code it covers. What's the most effective first step?

Practice Questions

Exam simulator

Question 1 of 13

Scenario · Code Generation with Claude Code

Your Storybook conventions sit in the root CLAUDE.md and load into every session, although only story files need them. Story files (*.stories.tsx) live beside their components in about forty directories across apps/web, apps/admin and packages/ui, and new component folders appear most sprints. What change would most effectively scope these conventions?

Sources