Certopolis

Claude Certified Architect – Foundations

.claude/rules paths: glob-scoped rules in Claude Code

A markdown file in .claude/rules/ with no frontmatter loads at launch like .claude/CLAUDE.md. Add a paths list of glob patterns to its YAML frontmatter and it loads only when Claude reads, writes or edits a matching file.

Unconditional and path-scoped rules

Put one topic per file in .claude/rules/, for example testing.md or api-design.md. Files are discovered recursively, so subfolders like frontend/ work. A rule without paths loads every session with the same priority as .claude/CLAUDE.md.

A rule with paths is conditional. With paths: ["src/api/**/*.ts"] in the frontmatter, the rule loads when Claude uses the Read, Write or Edit tool on a matching file, or views one with a Bash command that counts as a read, such as cat. paths is the only frontmatter field Claude Code reads from a rule; other fields are ignored.

Personal rules go in ~/.claude/rules/ and apply to every project on your machine. They load before project rules, but neither set overrides the other.

Glob patterns

**/*.ts matches TypeScript files in any directory. src/**/* matches all files under src/. *.md matches markdown files in the project root only. To match markdown at any depth under docs/, write docs/**/*.md.

Brace expansion matches several extensions in one pattern: src/**/*.{ts,tsx} expands to two patterns. A rule's whole paths list shares a budget of 1,000 expanded patterns and 4 MiB. A pattern that would exceed it is used unexpanded, and its literal braces match no files.

A [ starts a bracket expression. To match a literal [ in a folder name, escape it as \[. If the frontmatter YAML does not parse, Claude Code ignores it and loads the rule as if it had no paths; claude --debug shows the parse error.

When to use a rule instead of something else

Use a path-scoped rule for guidance that matters only for part of the codebase, such as Terraform naming under infra/. It stays out of context in sessions that never touch those files. For a multi-step procedure you run on request, use a skill instead. After /compact, path-scoped rules return once Claude next touches a matching file.

Where the exam catches people

  • *.md does not match markdown in subdirectories; it matches files in the project root only.
  • A rule with no paths field is not skipped; it loads in every session at launch.
  • A brace pattern over the expansion budget fails silently and matches nothing, so split it into plain patterns.
  • Writing "applies only to infra/" in a CLAUDE.md heading does not scope anything; only paths frontmatter makes loading conditional.

Written from Anthropic's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. Your monorepo keeps Terraform under infra/ and a React app under web/. You want Claude to follow a long Terraform naming convention whenever it opens a file under infra/, and you want none of that text loaded in sessions that only touch web/. Everyone who clones the repository should get the same behaviour. Which approach should you take?

    Right. In the game that’s Renown for your Claude Code Configuration and Workflows building.

    Not that one: A is right. In the game your Claude Code Configuration and Workflows building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    That satisfies both constraints at once: the convention is guaranteed present whenever infra/ files are in play, and absent from sessions that never touch them. Because the file is committed, every clone behaves the same way.

    Written from code.claude.com/docs/en/memory.md

  2. Your team keeps its runbooks as markdown under docs/, several levels deep in places, and you have written a rule that tells Claude the house format for a runbook. You want the rule to load whenever Claude opens any runbook, and to stay out of context otherwise. You are filling in its paths frontmatter. Which approach should you take?

    Right. In the game that’s Renown for your Claude Code Configuration and Workflows building.

    Not that one: D is right. In the game your Claude Code Configuration and Workflows building would lose a little Renown, and this question would come back later.

  3. Your .claude/rules/assets.md lists three paths patterns. Files under raw [2026]/ never bring the rule into context, and neither do the files matched by a pattern whose brace groups expand into many thousands of combinations. The third pattern works. Nothing in the session reports an error. What change would most effectively make the rule apply to all three sets of files?

    Right. In the game that’s Renown for your Claude Code Configuration and Workflows building.

    Not that one: D is right. In the game your Claude Code Configuration and Workflows building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    On braces: "Claude Code uses any pattern that would exceed the budget unexpanded, and its literal braces match no files." Escaping the bracket and removing the braces addresses both.

    Written from code.claude.com/docs/en/memory.md