Claude Code reads a file called CLAUDE.md from your project root at the start of every session. Whatever you put in it, Claude treats as ground truth about your project — your stack, your conventions, what it should never touch, how you write tests.
Without a CLAUDE.md, Claude has no project context. It guesses at your patterns, picks libraries based on popularity rather than what you actually use, and makes decisions you'll disagree with. With a good one, those problems mostly disappear.
New: CLAUDE.md Playground → Interactive visualizer for the four scopes below. Paste your files, toggle scopes on and off, see the concatenated context Claude actually reads at session start. Resolves @-imports and walks the subdirectory lazy-loading tree. Runs entirely in your browser.
A CLAUDE.md file is plain Markdown. Claude reads it as context, not as instructions to execute. There's no required format — but effective ones typically cover six areas:
# CLAUDE.md
## Stack
What technologies are actually in use. Be specific — "React" is less useful than
"Next.js 15 with App Router, TypeScript strict mode, Tailwind CSS, Supabase."
## Code Style
Your conventions. Named vs default exports. Where tests live. How you name things.
Rules Claude should follow without being asked.
## Architecture
Where things go. /app vs /components vs /lib. Which files own what.
If Claude doesn't know this, it'll create files wherever it thinks is right.
## What NOT to Touch
Files or directories Claude should never modify without asking.
next.config.ts, database migrations, auth middleware — list them explicitly.
## Testing
Your test framework, where tests live, what you do and don't test.
"Test behavior the user sees, not implementation details" changes everything.
## Commit Style
Your convention. feat/fix/chore. One concern per commit. Whatever your standard is.
Here's a CLAUDE.md for a Next.js project. Copy and adapt it.
# CLAUDE.md
## Stack
- Next.js 15 (App Router), TypeScript strict, Tailwind CSS
- Supabase (auth + database), Prisma ORM
- Vitest + React Testing Library
## Code Style
- Functional components only, no class components
- Named exports for components, default for pages
- Co-locate tests: Component.test.tsx next to Component.tsx
- No inline styles — Tailwind utilities only
## Architecture
- /app — routes and layouts only, no business logic
- /components — shared UI, no data fetching
- /lib — utilities, shared logic
- /hooks — custom React hooks
- Server Components by default, "use client" only when needed
## Never Touch Without Asking
- next.config.ts
- /app/api/** (coordinate changes)
- supabase/migrations/
- Any file in /lib/auth/
## Testing
- Vitest + RTL for components and hooks
- Test user-visible behavior, not internals
- No snapshot tests
- Mock at network layer (MSW), not at import level
## Commits
- feat / fix / chore / test
- One concern per commit
This is the section most people skip, and it causes the most pain. Without it, Claude will make changes to configuration files, database migrations, and auth code that seem locally reasonable but break things globally.
Think about what in your project would cause an outage or data loss if changed incorrectly, and list it.
Tip: The more specific, the better. "Don't touch config files" is too vague. "Don't touch next.config.ts, .env.local, or supabase/config.toml" is actionable.
Without explicit testing instructions, Claude defaults to writing tests that test implementation details — checking that a specific function was called, asserting on internal state, using snapshot tests that break on every UI change.
Adding a single line like "Test behavior the user sees, not implementation details" changes the quality of generated tests dramatically.
The structure above works for any stack. Swap out the technology names, keep the six sections. A Go + Gin backend, a Flutter mobile app, a Rails monolith — the CLAUDE.md looks the same, just with different specifics.
The most important thing is that it's specific. Generic instructions get generic results.
Treat CLAUDE.md like documentation — update it when your stack or conventions change. An outdated CLAUDE.md is worse than none because Claude will confidently follow instructions that no longer apply.
A good time to review it: when onboarding a new tool, when changing your testing setup, or when you notice Claude repeatedly making the same wrong decision.
The pattern above covers the most common case: a project's CLAUDE.md at the repo root. Claude Code actually reads from three scopes in order of precedence:
./CLAUDE.md or ./.claude/CLAUDE.md at your repo root. Nested CLAUDE.md files in subdirectories load lazily when Claude reads files in that subdirectory.~/.claude/CLAUDE.md, read for every project on your machine. Good for personal preferences like "use short commit messages" or "run tests before claiming work complete" that you don't want to repeat in every repo.There's also CLAUDE.local.md for project-specific preferences you want gitignored (sandbox URLs, local test data). And Claude Code's /init command auto-generates a starter CLAUDE.md by analyzing your repo.
CLAUDE.md is a plain Markdown file Claude Code reads from your project root at the start of every session. It gives Claude ground-truth context about your stack, conventions, architecture, and what not to touch.
No, Claude Code runs without one. But without CLAUDE.md it guesses at your patterns, picks libraries by popularity rather than what you use, and makes decisions you'll disagree with.
Six sections work for most projects: Stack, Code Style, Architecture, What NOT to Touch, Testing, and Commit Style. Be specific — generic instructions get generic results.
Project CLAUDE.md lives at the repo root (alongside package.json or pyproject.toml) and auto-loads at session start. Add per-subdirectory CLAUDE.md files for scoped context — they load lazily when Claude reads files in that subdirectory. For personal preferences that apply across all your projects, create ~/.claude/CLAUDE.md (user scope). Enterprise-managed policy files exist at a third, higher-precedence scope.
Treat it like documentation — update when your stack or conventions change. An outdated CLAUDE.md is worse than none because Claude will confidently follow rules that no longer apply.
Once you have a solid CLAUDE.md, the next multipliers are custom slash commands, workflow hooks, MCP servers for external data sources, and your settings.json for permission profiles, hook wiring, and model defaults.
Using GitHub Copilot too? Copilot's equivalent workspace file is .github/copilot-instructions.md — see the Copilot Customization Starter Kit for drop-in templates plus per-path .instructions.md rules and reusable .prompt.md files.
The Claude Code Starter Kit includes 5 ready-to-use CLAUDE.md templates (Next.js, FastAPI, Express, React Native, Data Science) plus 10 slash commands, a hooks cookbook, and 20 power prompts — free download.
Download free →Saved you time? Tip the maker in BTC — no account, no signup, just paste.
bc1qs04leape97ner4wqa98n94l9n0gv9aa84eg4ux