.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.