← Claude Code Hub
Jun 14, 2026 · 3 min read ✦ Tip #102

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

  • It's the surgical version of your project CLAUDE.md: instead of one file that keeps growing, rules scoped by area.
  • Sharing the repo with Cursor or Codex? With no CLAUDE.md, Claude Code now reads the shared AGENTS.md, and your .claude/rules/ keep loading alongside it. If you have both, one @AGENTS.md joins them: AGENTS.md in Claude Code.
  • Same "load only what's needed" idea as Tool Search for MCP: the expensive part is deferred.
  • How much each thing weighs in your window: when each feature loads.
  • There's another conditional thing in Claude Code that isn't this one, and the two are easy to mix up: the if field on hooks decides whether a process spawns, not what enters your context. That one is conditional hooks.

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

FREE GUIDE

You don't need Opus every time.

Model and effort are two settings, not one. 8 pages with the settings that actually move your bill, a three-question diagnostic for when something fails, and the price ladder.

  • 1. What "better" means capability, time and money
  • 2. Model who you send
  • 3. Effort how much rope you give
  • 4. Diagnostic three questions when something fails
  • 5. The bill where it comes from
Are you a professional Web developer?

It arrives by email · You join the Gravitas newsletter · Unsubscribe anytime

Stop overpaying in Claude Code
FREE GUIDE

You don't need Opus every time.

Are you a professional Web developer? · Unsubscribe anytime
Workshop for teams

Multiply your team's output without sacrificing quality: a 6 to 8 hour AI First workshop, online, on the Claude platform.

See the workshop

Using Opus for everything? See when you don't need it.