Course navigation
Claude CodeLesson 11 of 25

The CLAUDE.md File

Every time you start a Claude Code session, it reads a file called CLAUDE.md from your project root. Whatever is in that file becomes permanent context — your stack, conventions, folder structure, and commands — loaded automatically, every session, without you having to repeat it.

Write once, remembered forever

Without CLAUDE.md, every new session starts blank. You re-explain the stack, remind Claude which folders to use, and clarify naming conventions. With CLAUDE.md, all of that is already there — Claude reads it before your first message.

  • No re-explaining the stack on every session
  • Consistent file locations and naming
  • Conventions followed without repeating yourself

Before vs after CLAUDE.md

Same task, same Claude Code. The difference is entirely in what context is available at the start of the session.

Without CLAUDE.mdWith CLAUDE.md
First responseAsks which framework, folder, and styling approachGoes straight to code using project conventions
Component locationMay create files in the wrong directoryUses src/components/ as documented
StylingGuesses CSS variables or TailwindFollows the Tailwind + ThemeProvider pattern
Session overheadSeveral clarifying questions before any codeContext loaded before your first message
Claude Code prompt
> add a dark mode toggle
Claude: I'll create src/components/DarkModeToggle.tsx
as a 'use client' component using Tailwind's
dark: classes and the existing ThemeProvider.
The second session works because CLAUDE.md already told Claude the framework, component folder, styling approach, and pattern to use.

What to put in CLAUDE.md

Six categories cover the information Claude needs most. Add sections as your project grows — add a new entry the first time you find yourself repeating context.

SectionPurposeExample
Stack & frameworkWhat technology the project usesNext.js 15 App Router, TypeScript, Tailwind CSS, Prisma
Folder structureWhere things liveComponents: src/components/, API: src/app/api/
ConventionsNaming, formatting, and code style'use client' only when needed; PascalCase components
TestingFramework, file location, commandsVitest in src/__tests__/; npm run test
Dev commandsStart, build, lint, type-checkDev: npm run dev; Lint: npm run lint
What to avoidPatterns or packages you do not wantNo any type; do not modify prisma/schema.prisma without asking

A real CLAUDE.md example

Here is a complete CLAUDE.md for a Next.js SaaS app. Use it as a template and trim what does not apply to your project.

CLAUDE.mdMarkdown
# CLAUDE.md — my-saas-app
## Stack
- Framework: Next.js 15 App Router, TypeScript
- Styling: Tailwind CSS + shadcn/ui components
- Database: PostgreSQL via Prisma ORM
- Auth: NextAuth.js v5 (App Router config)
- Payments: Stripe
## Folder Structure
- Components: src/components/
- Pages: src/app/ (App Router)
- API routes: src/app/api/
- DB client + queries: src/lib/db/
- Types: src/types/
- Tests: src/__tests__/
## Conventions
- Use 'use client' only when component needs state or events
- No console.log in production code
- All DB queries go through src/lib/db/ — never inline in routes
- Component names: PascalCase. Files match component name
- Error handling: try/catch in all async server actions
## Testing
- Framework: Vitest
- Files: src/__tests__/ (filename.test.ts)
- Run: npm run test
## Commands
- Dev: npm run dev
- Build: npm run build
- Lint: npm run lint
- Type check: npx tsc --noEmit
- DB migrate: npx prisma migrate dev
## Avoid
- Do not use: any type, moment.js
- Do not modify: prisma/schema.prisma without asking
- Do not add new shadcn components without checking existing ones first
A complete CLAUDE.md at the project root

This file sits at the project root alongside package.json. Claude reads it automatically at the start of every session.

Where CLAUDE.md files live

You can have more than one. Claude reads all of them and merges the context.

LocationScopeUse for
CLAUDE.md (project root)Every session in this projectStack, conventions, and dev commands
src/components/CLAUDE.mdWhen working inside that folderFolder-specific rules, e.g. component library conventions
~/.claude/CLAUDE.mdEvery project on your machinePersonal preferences: code style, language, response format

How to create it

Three approaches — all valid. Pick whatever fits your workflow.

  1. Ask Claude to write it. Open a session in your project and ask it to inspect package.json, folder structure, and config files, then generate a CLAUDE.md at the root.
  2. Use the /init command. Type /init in the prompt box. Claude scans the project and creates a first draft you can edit.
  3. Write it by hand. Create CLAUDE.md at the project root in any text editor. Plain Markdown — no special syntax.
Claude Code prompt
> Look at @package.json and the project structure, then create a CLAUDE.md
at the root that documents the stack, folder conventions, dev commands,
and anything Claude should always know about this project.

Keeping it up to date

CLAUDE.md is a living document. The right time to update it is the moment you notice yourself re-explaining something to Claude.

SignalWhat to add
You added a new packageAdd it to the Stack section with a one-line description
You corrected Claude on where to put a fileUpdate the Folder Structure section with the correct path
Claude used a pattern you do not wantAdd it to Avoid with the preferred alternative
You have a new npm script the team uses dailyAdd it to Commands so Claude can run it correctly
A new convention was agreed in a code reviewAdd it to Conventions so Claude follows it from now on
Commit CLAUDE.md to git. Every team member and CI pipeline that uses Claude Code in this repo will benefit from it automatically.

Before you continue

  • CLAUDE.md gives Claude permanent project context on every session.
  • Cover stack, folder structure, conventions, commands, and things to avoid.
  • Place it at the project root; subdirectory and global files work too.
  • Use /init or ask Claude to generate a first draft, then refine by hand.
  • Next lesson: Settings and Configuration.

What's Next

CLAUDE.md gives Claude your project context on every session. Next: settings.json — model selection, auto-approval rules, and tool configuration.