What Are .claude/rules/ Files?
The .claude/rules/ directory is a subdirectory inside your project’s .claude/ folder. Any .md file you place there is automatically loaded by Claude Code and included in the system prompt alongside your main CLAUDE.md.
Think of it as modular configuration. Instead of one long project instruction file, you split Claude’s behavioral rules into separate, focused files by topic — each with its own name, scope, and ownership.
Every .md file in .claude/rules/ gets read on session start. Claude treats their contents as additional standing instructions — exactly as authoritative as what’s in CLAUDE.md, just organized into separate files.
Rules files don’t require any special format. A plain markdown file with bullet points, headers, or prose all work. Claude reads them as instructions, not as documentation.
This feature is part of Claude Code’s broader context engineering system, which gives teams fine-grained control over what Claude knows and follows without polluting the context window with a wall of text.
CLAUDE.md vs .claude/rules/ — When to Use Each
The distinction matters once your project has more than one person, more than one workflow, or more than one domain of concern. They serve different jobs.
| Dimension | CLAUDE.md | .claude/rules/*.md |
|---|---|---|
| Purpose | Project-wide context: what this codebase is, how it’s structured, key commands | Behavioral rules by domain: how Claude should act in specific scenarios |
| Granularity | One file covering the whole project | Many files, each covering one concern (testing, deploy, style, API, etc.) |
| Ownership | Usually owned by project lead / tech lead | Each file can be owned by a different team member or squad |
| Typical contents | Tech stack, repo structure, common commands, architecture decisions, critical laws | Testing requirements, deploy gates, naming conventions, API usage rules, PR workflow |
| Update frequency | Changes when architecture or project fundamentals change | Changes when specific workflows evolve; can be updated independently |
| Checkin | Always committed to git | Usually committed; can create local-only rules files too (add to .gitignore) |
| Conflict behavior | Both are loaded — Claude sees all instructions. More specific rules files generally take precedence where there’s overlap. | Same — Claude sees all. Write rules to be complementary, not contradictory. |
The mental model: CLAUDE.md answers “what is this project?” Rules files answer “how should you behave in specific situations?”
Developers dump everything into CLAUDE.md — project context, coding standards, testing rules, deploy process, PR workflow, API conventions — until it’s 800+ lines and Claude starts ignoring the bottom half. Rules files solve this by keeping each domain tight and readable.
For a full breakdown of all memory layers in Claude Code, see the Claude Code Memory Guide.
How Claude Code Loads Rules Files
Understanding the loading mechanism helps you write better rules and debug unexpected behavior.
-
1
Session start scan
When you start a Claude Code session in a project directory, Claude scans for
CLAUDE.mdin the current directory and parent directories, then reads all.mdfiles found in.claude/rules/. -
2
All files injected into system prompt
The contents of every rules file are concatenated and injected into Claude’s system prompt. Claude sees them as one continuous block of instructions alongside your
CLAUDE.md. There’s no lazy loading — everything in.claude/rules/is always active. -
3
File order
Files are loaded in filesystem order (typically alphabetical). If you need a specific rule to appear first, prefix filenames:
00-core-rules.md,01-testing-rules.md,02-deploy-rules.md. -
4
Rules stay active for the full session
Unlike conversation context that can be compacted away, rules files are re-read at session start and stay active. They don’t degrade as the session gets long.
-
5
Token budget consideration
Every rule file consumes context window tokens. Total context from
CLAUDE.md+ all rules files is typically in the 500–3,000 token range for well-structured projects. Avoid making rules files into documentation repositories — keep rules actionable and concise.
Load order: global ~/.claude/CLAUDE.md → project CLAUDE.md → .claude/rules/*.md → .claude/settings.json permissions → conversation context. Each layer adds to the previous; nothing is overwritten until conversation context where specifics win.
Why Modular Rules Files Beat a Monolith CLAUDE.md
Once you’ve used modular rules files on a real project, going back to a single CLAUDE.md feels like writing your entire codebase in one file. The benefits compound with team size and project complexity.
Each file does one job
Testing rules stay in testing-rules.md. Deploy rules stay in deploy-rules.md. Updates to one don’t risk clobbering the other. Grep is trivial.
Distributed authorship
Your backend engineer owns api-rules.md. Your DevOps engineer owns deploy-rules.md. Your QA lead owns testing-rules.md. No merge conflicts on the same file.
Clean diffs
When deploy-rules.md changes, the PR diff is focused on deploy rules only. Reviewers can evaluate the change without reading unrelated rules.
Enable or disable by file
Need to temporarily disable database migration rules? Rename the file or move it. No surgical editing of a monolith. Add a .disabled extension and rules files won’t be picked up.
There’s also a cognitive benefit for Claude. A well-named file like testing-rules.md signals to Claude that the following instructions are specifically about testing. That context — file name included — appears in the system prompt and helps Claude apply the right rules to the right actions.
5 Rules Files With Full Contents
These are production-quality examples you can adapt directly. Each file follows the same structure: clear heading, actionable bullet rules, no filler text. Claude responds best to direct imperatives, not explanations of why a rule exists.
1. testing-rules.md
2. deploy-rules.md
3. coding-standards.md
4. api-rules.md
5. workflow-rules.md
Best Practices for Structuring Rules Files
After working with rules files across different project types, these patterns consistently produce better Claude behavior and easier maintenance.
Keep files focused and short
A rules file covering exactly one domain should be 50–150 lines. Beyond that, you’re probably mixing concerns. If coding-standards.md starts covering deploy process, split it. Each file should pass the test: “Can I describe what this file covers in five words or less?”
Write imperatives, not explanations
Claude responds to direct instructions. Write rules as imperatives (“Always do X”, “Never do Y”, “Use Z when…”), not as rationale (“The reason we use X is because of historical context involving…”). Save rationale for comments in the codebase itself.
Use numbered prefixes for ordering
When rule precedence matters, control the load order with filename prefixes:
Separate hard rules from guidelines
Within each file, use clear visual hierarchy to distinguish non-negotiable rules from preferences. Claude reads and respects this hierarchy:
Reference, don’t duplicate
If something is already in CLAUDE.md, don’t repeat it in a rules file. Reference it: “See CLAUDE.md for the full architecture overview.” Duplication creates maintenance burden and creates confusion when the two copies drift.
Review and prune quarterly
Rules files accrete over time. A rule added for a specific incident six months ago may no longer apply. Schedule a quarterly pass: does each rule still reflect actual practice? Is it enforced by tooling now (linter, CI) and no longer needs to be in a rules file? Delete stale rules. Claude performing worse on a rule is sometimes a sign the rule is wrong, not Claude.
It’s valid to write a rule about the rules system itself. Example: "Before adding a new rule, check if it’s already covered by an existing rule file. Duplicate rules are worse than no rule." This keeps the system from bloating.
Team Workflows and Version Control
Rules files become significantly more valuable on teams than they are for solo developers. Here’s how to structure them for collaborative use.
Commit rules files to git
All rules files in .claude/rules/ should be committed. They’re part of the project’s definition of how work gets done — as important as .eslintrc or jest.config.js. New team members cloning the repo automatically get the full Claude configuration.
Local-only rules files
For personal Claude preferences that don’t belong in the shared project config, create a .claude/rules/local/ subdirectory and add it to .gitignore. Use this for personal debugging shortcuts, experimental rules you’re testing, or role-specific preferences that don’t apply to the whole team.
Rules file PR reviews
Changes to .claude/rules/ should go through code review like any other file. A rule change affects how Claude behaves for everyone on the team. Treat it with the same rigor as changing a linting rule — it has broad behavioral impact.
A useful PR description template for rules changes:
Layering with global Claude settings
Your team’s project-level .claude/rules/ files layer on top of each developer’s personal ~/.claude/CLAUDE.md. This means individual developers can have personal preferences (response format, verbosity level, preferred tools) without those preferences touching the shared project rules. Team rules win on any overlap. For more on this layering, see the memory hierarchy guide.
Bootstrapping a new project
When starting a new project, a minimal rules setup is better than a comprehensive one. Start with:
- coding-standards.md — language version, naming conventions, critical style rules
- workflow-rules.md — commit message format, branch strategy, PR requirements
Add more files as specific pain points emerge. Rules files added reactively tend to be more accurate and more followed than rules files written speculatively. The same principle applies to CLAUDE.md templates — start lean and evolve.
At the end of a project sprint, ask: did Claude do anything repeatedly wrong that isn’t covered by a rules file? If yes, that’s your next rules file entry. If Claude violated an existing rule, the rule probably needs to be rewritten to be more explicit. Rules files get better through iteration, not upfront perfection.
Get Pre-Built Rules Files for Your Role
Skip the rules file engineering. Brainfile packages include production-ready .claude/rules/ files for 18 professional roles — tested with real Claude Code workflows.