Skip to content
Anyway Works
Plan a call
Plan a call

CLAUDE.md: what to put in it, with an example

CLAUDE.md is a plain text file that Claude Code reads at the start of every session. Put in it what you would otherwise explain again each time: how to build and test the project, its conventions and where things live. Keep it under 200 lines and write each line so it can be checked. Run /init to get a first version.

No Claude Code yet? On Windows it is one command: install Claude Code on Windows.

Where does CLAUDE.md go?

There are four places, and Claude Code reads all that apply:

WhereFor whomUse it for
./CLAUDE.md or ./.claude/CLAUDE.mdEveryone on the project, through gitBuild commands, conventions, layout
./CLAUDE.local.mdOnly you, in this projectYour test data, your local addresses. Add it to .gitignore
~/.claude/CLAUDE.mdOnly you, in every projectYour own preferences
A managed file set by ITEveryone in the organisationCompany rules

Files above the folder you start in are loaded at the start; files in subfolders load when Claude works in that folder. They add up rather than replace each other, and the one closest to where you started is read last.

What belongs in it?

The docs give a test: write it down when

  • Claude makes the same mistake a second time,
  • a code review catches something Claude should have known,
  • you type the same correction you typed last session,
  • a new teammate would need the same context.

Keep it to facts that matter in every session. A procedure of several steps belongs in a skill; a rule for one part of the code belongs in a rule file under .claude/rules/, which can be set to load only for matching files.

How do you write a line Claude follows?

Concrete enough to check. The docs’ own examples:

  • “Use 2-space indentation” instead of “Format code properly”
  • “Run npm test before committing” instead of “Test your changes”
  • “API handlers live in src/api/handlers/” instead of “Keep files organized”

Group lines under headings. Remove lines that contradict each other: Claude may pick either one.

How long can CLAUDE.md be?

The docs say: “target under 200 lines per CLAUDE.md file. Longer files consume more context and reduce adherence.” Importing other files with @path/to/file keeps the file tidy but does not save room, because imported files load with it.

An example

# Shop website

## Commands
- npm run dev: local server on port 4321
- npm test: unit tests. Run before every commit
- npm run build: production build to dist/

## Layout
- Pages in src/pages, one file per address
- Product data in src/data/products.json, never in a page

## Conventions
- TypeScript strict. No any
- Prices are cents as integers, never floats
- Every image has width, height and alt text

## Never
- Never edit files in dist/
- Never commit .env

About twenty lines, each one checkable. That is the size most projects need.

Does Claude Code read AGENTS.md?

Yes. A repository with an AGENTS.md and no CLAUDE.md works as it is: Claude Code reads the AGENTS.md. When both exist, it reads CLAUDE.md only, unless your CLAUDE.md imports AGENTS.md with @AGENTS.md. Reading AGENTS.md directly needs Claude Code 2.1.277 or later.

Is CLAUDE.md a rule Claude must follow?

No. “Claude treats CLAUDE.md files and auto memory as context. They aren’t enforced configuration.” For something that must always or never happen, such as never touching .env, use a hook: a command that runs at a fixed moment, whatever Claude decides. We explain them in Claude Code hooks explained.

Sources

Want a project set up so the AI stops guessing? Plan a call.

Read from the Claude Code documentation on 3 December 2026.

New posts and news about our products, such as Hocusclick, now and then. Every mail has a link that stops it. See the privacy policy.

contact@anywayworks.com