# Claude Code Rules

> Small rule files. Some load only for some files.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** .claude/rules, Path-scoped rules, Rules folder

## Think of it like

It is like a binder with a tab for each topic.

## Definition

Rules are small files of instructions in a project's .claude/rules/ folder. Each file covers one topic, such as tests or the API. They load beside CLAUDE.md. A rule can also list file paths at its top. Then it only loads when Claude reads or edits a file that matches. Rules in the ~/.claude/rules/ folder at home apply to every project.

## Example

Jack's API rules only matter in one folder. He moves them into a rule with a paths line, and his main CLAUDE.md gets shorter.

## Example code

```markdown
---
paths: ["src/api/**"]
---
Every API route checks the user first.
```

This rule loads only for files in src/api.

## Why it matters

It keeps the context small, because a rule only costs space when it is needed.

## Common mistake

Putting every rule in CLAUDE.md. A rule for just some files is better with a paths line.

## Three principles

- **One topic a file.** In .claude/rules/.
- **Path rules.** Load when needed.
- **Personal rules.** In ~/.claude/rules/.

## Related terms

- [CLAUDE.md](https://learn.benibix.com/term/ai/claude-md)
- [CLAUDE.local.md](https://learn.benibix.com/term/ai/claude-local-md)
- [Context Window](https://learn.benibix.com/term/ai/context-window)
- [YAML Ain't Markup Language (YAML)](https://learn.benibix.com/term/development/yaml)

## Taught in

- [CLAUDE.md and Auto Memory](https://learn.benibix.com/learn/ai-claude-code/claude-md-and-auto-memory): Claude Code, 7/16

![A rule with paths loads only when Claude touches a matching file. A rule without paths loads every time.](https://learn.benibix.com/diagrams/cc-claude-code-rules.svg)

---

Source: https://learn.benibix.com/term/ai/claude-code-rules
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
