Claude Code & Terminal AI

The CLAUDE.md File: How to Write Instructions for Claude Code

CLAUDE.md holds the standing instructions Claude Code reads at the start of every session. Where the file goes, what to put in it, how imports, rules and auto memory work, and how to check that it loaded.

By Published Updated

CLAUDE.md is a markdown file of standing instructions that Claude Code reads at the start of every session. Put build and test commands, where things live and the rules for your project in it. Anthropic recommends under 200 lines per file, and run /init to generate a first draft from your code.

CLAUDE.md is a markdown file of standing instructions for Claude Code. Every session starts with a fresh context window, and according to Anthropic's memory documentation, CLAUDE.md files and auto memory are how knowledge carries from one session to the next. You write CLAUDE.md. Claude writes auto memory for itself.

If you run an internal tool you built with Claude Code, such as a quoting app, an intake form or a reporting script, CLAUDE.md is where you write down what you would otherwise explain again each time: how to run it, where things live and what must stay as it is. For what Claude Code is and how to install it, start with What Is Claude Code?.

Where the file goes

Each location has a different reach. The memory docs list them from broadest to most specific:

ScopeLocationWho it reaches
Managed policy/Library/Application Support/ClaudeCode/CLAUDE.md on macOS, /etc/claude-code/CLAUDE.md on Linux and WSL, and a ClaudeCode folder under Program Files on WindowsEveryone in the organization, set by IT
User~/.claude/CLAUDE.mdYou, in every project
Project./CLAUDE.md or ./.claude/CLAUDE.mdEveryone on the project, through version control
Local./CLAUDE.local.mdYou, in this project. Add it to .gitignore

Claude Code loads CLAUDE.md and CLAUDE.local.md from the folder you start it in and from every folder above it. The files are joined together, and none of them replaces another. Content runs from the top of the folder tree down to your working folder, so the file closest to where you started is read last. At each level, CLAUDE.local.md comes after CLAUDE.md.

A CLAUDE.md in a subfolder loads later, once Claude reads, writes or edits a file in that subfolder. That lets a large project keep instructions for one area out of every session.

Start with /init

Run /init inside Claude Code. Claude looks through the codebase and writes a starting CLAUDE.md with the build commands, test instructions and conventions it finds. If the file already exists, /init suggests improvements and leaves your file in place. Setting the CLAUDE_CODE_NEW_INIT environment variable to 1 first switches to an interactive version that asks questions and shows a proposal before it writes anything.

The generated file covers what Claude can see in the code. Your job is to add what it can't see, such as which folder holds live price rules or which script must never run against production.

What to put in it

Anthropic's docs suggest adding to CLAUDE.md when:

  • Claude makes the same mistake a second time
  • a code review catches something Claude should have known about the codebase
  • you type the same correction you typed last session
  • a new teammate would need the same context to be productive

Keep the file to facts that matter in every session: build commands, conventions, project layout and "always do X" rules. A multi-step procedure belongs in a skill, and a rule that only matters for one part of the codebase belongs in a path-scoped rule (see below).

Write each instruction so someone could check it. The docs give these pairs: "Use 2-space indentation" works better than "Format code properly", "Run npm test before committing" works better than "Test your changes", and "API handlers live in src/api/handlers/" works better than "Keep files organized".

Keep each file under 200 lines. The docs say longer files consume more context and reduce adherence. Group related instructions under headings, and remove instructions that contradict each other, because Claude may pick one of them arbitrarily.

An example for an internal tool

Here is a short project file for an invented internal quoting app:

# Quote builder (internal tool)

## Commands
- Install: `npm install`
- Run locally: `npm run dev`
- Tests: `npm test`. Run them before every commit.

## Layout
- Pages are in `app/`. Database queries are in `lib/db/`.
- Price rules are in `lib/pricing/rules.ts`. Ask before changing them.

## Rules
- Never edit a migration in `supabase/migrations/` that has already run. Add a new one.
- Keep customer names and emails out of logs and test fixtures.
- Use 2-space indentation.

Imports, rules and notes for maintainers

A CLAUDE.md can pull in other files with @path/to/file. Relative paths resolve from the file that contains the import, and an import can import other files up to four levels deep. Imported files load together with the CLAUDE.md that names them, so splitting a long file this way organizes it without saving context.

For larger projects, put topic files in .claude/rules/, one topic per file, such as testing.md or security.md. A rule file with no frontmatter loads at the start of every session. A rule with a paths field in its frontmatter loads only when Claude works with a matching file:

---
paths:
  - "src/api/**/*.ts"
