3.3 Path-Specific Rules for Conditional Convention Loading
What You Need to Know
Section titled “What You Need to Know”Root CLAUDE.md loads for every session. A directory-level CLAUDE.md applies to files in that one directory. A path-specific rule loads its conventions only when you edit files that match its glob patterns (patterns that describe a set of file paths). A path-specific rule covers a case that neither CLAUDE.md handles well: one file type that is spread across many directories.
This lesson uses one made-up example throughout: a catering firm whose ordering system has team-wide standards and Terraform hosting files. Its test files sit beside source files in many folders.
How Path-Specific Rules Work
Section titled “How Path-Specific Rules Work”Rule files are in .claude/rules/. Each rule file starts with YAML frontmatter (a block of settings written in YAML) whose paths field lists glob patterns. The rules load only when you edit a matching file.
---paths: ["terraform/**/*"]---# Terraform Conventions
- Use snake_case for all resource names- Tag every resource with environment and team labels- Never hardcode AMI IDs — use data sources- All modules must have a variables.tf, outputs.tf, and README.mdEdit a file that matches terraform/**/* and these rules load automatically. Edit a React component or an API handler and they do not load. The catering firm’s hosting conventions stay out of context while someone edits the menu pages.
Glob Patterns Match Across the Entire Codebase
Section titled “Glob Patterns Match Across the Entire Codebase”In a glob, ** matches across directory levels. So **/*.test.tsx matches every test file in the codebase, wherever it is. Take a typical project structure:
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.tsxTest files are next to their source files in four directories. A rule with paths: ["**/*.test.tsx", "**/*.test.ts"] applies the same test conventions to every one of those test files, automatically.
Why Not Directory-Level CLAUDE.md?
Section titled “Why Not Directory-Level CLAUDE.md?”A directory-level CLAUDE.md covers only its own directory. Test files across 50+ directories would need a CLAUDE.md in each. That means:
- 50+ copies of the same conventions
- Every new directory with tests needs a new copy
- Any convention change requires updating all 50+ files
- Inevitable differences between copies, as some copies become out of date
One rule file and one pattern avoid all four problems. The catering firm changes a test convention by editing one file.
Why Not Root CLAUDE.md?
Section titled “Why Not Root CLAUDE.md?”Root CLAUDE.md loads in every session, whichever files you edit. Terraform conventions in root CLAUDE.md use tokens while you edit React components. Test conventions in root CLAUDE.md load while you write API handlers. The catering firm’s hosting conventions would fill context during a menu fix.
Practical Rule File Examples
Section titled “Practical Rule File Examples”Test conventions across the entire codebase
Section titled “Test conventions across the entire codebase”---paths: ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"]---# Test Conventions
- Use describe/it blocks with descriptive names that read as sentences- Each test file must have at least one happy path and one error case- Use factory functions for test data, not inline object literals- Mock external services at the module boundary, not individual functions- Assert behaviour, not implementation detailsAPI conventions for any route handler
Section titled “API conventions for any route handler”---paths: ["src/api/**/*", "**/routes/**/*", "**/*.controller.ts"]---# API Conventions
- All endpoints return { data, error, metadata } response shape- Use Zod schemas for request validation at the handler boundary- Log request ID on every error response- Rate limiting configuration must be explicit, not inherited from defaultsInfrastructure-as-code conventions
Section titled “Infrastructure-as-code conventions”---paths: ["terraform/**/*", "**/*.tf", "infrastructure/**/*"]---# Infrastructure Conventions
- State files must reference remote backends, never local- Use workspaces for environment separation- Every module must be versioned with a CHANGELOGWhen to Use Each Approach
Section titled “When to Use Each Approach”| Scenario | Best approach |
|---|---|
| Universal team standards that apply to all code | Root CLAUDE.md |
| Conventions for one specific package directory | Directory-level CLAUDE.md |
| Conventions for a file type spread across many directories | Path-specific rules with glob patterns |
| Task-specific workflows invoked on demand | Skills in .claude/skills/ |
The catering firm puts team-wide standards in root CLAUDE.md, and its test and Terraform conventions in path-specific rules.
In the exam
Section titled “In the exam”The exam frequently presents test files that are next to their source files in many directories. The answer is always path-specific rules with glob patterns. Wrong options use root CLAUDE.md or a CLAUDE.md in every directory.
Path-specific rules are one of Domain 3’s six task statements. As of 2026, Anthropic has no standalone Claude Code certification, and no other exam tests Claude Code as heavily as this one.
Exam Traps
Section titled “Exam Traps”Sources
Section titled “Sources”- Claude Code Memory and Rules Documentation — Anthropic
- Claude Certified Architect Foundations Exam Guide — Task Statement 3.3 — Anthropic
- Claude Certified Architect Foundations Exam Guide — Sample Question 6 — Anthropic
- CCAR-F Exam Guide v1.0: Task Statement 3.3 — Anthropic
Exam Simulator
Section titled “Exam Simulator”Five exam-style multiple-choice questions on Path-Specific Rules for Conditional Convention Loading. Pick an answer, then open the explanation.
Question 1
Section titled “Question 1”A codebase has test files co-located with source files throughout 50+ directories (e.g., Button.test.tsx next to Button.tsx). The team wants all tests to follow the same conventions regardless of location. What is the most maintainable approach?
- A. Create a skill in .claude/skills/ that includes the test conventions and instruct developers to invoke it before writing tests
- B. Place a CLAUDE.md file in every directory containing test files
- C. Add all test conventions to the root CLAUDE.md file
- D. A rule file in .claude/rules/ with frontmatter paths: [“/*.test.tsx”, “/*.test.ts”]
Answer & explanation
Correct: D
- A is wrong: This approach relies on developers remembering to invoke the skill for every test edit — human discipline is the weak link. Skills can auto-activate via a paths frontmatter, but even then they load on-demand as a task-style workflow rather than as always-in-context guidance. Path-specific rules in .claude/rules/ load into context automatically when Claude reads a matching file, with no human step.
- B is wrong: With 50+ directories, this creates massive duplication. Every convention change requires updating 50+ files. New directories need new copies. Drift is inevitable.
- C is wrong: Root CLAUDE.md loads for every session. Test conventions would consume tokens even when editing non-test files like API handlers or database models.
- D is correct: Glob patterns in .claude/rules/ match files by pattern across the entire codebase. The conventions load automatically when editing any test file, regardless of directory. One file covers all 50+ directories with zero maintenance as new test files are added.
Question 2
Section titled “Question 2”A project has Terraform infrastructure files in terraform/ and application code in src/. The Terraform conventions include specific resource naming rules that are irrelevant to application code. Where should these conventions be configured for maximum token efficiency?
- A. In root CLAUDE.md so they are always available
- B. In .claude/rules/terraform.md with paths: [“terraform//*”, “/*.tf”] in the YAML frontmatter
- C. In a directory-level CLAUDE.md placed inside terraform/ alongside the module definitions themselves
- D. In a skill at .claude/skills/terraform/SKILL.md that developers invoke before editing any module
Answer & explanation
Correct: B
- A is wrong: Root CLAUDE.md loads for every session. Terraform naming rules would consume tokens when editing React components or API handlers – completely wasted context.
- B is correct: Path-specific rules with glob patterns cover both the terraform/ directory tree and any .tf files anywhere in the codebase. They load only when editing matching files, providing maximum token efficiency.
- C is wrong: A directory-level CLAUDE.md only covers the terraform/ directory. If .tf files exist elsewhere in the codebase (infrastructure-as-code modules in other locations), they would not be covered.
- D is wrong: Skills load on-demand as task-style workflows rather than as always-in-context guidance. Infrastructure conventions should shape every edit to an infrastructure file, which is exactly what .claude/rules/ with path scoping provides.
Question 3
Section titled “Question 3”A developer is editing a file at src/api/auth.ts. The project has three rule files: .claude/rules/testing.md (paths: [“/*.test.ts”]), .claude/rules/api-conventions.md (paths: [“src/api//”]), and .claude/rules/terraform.md (paths: [“terraform/**/”]). Which rules are loaded?
- A. Only api-conventions.md, because the file matches src/api/**/*
- B. All three, because they are all in the .claude/rules/ directory
- C. api-conventions.md and testing.md, because the file is in src/
- D. None, because path-specific rules require explicit invocation
Answer & explanation
Correct: A
- A is correct: src/api/auth.ts matches the pattern src/api/**/* in api-conventions.md. It does not match /*.test.ts (not a test file) or terraform//* (not in the terraform directory).
- B is wrong: Path-specific rules only load when the file being edited matches the glob patterns in the frontmatter. Being in .claude/rules/ does not mean automatic loading for all files.
- C is wrong: testing.md requires files matching **/*.test.ts. auth.ts is not a test file, so testing rules do not load.
- D is wrong: Path-specific rules load into context automatically when Claude reads a matching file. They do not require explicit invocation. Skills, by contrast, load on-demand as task-style workflows.
Question 4
Section titled “Question 4”A team moves all their conventions from root CLAUDE.md into path-specific rules in .claude/rules/. When a developer edits a utility function in src/utils/format.ts, they notice that the general coding standards (naming, error handling) no longer apply. What went wrong?
- A. Path-specific rules cannot contain general coding standards
- B. The developer needs to run /memory to reload the configuration
- C. The glob misses utility files, or they belong in the root
- D. .claude/rules/ files only work for test and infrastructure files
Answer & explanation
Correct: C
- A is wrong: Path-specific rules can contain any type of convention. The issue is how the glob patterns are defined.
- B is wrong: /memory is a diagnostic tool that shows loaded files. It does not reload or trigger loading.
- C is correct: If general coding standards apply to ALL files, they either need a glob pattern like [“**/*”] or they should remain in root CLAUDE.md. Moving universal standards to path-scoped rules without a catch-all pattern breaks their universal application.
- D is wrong: .claude/rules/ files work for any file type. The glob pattern determines which files trigger loading, not the content of the rules.
Question 5
Section titled “Question 5”Which of the following is the primary advantage of path-specific rules over root CLAUDE.md for file-type-specific conventions?
- A. Path-specific rules are version-controlled while root CLAUDE.md is not
- B. They load only when editing matching files, saving context tokens
- C. Path-specific rules support YAML frontmatter while root CLAUDE.md does not
- D. Path-specific rules can be shared via git while root CLAUDE.md cannot
Answer & explanation
Correct: B
- A is wrong: Both path-specific rules and root CLAUDE.md are version-controlled when placed in the repository.
- B is correct: Token efficiency is the primary advantage. Path-specific rules load only for matching files, so Terraform conventions do not consume tokens when editing React components. Root CLAUDE.md loads everything for every session.
- C is wrong: While path-specific rules use YAML frontmatter for path scoping, this is a mechanism, not the primary advantage. The advantage is the conditional loading that the frontmatter enables.
- D is wrong: Both root CLAUDE.md and .claude/rules/ files are inside the repository and shared via git.