Path-Specific Rules
The mechanism
Put one-topic Markdown files in .claude/rules/ (discovered recursively, so subfolders like frontend/ work). A rule without a paths field loads unconditionally. A rule with paths is conditional:
1---2paths:3 - "src/api/**/*.ts"4---5# API Development Rules6- All API endpoints must include input validationIt loads when Claude uses Read, Write or Edit on a matching file (also when a Bash command counts as a read).
Glob patterns
| Pattern | Matches |
|---|---|
**/*.ts | All TypeScript files anywhere |
src/**/* | Everything under src/ |
*.md | Markdown files in the project root |
src/components/*.tsx | Components in one directory |
src/**/*.{ts,tsx} | Brace expansion for several extensions |
paths takes a YAML list or a comma-separated string. paths is the only frontmatter field Claude Code reads on a rule; others are ignored. Invalid YAML makes it load as if it had no paths (check with claude --debug).
Related locations
- User-level rules:
~/.claude/rules/apply to every project. - Shared rules: symlinks into
.claude/rules/are supported (approval is asked once per project).
When to use which mechanism (design guidance)
| Situation | Use |
|---|---|
| Applies to the whole repo | Root CLAUDE.md |
| Applies to one directory and its team | A CLAUDE.md in that directory (loads on demand) |
Applies to a file type scattered across directories (all tests, all *.tsx) | .claude/rules/ with paths globs |
| A multi-step procedure | A skill |
Path-scoped rules shine when conventions follow file type, not folder: a directory CLAUDE.md cannot express "all *.test.ts files wherever they live".
Exam traps
- A directory CLAUDE.md for conventions that span many directories.
- Expecting a path rule to load at launch. It loads when matching files are touched.
- Unquoted or malformed globs.
- Assuming extra frontmatter fields do something.
References
- How Claude remembers your project — checked Oct 16, 2026
Check your understanding
Test conventions for
**/*.test.tsacross the whole monorepo. Mechanism?Show answerHide answerAnswer
.claude/rules/testing.mdwithpaths: ["**/*.test.ts"].Does a path rule load at session start?Show answerHide answer
Answer
No, when Claude reads, writes or edits a matching file.Brace expansion for
.tsand.tsx?Show answerHide answerAnswer
src/**/*.{ts,tsx}.