Skip to content
CCAR-FAcademy
Domain 3 · Statement 3.3 3 of 6
3.3

Apply path-specific rules for conditional convention loading

  • Rule files in .claude/rules/ can declare YAML frontmatter paths with glob patterns for conditional activation.
  • A path-scoped rule loads only when files matching its globs come into play, cutting both irrelevant context and token usage. The guide says "editing"; in Claude Code the trigger is Claude reading a matching file, so exploration counts too.
  • Use globs (e.g. **/*.test.tsx) when a convention applies to a file type spread across many directories.
  • Use a directory-level CLAUDE.md only when the convention genuinely belongs to one location in the tree.
  • Glob rules express a cross-cutting convention once, instead of duplicating it into a CLAUDE.md in every directory that contains such files.

Path-specific rules solve a targeting problem. Directory-level CLAUDE.md files scope conventions by location; path-specific rules scope them by file pattern. Many real conventions are file-type conventions, and those files are scattered across the tree.

A rule file in .claude/rules/ can carry YAML frontmatter with a paths field containing glob patterns.33 The rule is then activated conditionally: it loads only when a file that is read or edited matches one of those globs. A Terraform rule with paths: ["terraform/**/*"] is invisible while you work on the React frontend, and appears the moment you touch infrastructure code.

Why conditional loading matters

Two effects, and the exam cares about both:

  • Less irrelevant context. Claude is not reading Terraform naming conventions while fixing a CSS bug, so the instructions it does see are all relevant to the task.
  • Lower token usage. Always-loaded memory is paid for in every session. Path-scoped rules are paid for only in the sessions that need them, which is what lets a large team keep a genuinely detailed rule set without bloating every conversation.

Globs vs directory-level CLAUDE.md

This is the discrimination the exam tests. Use a directory-level CLAUDE.md when the convention really is about a place: everything under services/billing/ must go through the ledger client. Use a path-scoped rule when the convention is about a kind of file that spans multiple directories:35

  • **/*.test.tsx — test conventions, when tests sit next to the code they test all over the repo.
  • **/migrations/*.sql — migration safety rules, one folder per service.
  • terraform/**/* — infrastructure conventions.

With directory-level files you would have to duplicate the same test conventions into a CLAUDE.md in every directory that happens to contain tests, and then keep those copies in sync forever. A single glob-scoped rule file expresses the intent once, applies it by file type regardless of directory location, and stays out of context when it does not apply.

Path-scoped rule or skill?

Migrations show up on both sides of this line, so fix the discriminator now. A procedure you invoke — the steps for generating a migration — belongs in a skill (3.2). A convention that should apply whenever matching files come into play — migrations must be reversible — belongs in a path-scoped rule. Same subject, different trigger: one is called on demand, the other activates from the files read or edited.

The mental model: paths turns a rule from "always on" into "on when relevant", and the glob is how you express relevance.

One operational note: after /compact, a project-root CLAUDE.md is re-read from disk, but path-scoped rules are not — they reload the next time a matching file comes up.33

How a path-scoped rule decides whether to loadMake clear that the paths glob in a rule file is evaluated against the files read or edited, so only matching rules enter the session context while non-matching rules cost nothing.Session starts touching filesSessionstartstouchingfilesRead .claude/rules/ frontmatterRead.claude/rules/frontmatterRule has a paths field?Rule has apaths field?Files read or edited match a glob?Files read oredited matcha glob?Rule loaded into contextRule loadedinto contextRule stays out of contextRule staysout ofcontextAlways loadedAlwaysloadedenumerate rulefilesper rule fileno paths fieldunconditionalyesmatch, e.g.**/*.test.tsxno match, no tokencost
How a path-scoped rule decides whether to load

Make clear that the paths glob in a rule file is evaluated against the files read or edited, so only matching rules enter the session context while non-matching rules cost nothing.

one transition at a time

Hover a rule outcome to see an example glob and the kind of read or edit that would trigger it.

Test conventions that follow the files, not the folders

Scenario 2 · Code Generation with Claude Code

A React monorepo colocates tests: components/Button/Button.test.tsx, hooks/useCart.test.tsx, packages/api/src/resolvers/order.test.tsx. The team has firm test conventions (React Testing Library only, no snapshot tests, one describe per exported symbol).

Encoding this as directory-level CLAUDE.md files would mean a copy in dozens of directories. Instead one rule file scoped with paths: ["**/*.test.tsx"] applies wherever a test file lives, and contributes nothing until a test file is read or edited.

markdown
---
description: Frontend test conventions
paths: ["**/*.test.tsx", "**/*.test.ts"]
---

# Test conventions

- Use React Testing Library. Never add snapshot tests.
- Query by accessible role or label, never by test id.
- One top-level describe block per exported symbol.
- Shared fixtures live in tests/fixtures/; do not build ad hoc factories.
- Assert on user-visible behavior, not on internal state.
.claude/rules/testing.md — activated only when a test file is read or edited

Infrastructure rules that stay out of application sessions

Scenario 4 · Developer Productivity with Claude

An infra team maintains long Terraform conventions — module structure, required tags, no inline provider blocks, remote state layout. Application engineers touch terraform/ a few times a quarter.

Scoping the rule to paths: ["terraform/**/*"] means the conventions are present and authoritative when someone edits infrastructure, and absent the rest of the time. Compare the alternative: the same text in the root CLAUDE.md would be loaded in every frontend session forever.

yaml
---
description: Terraform module and tagging conventions
paths:
  - "terraform/**/*"
  - "**/*.tf"
---
# body: the actual conventions follow as markdown
The frontmatter is what does the scoping

Choosing between the two mechanisms

Ask "is this rule about a place or about a kind of file?"

Convention Right mechanism
Everything in services/billing/ must use the ledger client Directory-level services/billing/CLAUDE.md
All test files, wherever they live, follow these conventions .claude/rules/testing.md with paths: ["**/*.test.tsx"]
SQL migrations in every service must be reversible .claude/rules/migrations.md with paths: ["**/migrations/*.sql"]
Project build and run instructions Root CLAUDE.md (always loaded)

The failure mode of getting this wrong is not a broken build — it is silent drift: duplicated directory files fall out of sync, or a monolithic always-loaded file quietly eats the context budget.

  • Duplicating the same test or migration conventions into a directory-level CLAUDE.md in every folder that contains such files, instead of one glob-scoped rule because the copies inevitably drift apart.
  • Putting cross-cutting file-type conventions in the always-loaded root CLAUDE.md instead of a path-scoped rule because every unrelated session then pays the token cost for context it cannot use.
  • Writing an overly broad glob such as **/* in a paths field because the rule is then effectively always loaded and you have lost the benefit of conditional activation.
  • The give-away phrase is "spread throughout the codebase" or "regardless of directory" — that always points to glob-based paths scoping over directory-level CLAUDE.md.
  • When a stem complains about token usage or irrelevant instructions, prefer the answer that makes rules conditional, not the one that deletes or shortens them.
  • A tempting distractor is "add a CLAUDE.md to each directory containing tests" — it works today and is a maintenance trap tomorrow; the exam wants the single glob-scoped rule.
References — 2 sources
  1. How Claude remembers your project Anthropic Settles the precedence question the guide leaves open: discovered CLAUDE.md files are concatenated in load order rather than overriding each other. Also adds the two locations the three-level table omits — machine-wide managed policy, which individual settings cannot exclude, and gitignored `CLAUDE.local.md` — and states that path-scoped rules trigger when Claude *reads* a matching file, that `@path` imports load at launch so they do not reduce context, and that rules with `paths:` are not re-injected after `/compact`.
  2. Explore the .claude directory Anthropic The annotated map of everything Claude Code reads under `.claude/`, which shows `@import` targets, `rules/` with `paths:` globs and directory-level files as entries in one documented layout rather than isolated mechanisms.
All sources verified ·

Live product docs — where they differ from the exam guide, answer from the guide. All references

Exam guide, verbatim — what is measured

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
Back to top