Instead of stuffing everything into one CLAUDE.md, use .claude/rules/ to load instructions conditionally based on which files Claude is working with.
Setup
.claude/rules/
typescript.md # Loaded when editing *.ts, *.tsx
python.md # Loaded when editing *.py
testing.md # Loaded when editing *test*, *spec*
security.md # Loaded when editing auth/*, crypto/*
Each rule file uses YAML frontmatter with a glob pattern:
---
globs: ["*.ts", "*.tsx"]
---
- Use `type` instead of `interface` for object types
- Prefer `z.infer<typeof schema>` over manual type definitions
- All API responses must use the `ApiResponse<T>` wrapper
Benefits
- Lean context: Only relevant rules load, saving tokens
- No conflicts: Python rules don’t pollute TypeScript sessions
- Easy maintenance: Each concern lives in its own file
- Team-friendly: Different team members can own different rule files
vs. Subdirectory CLAUDE.md
| Feature | .claude/rules/ | Subdirectory CLAUDE.md |
|---|---|---|
| Matches by | File glob pattern | Working directory |
| Best for | Language/file type rules | Module-specific context |
| Granularity | Fine (per file type) | Coarse (per directory) |
Tip
Keep each rule file focused and short. The same 200-line attention limit applies. Splitting into many small files is better than a few large ones.