CLAUDE.md: Your Project's Brain
After this lesson, you will be able to:
- Write a CLAUDE.md that captures your project's tech stack, conventions, and 'house rules', so every Claude Code session starts already knowing the rules
- Use nested CLAUDE.md files in monorepos so each subproject loads its own context without bloating the top-level file
- Distinguish CLAUDE.md (always loaded) from .claude/rules/ (path-scoped) from settings.json (config), and pick the right place for each rule
- Avoid the three CLAUDE.md anti-patterns that bloat context, encourage hallucination, or get ignored entirely
Before you start
#What CLAUDE.md Is
A markdown file at your project root (or any directory). When Claude Code starts a session, it loads CLAUDE.md into the conversation context. Result: every conversation starts knowing the rules of YOUR project. It is guidance Claude reads, not a setting the program enforces, so a rule you must never break belongs in a hook or a permission rule as well.
my-project/
├── CLAUDE.md ← always loaded
├── .claude/
│ ├── settings.json
│ └── rules/ ← path-scoped rules
│ ├── frontend.md
│ └── api.md
├── src/
└── package.json
#What to Put in CLAUDE.md
Your CLAUDE.md says 'Use Tailwind v4.' Two weeks later you upgrade to v5 but forget to update CLAUDE.md. What goes wrong on the next session?
A high-quality CLAUDE.md typically has 5 sections:
#1. Tech Stack & Conventions
## Tech Stack
- **Frontend**: React 19 + TypeScript + Tailwind v4 (CSS-based @theme)
- **Backend**: FastAPI + Pydantic + Postgres
- **Testing**: Vitest + Playwright + pytest
## Code Conventions
- TypeScript: strict mode, no `any`, named exports
- Python: type hints on all public functions
- File names: kebab-case (.tsx, .ts, .py)
- Commits: conventional (feat:, fix:, docs:, refactor:)
#2. Always-Do / Never-Do Rules
## Always
- Run `npm run lint` before committing
- Add tests for any new business logic
- Use Pydantic for API request/response validation
## Never
- Commit .env files or secrets
- Use `any` in TypeScript
- Skip the eval pipeline before deploying ML models
#3. Project Structure
## Project Layout
- `src/components/` — React components, kebab-case files
- `src/lib/stores/` — Zustand stores
- `src/content/lessons/` — MDX lesson content
- `api/` — FastAPI endpoints
#4. Workflow Patterns
## Adding a New Feature
1. Create vertical slice: backend + frontend + tests
2. Run `npm run build` and `pytest` to verify
3. Open PR with conventional commit message
#5. Things You Always Forget
## Gotchas
- The Postgres connection requires SSL on staging — set DATABASE_URL accordingly
- Stripe webhooks need raw body parsing (don't use bodyParser middleware)
#Nested CLAUDE.md (Monorepos)
For monorepos, put a CLAUDE.md in each major subdirectory. Claude Code auto-loads them all when working in that subdirectory:
my-monorepo/
├── CLAUDE.md ← root: tooling, repo structure, shared conventions
├── apps/
│ ├── web/
│ │ ├── CLAUDE.md ← frontend-specific: React 19, Zustand, Tailwind
│ │ └── ...
│ └── api/
│ ├── CLAUDE.md ← backend-specific: FastAPI, Postgres, auth
│ └── ...
└── packages/
└── shared/
└── CLAUDE.md ← shared lib: types, utilities, version policy
apps/web/ the root file and apps/web/CLAUDE.md both apply, and when editing a packages/shared file the root file and packages/shared/CLAUDE.md apply.#CLAUDE.md vs .claude/rules/ vs settings.json
| File | Loaded When | Use For |
|---|---|---|
| CLAUDE.md | Every session in/below this dir | Conventions, tech stack, project rules |
| .claude/rules/*.md | Conditional via path matchers | Path-scoped rules ("only for src/api/**") |
| .claude/settings.json | Always | Permissions, hooks, tool config (MCP servers live in .mcp.json) |
| .claude/settings.local.json | Always (local only, gitignored) | Personal overrides: your own hooks and permission grants |
Rule of thumb:
- Tech stack + code conventions → CLAUDE.md
- Path-specific rules ("API endpoints must use Pydantic") → .claude/rules/api.md
- Permission allowlists, hooks → settings.json; MCP servers → .mcp.json
#Three Anti-Patterns to Avoid
#Hands-On
Tests: Run it, fix the listed problems, and run it again until it prints that CLAUDE.md passes every check. Then save the text as CLAUDE.md in a real project and ask Claude a project-specific question to confirm it is loaded.
#Key Takeaways
- CLAUDE.md = your project's house rules. Auto-loaded every session, eliminates repetitive context-setting
- Five sections: tech stack, always/never rules, project structure, workflow patterns, gotchas
- Nested CLAUDE.md for monorepos. Each subproject's CLAUDE.md loads when working in that subtree
- CLAUDE.md vs .claude/rules/ vs settings.json. Rules vs path-scoped rules vs config
- Anti-patterns: kitchen sink, aspirational lies, empty file, all defeat the purpose
#Quick Check
Your team's CLAUDE.md is 1500 lines and covers every detail of your codebase. Symptoms: Claude is slower to respond and frequently misses small rules. What's the fix?
You have a monorepo with a Next.js frontend and a FastAPI backend. The frontend uses Tailwind kebab-case files; the backend uses snake_case Python files. Where should each convention live?