Home / Blog / CLAUDE.md in Claude Code: project instructions, rules and memory
Updated: 2026-11-24 · 11 min read · Vladyslav Koshelyev

CLAUDE.md in Claude Code: project instructions, rules and memory

TL;DR: CLAUDE.md is an instructions file Claude Code reads at the start of every session: build and test commands, architecture, conventions and things to avoid. A good one is short (under 200 lines), specific and free of contradictions. Larger projects split instructions into .claude/rules/ files scoped to paths.

CLAUDE.md in Claude Code: project instructions, rules and memory
🧩
CLAUDE.md templates (ZIP)Web app, Python API and PHP site + .claude/rules examples and a CLAUDE.local.md sample
Download

The same templates are in the open-source claude-code-kit repository on GitHub.

Why CLAUDE.md matters

Every Claude Code session starts fresh: the model doesn’t remember that yesterday you agreed to run tests with pnpm. CLAUDE.md fixes that — write the essentials once and Claude gets them in context on every launch.

Per the docs, CLAUDE.md content is delivered as a user message after the system prompt. It’s strong guidance, not enforcement. Anything that must never happen belongs in hooks and permission rules in settings.json.

Where the files live and how they load

Claude Code memory file layers: managed policy, user, project, local
Files don’t override each other — they stack, from broad to specific
ScopeLocationUse for
Managed policysystem-wide Claude Code folder (set by IT)organization-wide rules
User~/.claude/CLAUDE.mdyour preferences across all projects
Project./CLAUDE.md or ./.claude/CLAUDE.mdteam instructions, committed to git
Local./CLAUDE.local.mdyour personal project notes; add to .gitignore

All discovered files are concatenated; more specific ones come later.

How Claude discovers CLAUDE.md files

  • Up the tree, at launch: CLAUDE.md files in the working directory and every parent directory.
  • Down the tree, on demand: files in subdirectories load when Claude reads or edits files there — handy in monorepos.
  • Check what’s loaded with /memory.

What to put in CLAUDE.md

  1. Commands: install, run, test, lint — exactly as you run them.
  2. Architecture: where things live and where new code goes.
  3. Conventions: style, naming, preferred libraries.
  4. Don’ts: files not to touch, actions that need a question first.
  5. Pointers to detailed docs via imports.
# Project: shop — Next.js + PostgreSQL

## Commands
- Dev: `npm run dev`
- Tests: `npm test` — run the related test after every change
- Must pass before finishing: `npm run lint && npm run typecheck`

## Don't
- Don't edit .env* or package-lock.json
- Don't add dependencies without asking

Writing instructions Claude follows

  • Under 200 lines per file — longer files consume context and reduce adherence.
  • Specific and verifiable: “use 2-space indentation”, not “format code properly”.
  • Structured: Markdown headings and short bullets.
  • Consistent: if two rules conflict, Claude may pick either one.
  • Notes for humans go in block HTML comments <!-- ... -->, which are stripped before reaching the model.

Imports with @

CLAUDE.md can pull in other files: @docs/api-conventions.md. Paths resolve relative to the importing file, and imports can nest up to four hops. Imports inside code blocks and `code spans` are ignored.

Imports don’t save context — the imported file loads in full. To load instructions only when relevant, use path-scoped rules.

Path-scoped rules in .claude/rules

A rule without frontmatter loads at launch. A rule with paths loads only when Claude works on matching files:

---
paths:
  - "app/api/**/*.ts"
---
# API route rules
- Validate request bodies with zod, return 400 on failure

paths is the only field Claude Code reads from a rule; it accepts a list or a comma-separated string and supports patterns like src/**/*.{ts,tsx}. Personal rules for all projects go in ~/.claude/rules/.

CLAUDE.local.md, /init and /memory

  • CLAUDE.local.md — personal project notes, loaded after CLAUDE.md in the same folder; keep it out of git.
  • /init generates a starter CLAUDE.md, or suggests improvements if one exists. Always edit the result.
  • /memory lists all memory files, opens them for editing and manages auto memory.

Auto memory

Claude Code also keeps its own notes about the project and your preferences in ~/.claude/projects/<project>/memory/, with MEMORY.md as the index. The first 200 lines or 25 KB of the index load at session start; topic files load on demand. Turn it off in /memory or with "autoMemoryEnabled": false in project settings.

The difference: CLAUDE.md is written by you and shared through git; auto memory is Claude’s private notes on your machine.

Monorepos: excluding other teams’ files

Use the claudeMdExcludes setting — an array of path globs, for example in .claude/settings.local.json — to skip CLAUDE.md files you don’t need. Managed policy files can’t be excluded.

Checklist

  1. Run, test and lint commands are present and work.
  2. There’s a map of the project.
  3. Rules are specific and consistent.
  4. Under 200 lines; details live in path-scoped rules.
  5. Hard limits are enforced with hooks or permissions.
  6. Personal notes live in CLAUDE.local.md.

Related: install and safe setup, skills, subagents.

FAQ

Where should CLAUDE.md live?

Team instructions in the project root (./CLAUDE.md or ./.claude/CLAUDE.md), personal preferences in ~/.claude/CLAUDE.md, personal project notes in ./CLAUDE.local.md.

How long should CLAUDE.md be?

The docs recommend under 200 lines per file. Move details into .claude/rules/ with paths so they load only when needed.

Does CLAUDE.md guarantee Claude won’t do something?

No — it’s guidance. Enforce hard limits with hooks and permission rules in settings.json.

What’s the difference between CLAUDE.md and auto memory?

You write CLAUDE.md and commit it; Claude writes auto memory and keeps it locally under ~/.claude/projects/.../memory/.

Let’s talk about your project

Describe the task in a couple of sentences — I reply within one business day. Free and no obligation.

Telegram   Discuss a project

AI assistants for your industry

Services