CoreCodeDocs

Get the most from CoreCode

How to write CLAUDE.md

Last updated: October 27, 2026

CLAUDE.md is the project briefing Claude Code reads at the start of every session. Written well, Claude stops repeating mistakes; long and messy, it wastes context every turn. This page follows Anthropic's official guide, plus what it means for your bill.

Key points
  • CLAUDE.md is context, not enforced configuration: Claude takes it into account but does not guarantee every rule. Block what must never happen with a hook.
  • Personal rules go in ~/.claude/CLAUDE.md, project rules in ./CLAUDE.md or ./.claude/CLAUDE.md, and your own project preferences in ./CLAUDE.local.md, listed in .gitignore.
  • Write concrete, checkable rules, keep each file under 200 lines, and organize with headings and bullets.
  • Put rules that apply to part of the codebase in .claude/rules/ scoped with paths; write multi-step procedures as skills.
  • It is sent with every turn; an edit made mid-session applies only after /clear, /compact or a restart.

What CLAUDE.md is

A plain Markdown file stating what Claude should know in this project: how to build and test, code conventions, the layout, "always do X" rules. Claude Code reads it at the start of every session as context.

It is not enforced configuration. The more specific and concise the rules, the more consistently Claude follows them; for something that must never happen, such as editing a protected directory, use a PreToolUse hook.

Claude Code also has auto memory: corrections you give it are saved under ~/.claude/projects/<project>/memory/. CLAUDE.md holds the rules you write, auto memory what Claude learns; both load every session.

Where it goes

ScopeLocationWhat it is for
User~/.claude/CLAUDE.mdPreferences for all your projects, such as reply language or tools you use
Project./CLAUDE.md or ./.claude/CLAUDE.mdTeam rules: build commands, code standards, architecture. Commit it
Local./CLAUDE.local.mdYour own preferences for this project, such as a local test URL. Add it to .gitignore

At launch, Claude Code reads CLAUDE.md from the working directory and every directory above it, concatenated from the top down, so the file closest to where you started is read last. A CLAUDE.md in a subdirectory loads later, when Claude reads or edits a file in that subdirectory.

Where to start

Run /init in the project. Claude analyzes the codebase and writes a CLAUDE.md with build commands, test instructions and conventions it finds; if one exists, it suggests improvements instead of overwriting it. Then add what Claude could not discover on its own.

What to put in it

Treat it as the place for whatever you would otherwise explain again. Add a line when:

Keep to facts every session needs. Write multi-step procedures as skills, which load when needed, and put rules for one part of the codebase in .claude/rules.

How to write rules that work

Write rules you could check, not general wishes:

Instead ofWrite
Format code properlyUse 2-space indentation
Test your changesRun npm test before committing
Keep files organizedAPI handlers live in src/api/handlers/

A short example:

# Project

## Commands
- Install: pnpm install (not npm)
- Test: pnpm test, must pass before committing
- Run locally: pnpm dev, port 3000

## Conventions
- TypeScript strict mode, no any
- API handlers in src/api/handlers/, one route per file
- Schema changes only through prisma migrate

Importing other files

Pull in other files with @path, for example See @README and @docs/git-instructions.md. Relative paths resolve from the CLAUDE.md that contains them, and imports nest up to four levels. `@README` inside backticks is not imported.

Imports organize a file but do not reduce its context cost: imported content loads every time too. The first time a project imports a file outside its directory, Claude Code asks you to approve it.

Splitting by scope with .claude/rules

In a larger project, split instructions into topic files under .claude/rules/, such as testing.md or api-design.md. A rule without paths loads at launch like CLAUDE.md; one with paths loads only when Claude works on matching files:

---
paths:
  - "src/api/**/*.ts"
---
# API rules
- Validate every endpoint's input
- Return errors as ApiError

A section of CLAUDE.md that has grown into a multi-step procedure can become a skill, which loads only when used; see the skills guide.

If you already have AGENTS.md

From Claude Code v2.1.277, Claude reads AGENTS.md directly: without a CLAUDE.md it reads AGENTS.md, and with one it reads only CLAUDE.md. To share one file across coding tools, add a line @AGENTS.md to your CLAUDE.md.

Cost and caching

More ways to save are in Spending less on Claude Code.

How to confirm it loaded

FAQ

How long should CLAUDE.md be?

Anthropic recommends under 200 lines per file. Move rules for part of the codebase into .claude/rules/ with paths, and multi-step procedures into skills.

Why doesn't Claude follow my CLAUDE.md?

Usually the rules are vague, the file is long, rules contradict each other, or a mid-session edit has not applied yet. Check with /context that the file loaded, make rules concrete and checkable, and use a hook for anything that must be enforced.

Why didn't my edit to CLAUDE.md take effect?

The running session does not reread it. Run /clear, /compact or restart Claude Code.

Can I use CLAUDE.md and AGENTS.md together?

With a CLAUDE.md present, only CLAUDE.md is read by default. Add @AGENTS.md to your CLAUDE.md to share one set of instructions.