Path-Specific Rules (.claude/rules/)
CoreApply path-specific rules for conditional convention loading · Difficulty 2/5
The .claude/rules/ directory allows organizing project instructions into focused, topic-specific files that can be conditionally loaded based on file paths.
Structure
.claude/rules/
testing.md # Testing conventions
api-conventions.md # API patterns
react-style.md # React component patternsConditional Loading with Globs
Add YAML frontmatter to conditionally apply rules:
---
paths: ["**/*.test.tsx", "**/*.spec.ts"]
---
All tests should follow the AAA pattern (Arrange, Act, Assert)...Rules load only when editing files that match the glob patterns, reducing irrelevant context and token usage.
Glob Patterns vs Directory-Level CLAUDE.md
Directory-level CLAUDE.md files apply to everything in that directory. But conventions like "test file standards" apply to test files spread across the entire codebase, not confined to one directory.
Glob-pattern rules solve this by matching file type regardless of directory location:
**/*.test.tsx -- all test files anywhereterraform/**/* -- all Terraform filessrc/api/**/*.ts -- API source filesWhen to Use Each
| Configuration | Best For |
|---|
|---|---|
| Directory CLAUDE.md | Conventions specific to one directory subtree |
|---|---|
| Path-specific rules | Conventions for file types spread across the codebase |
| Root CLAUDE.md | Universal conventions that always apply |
Key Takeaways
- ✓Use .claude/rules/ with glob patterns for file-type-specific conventions
- ✓Rules load only when editing matching files, reducing token usage
- ✓Glob patterns beat directory CLAUDE.md when conventions span multiple directories
- ✓Use paths frontmatter field for conditional rule activation
Related Concepts
Test Yourself1 of 2
Your team's CLAUDE.md file has grown to over 500 lines, mixing various conventions and procedures. Developers find it difficult to locate and update relevant sections. What approach does Claude Code support for organizing instructions?