Create Rule
Rules vs CLAUDE.md vs Skills
Choose the right mechanism before writing anything:
| Mechanism |
When to use |
Loads |
| Rule |
Behavioral instructions scoped to a topic or file type |
Every session (or on path match) |
| CLAUDE.md |
Broad project context: build commands, architecture, workflows |
Every session |
| Skill |
Repeatable on-demand workflows |
Only when invoked |
If the instruction only makes sense for certain file types (e.g. Go, test files), use a path-scoped rule. If it's a repeatable task workflow, use a skill instead.
Storage Locations
| Scope |
Path |
| Personal, all projects on this machine |
~/.claude/rules/<topic>.md |
| Project, shared with team via git |
.claude/rules/<topic>.md |
Rules in subdirectories are discovered recursively (e.g. .claude/rules/frontend/react.md works).
Rule File Format
---
paths: # optional; omit for always-load
- "**/*.go"
- "**/*_test.go"
---
# rule-name
Instructions...
No paths frontmatter → rule loads every session.
paths present → rule loads only when Claude opens a matching file.
Path Scoping Decision
Use always-load (no frontmatter) for:
- Universal behaviors: commit style, escalation policy, output verbosity
- Toolchain choices: task runner, package manager, CI tooling
Use path-scoped for:
- Language conventions:
**/*.go, **/*.ts, **/*.py
- Test files:
**/*_test.go, **/*.test.ts, **/*.spec.ts
- Domain directories:
src/api/**/*, e2e/**/*.go, migrations/**/*.sql
See references/rule-patterns.md for glob pattern examples.
Writing Effective Rules
- Specific and verifiable: "Use 2-space indentation" not "format code nicely"
- One topic per file with a descriptive filename (
testing.md, api-design.md)
- Under 200 lines. Longer files reduce adherence; split if growing large
- Markdown structure: use headers and bullets, not dense paragraphs
- No contradictions across rule files; audit when adding new ones
- Use RFC 2119 key words for requirement levels (
MUST / SHOULD / MAY), sparingly and only for genuine requirements. See the normative-language rule. For a requirement that is also frequently violated, add a short "Frequently missed:" lead-in.
Workflow
- New or update? Check existing rules in the target directory for overlap
- Scope: personal (
~/.claude/rules/) or project (.claude/rules/)?
- Path scope: universal (no frontmatter) or file-type specific?
- Check for conflicts: scan existing rules for contradictions or duplication
- Write the file: concrete, verifiable instructions; one topic
- Verify: confirm file is under 200 lines and uses specific language
Authoring Checklist
Anti-Patterns
- Vague rules: "write clean code", "be consistent". Not actionable
- Duplicating defaults: don't document what Claude already does correctly
- Over-specifying: bloated rule files cause Claude to ignore them
- Wrong scope: file-type-specific rules (Go, SQL) in always-load waste context
- Contradictions: two rules giving conflicting guidance on the same behavior
- Workflow steps in rules: if it's a multi-step process, use a skill instead
Additional Resources
1---2name: create-rule3description: Use when creating, writing, or updating a Claude Code rule file (.claude/rules/*.md or ~/.claude/rules/*.md), or when asking about rule format, path scoping, or rule best practices.4---56# Create Rule78## Rules vs CLAUDE.md vs Skills910Choose the right mechanism before writing anything:1112| Mechanism | When to use | Loads |13|---|---|---|14| **Rule** | Behavioral instructions scoped to a topic or file type | Every session (or on path match) |15| **CLAUDE.md** | Broad project context: build commands, architecture, workflows | Every session |16| **Skill** | Repeatable on-demand workflows | Only when invoked |1718If the instruction only makes sense for certain file types (e.g. Go, test files), use a path-scoped rule. If it's a repeatable task workflow, use a skill instead.1920## Storage Locations2122| Scope | Path |23|---|---|24| Personal, all projects on this machine | `~/.claude/rules/<topic>.md` |25| Project, shared with team via git | `.claude/rules/<topic>.md` |2627Rules in subdirectories are discovered recursively (e.g. `.claude/rules/frontend/react.md` works).2829## Rule File Format3031```markdown32---33paths: # optional; omit for always-load34 - "**/*.go"35 - "**/*_test.go"36---3738# rule-name3940Instructions...41```4243No `paths` frontmatter → rule loads every session.44`paths` present → rule loads only when Claude opens a matching file.4546## Path Scoping Decision4748Use **always-load** (no frontmatter) for:49- Universal behaviors: commit style, escalation policy, output verbosity50- Toolchain choices: task runner, package manager, CI tooling5152Use **path-scoped** for:53- Language conventions: `**/*.go`, `**/*.ts`, `**/*.py`54- Test files: `**/*_test.go`, `**/*.test.ts`, `**/*.spec.ts`55- Domain directories: `src/api/**/*`, `e2e/**/*.go`, `migrations/**/*.sql`5657See [references/rule-patterns.md](references/rule-patterns.md) for glob pattern examples.5859## Writing Effective Rules6061- **Specific and verifiable**: "Use 2-space indentation" not "format code nicely"62- **One topic per file** with a descriptive filename (`testing.md`, `api-design.md`)63- **Under 200 lines**. Longer files reduce adherence; split if growing large64- **Markdown structure**: use headers and bullets, not dense paragraphs65- **No contradictions** across rule files; audit when adding new ones66- Use RFC 2119 key words for requirement levels (`MUST` / `SHOULD` / `MAY`), sparingly and only for genuine requirements. See the `normative-language` rule. For a requirement that is also frequently violated, add a short "Frequently missed:" lead-in.6768## Workflow69701. **New or update?** Check existing rules in the target directory for overlap712. **Scope**: personal (`~/.claude/rules/`) or project (`.claude/rules/`)?723. **Path scope**: universal (no frontmatter) or file-type specific?734. **Check for conflicts**: scan existing rules for contradictions or duplication745. **Write the file**: concrete, verifiable instructions; one topic756. **Verify**: confirm file is under 200 lines and uses specific language7677## Authoring Checklist7879- [ ] Description starts with "Use when..." if this is actually a skill (wrong tool if so)80- [ ] Topic is focused: one concern per file81- [ ] Path scope matches actual applicability (don't always-load a Go-only rule)82- [ ] Instructions are concrete and verifiable, not vague83- [ ] No contradictions with existing rules in the same directory84- [ ] File is under 200 lines8586## Anti-Patterns8788- **Vague rules**: "write clean code", "be consistent". Not actionable89- **Duplicating defaults**: don't document what Claude already does correctly90- **Over-specifying**: bloated rule files cause Claude to ignore them91- **Wrong scope**: file-type-specific rules (Go, SQL) in always-load waste context92- **Contradictions**: two rules giving conflicting guidance on the same behavior93- **Workflow steps in rules**: if it's a multi-step process, use a skill instead9495## Additional Resources9697- Full glob pattern examples and good/bad rule samples: [references/rule-patterns.md](references/rule-patterns.md)98- Official docs: https://code.claude.com/docs/en/memory#organize-rules-with-clauderules