All Days
Day 20

Founder OS — Path-Scoped Rules

Claude Code — Hidden Feature #005

Rules that load only when needed.

Most people dump everything into one CLAUDE.md. 3% know about .claude/rules/ — a folder where each file can have its own path filter. API rules only load when you touch API files.

.claude/rules/
the folder
paths:
frontmatter filter
zero waste
context only when relevant

The problem with one big CLAUDE.md

Why splitting rules into a folder beats a single file

the wrong way

One CLAUDE.md with 500 lines. API style guides, test conventions, DB rules, frontend patterns, security policies, all at once.

Problem: every rule loads on every file. Context bloat. Reduced adherence. Irrelevant instructions taking up tokens.

the right way

Split into .claude/rules/. Each file has a paths: filter. API rules only load when src/api/** is touched.

Result: Claude gets exactly the rules it needs. Nothing extra. Better adherence. Lower token cost.

Example structure

Click any file to see the rule content

.claude/
└── rules/
← always loads
← always loads
← src/api/**
← src/components/**
← prisma/** *.sql
← src/auth/**

← click a file to see the rule

How path scoping works

The frontmatter syntax

always loads (no frontmatter)
# code-style.md
# no frontmatter = loads for every file

Use 2-space indentation.
Always use TypeScript.
Prefer const over let.
path-scoped (only when matching)
---
paths:
  - "src/api/**/*.ts"
  - "src/routes/**/*.ts"
---

# api-design.md — loads ONLY for API files

All endpoints need input validation.
Return 422 for validation errors.
Never expose internal stack traces.

Real rule examples

Common patterns you can use today

Test files
---
paths: ["**/*.test.ts", "**/*.spec.ts"]
---
Use vitest, not jest.
No mocking the database.
Always test both success and error paths.
React components
---
paths: ["src/components/**"]
---
Use functional components only.
No prop drilling beyond 2 levels.
All components must have TypeScript props.
Database files
---
paths: ["prisma/**", "**/*.sql"]
---
Never modify existing migrations.
Always add indexes for foreign keys.
Soft-delete instead of hard-delete.
n8n workflows
---
paths: ["workflows/**/*.json"]
---
Always add error handling nodes.
Use Set node for data transformation.
Document every workflow with a sticky note.
don't miss what's next.

playbooks, templates, and tools that actually save you hours. straight to your inbox. no spam. unsubscribe anytime.

Day 20 of 30  ·  AY Automate · Claude Code Series