---

# API rules
- Every endpoint validates its input.
- Use the standard error response format.

Block-level HTML comments, such as <!-- note for whoever edits this -->, are removed before the file reaches Claude, so you can leave notes for people without using context.

If the repository already has AGENTS.md

Claude Code can read AGENTS.md, the instruction file some other coding agents use. By default it reads AGENTS.md only when there is no CLAUDE.md in your working folder or above it. If you keep both, Claude reads only CLAUDE.md, so the docs suggest starting CLAUDE.md with an @AGENTS.md import and adding anything specific to Claude below it. Reading AGENTS.md directly needs Claude Code v2.1.277 or later.

Auto memory, the notes Claude keeps

Auto memory is on by default in local sessions. Claude saves notes about your preferences, corrections you give it, project context it can't get from the code, and where to find outside information. The notes live in ~/.claude/projects/<project>/memory/. An index file there, MEMORY.md, loads at the start of each session, up to its first 200 lines or 25KB. They stay on your machine and aren't shared across machines.

Run /memory to open your CLAUDE.md files, browse what auto memory saved, or turn auto memory off. The toggle writes autoMemoryEnabled to your user settings. When you ask Claude to remember something, it goes to auto memory. To put it in CLAUDE.md instead, say "add this to CLAUDE.md".

CLAUDE.md or a setting

Claude reads CLAUDE.md as context and tries to follow it, and the docs note there's no guarantee of strict compliance. For something that must hold every time, use configuration. A hook runs a shell command at a fixed point, such as before every file edit, whatever Claude decides. A deny rule under permissions.deny in .claude/settings.json, such as Edit(/.env), stops Claude's built-in file tools from editing that path. The permissions page explains the rule syntax, and the settings page explains which settings file reaches whom.

Check that it loaded

Run /context all in a session and look under Memory files. A file that isn't listed there is one Claude can't see. A subfolder CLAUDE.md won't appear in that list until it loads, and a Loaded line with its path appears in the terminal when it does.

If Claude seems to ignore an instruction, check that the file is in a location that loads, make the wording more specific, and look for a conflicting instruction in another file. Running /doctor prompt-audit (v2.1.283 or later) reports outdated or conflicting instructions and proposes edits, and nothing changes until you ask Claude to apply them. After /compact, Claude reads the project-root CLAUDE.md again from disk, so an instruction kept there survives compaction and one given only in chat may not.

Sources

  1. How Claude remembers your project: CLAUDE.md, rules, AGENTS.md and auto memory (Anthropic documentation) (checked 2026-12-02)
  2. Automate actions with hooks (Anthropic documentation) (checked 2026-12-02)
  3. Configure permissions: permission modes and rules (Anthropic documentation) (checked 2026-12-02)
  4. Settings files and precedence (Anthropic documentation) (checked 2026-12-02)
the list

Get the next one.

Field notes from real deployments, written the way this one was. No schedule promised and nothing sold to you. Unsubscribe whenever.

Frequently asked questions

What is CLAUDE.md?

CLAUDE.md is a markdown file of standing instructions that Claude Code reads at the start of every session. It usually holds build and test commands, coding conventions, the project layout and rules such as files to leave alone. A project file sits at ./CLAUDE.md or ./.claude/CLAUDE.md and is shared through version control.

How do I create a CLAUDE.md file?

Run /init inside Claude Code in your project folder. Claude looks through the codebase and writes a starting file with the commands and conventions it finds. If a CLAUDE.md already exists, /init suggests improvements and doesn't overwrite it. Then add what Claude can't see in the code.

How long should CLAUDE.md be?

Anthropic's docs recommend under 200 lines per CLAUDE.md file, because longer files use more context and reduce adherence. Move instructions that matter for only part of the codebase into path-scoped rules in .claude/rules/, which load only when Claude works with matching files.

Can I have more than one CLAUDE.md in a project?

Yes. Files in the folder you start in and every folder above it load at launch and are joined together, with the closest one read last. A CLAUDE.md in a subfolder loads once Claude reads or edits a file in that subfolder. CLAUDE.local.md holds personal notes for one project.

Does Claude Code read AGENTS.md?

Yes, from v2.1.277. By default it reads AGENTS.md only when there's no CLAUDE.md in your working folder or above it. To use both, start CLAUDE.md with an @AGENTS.md import and add Claude-specific instructions below it.

Need help implementing this?

Prometheus does AI consulting and implementation, remote, with onsite days available in Milwaukee. We set it up, train your team, and make sure it works.

let's talk