← Claude Code Hub
✦ Tip #102 Jun 14, 2026

Conditional rules in Claude Code: stop loading your whole CLAUDE.md every session

Your CLAUDE.md grows and loads whole every session, no matter how much of each part you use. There's a folder that makes each rule show up only when it matters.

A monolithic CLAUDE.md that loads whole every session versus .claude/rules/ with per-scope files and paths: frontmatter where editing src/api lights up the api-endpoints rule while the vue and tests rules stay dimmed; the general rule always loads

TL;DR Split your CLAUDE.md into files inside .claude/rules/ and give them a paths: frontmatter with globs. Each rule only enters context when Claude touches files matching its pattern. Your API rules don't take up space when you're editing Vue components, and vice versa. Rules without paths always load. It's the same principle as skills: the expensive part only when it's needed.

Your CLAUDE.md grows, and all of it loads every session, no matter how much of each part you actually use. Your endpoint rules ride along in context even when you spend the afternoon in the frontend. There's a way to make each rule show up only when it matters, and it lives in a folder a lot of people don't know exists.

Result:

.claude/rules/
├── api-endpoints.md      # only loads for src/api/**/*.ts
├── vue-components.md     # only loads for src/components/**/*.vue
├── testing.md            # only loads for tests/**/*.test.ts
└── general.md            # always loads (no paths frontmatter)

How it works

Claude Code discovers every .md inside .claude/rules/ (recursively, so you can nest them in subfolders) and loads them as project memory, with the same priority as .claude/CLAUDE.md. The frontmatter is what makes the difference:

  • With paths: (a list of globs): the rule is conditional. It only applies when Claude works with files matching the pattern. It doesn't load every turn, but when Claude reads a matching file.
  • Without paths:: it always loads, like another chunk of your CLAUDE.md.

Setup

1. Create a conditional rule

.claude/rules/api-endpoints.md:

---
paths:
  - "src/api/**/*.ts"
---

# API rules

- Every endpoint validates input before processing.
- Use the error format from src/api/errors.ts.
- Correct HTTP status codes (201 on create, 204 on delete).

2. Another for a different scope

.claude/rules/vue-components.md:

---
paths:
  - "src/components/**/*.vue"
  - "src/pages/**/*.vue"
---

# Vue component rules

- Composition API with <script setup lang="ts">.
- Props typed with defineProps<T>().
- Keep templates under 80 lines; extract children.

3. An unconditional one, for everything

.claude/rules/general.md (no frontmatter): 2-space indentation, no console.log in production, JSDoc on public functions.

Glob patterns you can use

Pattern Matches
**/*.ts Every .ts in any folder
src/**/* Everything under src/
src/components/*.tsx Components in one specific folder
**/*.{ts,tsx} .ts and .tsx (brace expansion)

You can list several patterns under paths: to widen the scope.

Details that help

  • Symlinks supported. Keep a shared rule set and link it into multiple projects: ln -s ~/shared-rules .claude/rules/shared.
  • User-level rules. ~/.claude/rules/*.md apply to all your projects; project rules take higher priority.
  • Rule or skill? If the instruction is for a specific task you don't need in context all the time, prefer a skill: it loads only when you invoke it. Conditional rules load when you touch matching files.

Where it fits

Official docs: Manage Claude's memory — Organize rules with .claude/rules/

Free guide

51 tips to master Claude Code.

One page per tip. Five chapters. What I actually use daily in production — no theory, no fluff.

  • I. Getting started 10 tips
  • II. Awareness 3 tips
  • III. Mastery 22 tips
  • IV. Autonomy 10 tips
  • V. Comparison 6 tips
Are you a professional Web developer?

You'll receive the guide by email · You join the Gravitas newsletter · Unsubscribe anytime

of 51
#

Wmedia · 51 Tips
Free guide · 51 tips · 5 chapters

51 tips to master Claude Code.

Are you a professional Web developer? · Unsubscribe anytime