Skip to main content

Anatomy of CLAUDE.md

Team memory, conventions, patterns, and living architecture.

CLAUDE.md

The project memory and "contract" that tells Claude how your project really works.


TL;DRโ€‹

  • CLAUDE.md is a markdown file at the repo root that Claude reads first.
  • It encodes your stack, conventions, architecture, and guardrails.
  • Keep it short (โ‰ค 300 lines), specific, and current.
  • Treat it like a living onboarding doc โ€” for humans and the AI.
  • Update it whenever a real-world decision changes.

Why this mattersโ€‹

Think of CLAUDE.md as the employee handbook you hand to a brilliant new hire on day one. Without it, they guess. With it, they ship like a senior teammate.

Bottom line: A great CLAUDE.md is the single highest-leverage file in your repo.


The Big Pictureโ€‹

Bottom line: Context flows top-down โ€” CLAUDE.md sets the tone for everything else.


Ideal Structure (sections to include)โ€‹

SectionPurpose
Project overviewOne paragraph: what this repo is
Tech stackLanguages, frameworks, versions
Project layoutFolder responsibilities
ConventionsNaming, commits, style
Workflows & commandsHow to build/test/deploy
Testing strategyWhat "done" means
Security & data handlingNon-negotiables
Do's & don'tsQuick guardrails
Integrations & MCP serversExternal tools available
Known issues / gotchasSave future-debug time
Pitfalls to avoidPast mistakes encoded
Important project historyWhy things are the way they are

Step-by-Step Setupโ€‹

1. Create the fileโ€‹

touch CLAUDE.md

2. Drop in the skeletonโ€‹

# Project: <your-project>
> One-line summary of what this project does.

## 1. Tech Stack
- Next.js 14 (App Router) ยท TypeScript ยท Tailwind CSS
- Supabase (Auth, Postgres, Storage)
- Prisma ORM ยท tRPC API ยท Zod validation

## 2. Project Layout
- `src/app/` โ†’ Routes (App Router)
- `src/components/` โ†’ Reusable UI components
- `src/services/` โ†’ Business logic
- `src/utils/` โ†’ Helpers & utilities
- `prisma/` โ†’ Schema & migrations
- `tests/` โ†’ Unit & integration tests

## 3. Conventions
- Use TypeScript strict mode.
- Prefer server components; use client only when needed.
- Use functional components & hooks.
- File names: kebab-case. Components: PascalCase.
- Export types explicitly.

## 4. Workflows
- Dev: `npm run dev`
- Build: `npm run build`
- Test: `npm test`
- MCP: GitHub, Postgres, Slack (see `.mcp.json`)

## 5. Testing
- Vitest for units; Playwright for e2e.
- Min 80% line coverage on `src/services`.
- Write tests **before** implementation.

## 6. Security
- No secrets in code or logs.
- Validate all user input with Zod.
- Parameterized queries only.

## 7. Git
- Conventional commits (`feat:`, `fix:`, `chore:`).
- Never commit directly to `main`.
- PRs require: green CI + 1 reviewer.

## 8. Known Issues
- Prisma migrations must be applied before deploy.
- Tailwind purges class names built dynamically โ€” use safelist.

## 9. Do / Don't
โœ… Be specific and concrete.
โœ… Reference docs/ for depth.
โŒ Don't include vague statements.
โŒ Don't put secrets here.

3. Commit itโ€‹

git add CLAUDE.md && git commit -m "docs: add CLAUDE.md"

4. Iterate every sprintโ€‹

Add one section each time you notice Claude getting something wrong.


Variants for Different Team Settingsโ€‹

๐Ÿ‘ค Solo developerโ€‹

Keep it โ‰ค 100 lines. Skip "Git" rules; focus on stack + conventions.

๐Ÿ‘ฅ Small team (2โ€“10)โ€‹

Add Workflows, Testing, and Git rules. Reference docs/onboarding.md for depth.

๐Ÿข Enterprise / regulatedโ€‹

  • Add Security, Compliance, and Data classification sections.
  • Link to internal policy docs.
  • Lock changes behind a code-owner review.
## Compliance
- All PRs must pass `policy-check.sh`.
- PII access requires `@security-auditor` review.
- Data residency: EU only.

๐ŸŒ Open-sourceโ€‹

  • Include Contribution guide + Code of Conduct links.
  • Make examples newcomer-friendly.
  • Mark decisions ([DECISION]) so contributors don't relitigate them.

Bottom line: Same skeleton, escalating depth.


Anatomy of a Single Section (zoom-in)โ€‹

## Conventions
- **Language:** TypeScript strict mode (`"strict": true`).
- **Style:** Prettier defaults + ESLint recommended.
- **Naming:** files `kebab-case`, components `PascalCase`, vars `camelCase`.
- **Imports:** absolute paths via `@/` alias.
- **Comments:** only "why", never "what".

Notice: concrete, enforceable, terse.


Common Patterns & Recipesโ€‹

Pattern 1 โ€” Reference external docsโ€‹

> For deep architecture details, see `docs/architecture.md`.

Pattern 2 โ€” Encode a non-negotiableโ€‹

> โ›” **NEVER** call third-party APIs without a retry + timeout wrapper.

Pattern 3 โ€” Few-shot a conventionโ€‹

### Commit messages โ€” examples
โœ… `feat(auth): add magic-link login`
โœ… `fix(api): handle 429 from Stripe`
โŒ `update stuff`

Pattern 4 โ€” Decision logโ€‹

## Decisions
- [2026-03-12] Chose tRPC over REST for type safety. (Owner: @vk)
- [2026-04-08] Adopted Prisma migrations as the source of truth.

Best Practices โœ…โ€‹

  • Be specific & concrete โ€” examples over adjectives.
  • Show examples for every convention.
  • Keep it concise (< 300 lines).
  • Update when things change.
  • Link to docs for depth instead of inlining everything.

Anti-Patterns โŒโ€‹

  • Vague statements ("write clean code").
  • Outdated info (last edited 9 months ago).
  • Secrets or tokens.
  • Walls of text with no structure.
  • Internal jokes nobody outside the team understands.

Troubleshootingโ€‹

SymptomCauseFix
Claude ignores rulesFile too long / vagueTrim to bullets, add examples
Wrong stack assumedStack section missingPin versions explicitly
Repeated mistakesNo "anti-patterns" sectionAdd it; cite real examples
Drift over timeNot updatedAdd to PR checklist: "Updated CLAUDE.md?"
Sensitive leak riskSecrets in fileRemove; reference env vars

Starter Template (the bare minimum)โ€‹

# Project: <name>
> One-line summary.

## Tech Stack
-

## Workflows
- Dev:
- Build:
- Test:

## Conventions
-

## Security
-

## Notes
-

๐Ÿ’ก Tip: Treat CLAUDE.md like a README for Claude. Keep it living & true.


Glossaryโ€‹

  • CLAUDE.md โ€” Root-level memory file Claude reads first.
  • Convention โ€” A rule the team agrees to follow consistently.
  • Decision log โ€” A dated record of architectural choices.
  • Guardrail โ€” A non-negotiable safety/quality rule.

Further Readingโ€‹

  • Search: "Claude Code project memory CLAUDE.md best practices"
  • Search: "awesome-claude-md examples GitHub"
  • Search: "AI coding agent prompt engineering for repositories"