PrepGenAICerts

.claude/rules/: Scoped by Frontmatter, Not by Folder

Core

Identify Claude Code's core component types · Difficulty 2/5

0%
rules-filesfrontmatterpath-scopingclaude-code

Explanation

A Second, Narrower Layer of Rules

CLAUDE.md is the always-on baseline -- it loads into every session, unconditionally. Rules instruction files are a distinct mechanism that adds a narrower layer on top of that baseline: they let a piece of guidance apply only where it's relevant, instead of loading into every session and diluting the file that's supposed to hold universal context.

Rules files live in a project's .claude/rules/ directory, one Markdown file per rule (or per related group of rules), each with a YAML frontmatter block at the top.

Scope Comes From Frontmatter, Not From Where the File Sits

This is the one fact worth knowing cold: a rules file's scope is controlled entirely by a paths glob declared in its YAML frontmatter -- not by which subdirectory of .claude/rules/ the file happens to live in. Placing a file at .claude/rules/database/transactions.md versus .claude/rules/transactions.md has zero effect on when it loads; only the paths field does that.

---
paths:
  - "src/db/**/*.sql"
---
All SQL in this module must include an explicit transaction boundary.

A rule scoped this way enters context only when Claude Code is actually working with a file matching that glob -- e.g., something under src/db/ ending in .sql. The rest of the codebase never pays the context cost of a rule that doesn't apply to it.

**Critically: a rules file with no paths frontmatter at all loads unconditionally, at session start, with the same standing as CLAUDE.md.** Omitting paths doesn't mean "loads nowhere" -- it means "loads everywhere, always," exactly like the project's CLAUDE.md. Subdirectory organization under .claude/rules/ is purely cosmetic bookkeeping for humans browsing the folder; it carries no scoping meaning to Claude Code itself.

Where Each Piece of Guidance Belongs

GuidanceWhere it belongsWhy
"Never modify the database schema"CLAUDE.mdApplies everywhere in the project
"All SQL in the database module needs an explicit transaction boundary".claude/rules/database.md with paths: ["src/db/**/*.sql"]Only relevant to one part of the tree -- would be noise everywhere else

Broad, universal constraints belong in CLAUDE.md. Narrow, path-specific guidance belongs in a rules file scoped with paths -- that's what keeps CLAUDE.md from growing into an undifferentiated pile that dilutes the instructions that actually matter on any given task.

Common exam traps

  • Assuming a rules file's location inside .claude/rules/ determines its scope. It doesn't -- only the paths frontmatter field does. A file sitting in a database/ subfolder with no paths key still loads unconditionally, for every task, everywhere.
  • Assuming a rules file with no paths field simply doesn't load. The opposite is true: without paths, it loads exactly like CLAUDE.md -- unconditionally, at session start.

Key Takeaways

  • Rules files live in .claude/rules/ and add a narrower, path-scoped layer on top of CLAUDE.md's always-on baseline
  • Scope is controlled exclusively by a paths glob in the rules file's YAML frontmatter, not by which subdirectory of .claude/rules/ the file lives in
  • Subdirectory placement inside .claude/rules/ is purely organizational -- it has no effect on when a rule loads
  • A rules file with no paths field loads unconditionally at session start, with the same standing as CLAUDE.md
  • Broad, universal constraints belong in CLAUDE.md; narrow, path-specific guidance belongs in a paths-scoped rules file

Glossary Terms

Related Concepts

PrepGenAICerts.com is an independent third-party exam-prep platform for the Claude Certified Architect (CCA-F) certification. We are not affiliated with, endorsed by, or acting on behalf of Anthropic PBC.

Note: New premium upgrades are temporarily paused while we resolve an issue with our payment provider. Existing premium members retain full access.