All posts

CLAUDE.md File: What It Is and How to Write One

What CLAUDE.md is, what to put in it (with a copyable template), how Claude Code reads it, and how to view it rendered instead of as raw text.

Short answer: CLAUDE.md is a Markdown file of persistent instructions that Claude Code reads at the start of every session. You use it to tell Claude about your project's build commands, conventions and rules so you don't have to repeat them. Claude treats it as context, not enforced configuration.

If you use Claude Code, you've probably seen it mention a CLAUDE.md file. This post covers what goes in it, where it can live, how Claude Code loads it, a template you can copy, and how to read it rendered. Facts about how Claude Code loads the file come from Anthropic's Claude Code memory documentation, checked on 2026-10-28.


What Is CLAUDE.md?

Each Claude Code session starts with a fresh context window. CLAUDE.md is one of two ways knowledge carries across sessions: it holds instructions you write yourself (the other, auto memory, holds notes Claude writes). Anthropic describes it as the place to write down what you would otherwise re-explain: build commands, conventions, project layout and "always do X" rules.

Claude treats these files as context, not enforced configuration. The more specific and concise the instructions, the more consistently Claude follows them. To block an action regardless of what Claude decides, Anthropic points to hooks rather than CLAUDE.md.


Where CLAUDE.md files live

Claude Code supports several locations, each with a different scope:

ScopeLocationShared with
Project./CLAUDE.md or ./.claude/CLAUDE.mdYour team, via source control
User~/.claude/CLAUDE.mdOnly you, in all projects
Local./CLAUDE.local.md (add it to .gitignore)Only you, in this project
Managed policyOn macOS, /Library/Application Support/ClaudeCode/CLAUDE.mdAll users in an organization

Claude Code loads CLAUDE.md and CLAUDE.local.md from your working directory and every directory above it. Run it in foo/bar/ and it loads foo/bar/CLAUDE.md and foo/CLAUDE.md. The files are concatenated rather than overriding each other. Files in subdirectories under your working directory load on demand, when Claude reads or edits a file in that subdirectory.

To see which memory files loaded, run /context in a session. Run /memory to list your CLAUDE.md files and open one in your editor. Run /init to generate a starting CLAUDE.md from your codebase; if one exists, /init suggests improvements rather than overwriting it.


A CLAUDE.md template you can copy

Replace every placeholder. Keep only the sections that apply to your project.

# Project Name

One or two sentences: what this project is and who it is for.

## Commands

- Install: `npm install`
- Dev server: `npm run dev`
- Test: `npm test`
- Build: `npm run build`

## Project layout

- `src/app/` - pages and routes
- `src/components/` - reusable UI components
- `src/lib/` - helpers and shared utilities
- `src/generated/` - auto-generated, do not edit by hand

## Conventions

- Use 2-space indentation.
- Component files are PascalCase; other files are kebab-case.
- API handlers live in `src/api/handlers/`.

## Rules

- Run `npm test` before committing.
- Never commit `.env` files.
- Ask before adding a new dependency.

## More context

See @README for the project overview.

The last line uses the @path import syntax described below.


Best practices

These follow Anthropic's guidance on writing effective instructions.

  • Be specific enough to verify. "Use 2-space indentation" beats "Format code properly". "Run npm test before committing" beats "Test your changes".
  • Keep it short. Anthropic suggests under 200 lines per CLAUDE.md. Longer files use more context and reduce how well Claude follows them.
  • Use headers and bullets. Organized sections are easier for Claude to follow than dense paragraphs.
  • Avoid contradictions. If two instructions conflict, Claude may pick one arbitrarily. Review your files, including nested ones, now and then and remove outdated rules.
  • Add to it when something repeats. Good triggers: Claude makes the same mistake twice, a code review catches something Claude should have known, or you type the same correction again.
  • Move narrow instructions out. Anything that only matters for part of the codebase can go in a path-scoped rule in .claude/rules/, or a skill, instead of the main file.
  • Keep personal preferences out of the shared file. Use ~/.claude/CLAUDE.md or CLAUDE.local.md.

Importing other files

A CLAUDE.md can pull in other files with @path/to/import. Relative paths resolve relative to the file that contains the import, and imported files can import others up to four hops deep. Imports are loaded into context together with the file that references them, so they organize a long file but do not reduce its context cost. Text inside backticks or code blocks is not treated as an import, so write `@README` if you want to mention a path literally.


Reading CLAUDE.md rendered

A good CLAUDE.md uses headings, tables and code blocks, and in a plain text editor you see the raw symbols. A Markdown viewer shows the formatted version. We make OpenMark, a native Mac Markdown viewer and editor with an iPhone and iPad reader ($9.99 once, offline, no account). It renders tables, Mermaid diagrams and highlighted code. For a comparison of ways to do this, see Best CLAUDE.md Viewer for Mac and Best Apps to Open Claude Markdown Files.


Further reading

Markdown for Developers: README Files, Documentation, and More covers the wider Markdown feature set. For why AI tools output Markdown, see Markdown vs Rich Text.


Download OpenMark: $9.99 once for Mac, iPhone and iPad.

Frequently asked questions

What is a CLAUDE.md file?
CLAUDE.md is a Markdown file of persistent instructions that Claude Code reads at the start of every session. You use it to record build commands, conventions and rules so you do not have to repeat them. Claude treats it as context, not enforced configuration.
Where does Claude Code look for CLAUDE.md?
Claude Code loads CLAUDE.md files from your working directory and every directory above it, plus ~/.claude/CLAUDE.md for your personal instructions in all projects. Files in subdirectories load on demand when Claude reads or edits a file there. Anthropic documents these locations in its Claude Code memory docs.
How do I create a CLAUDE.md file?
Run /init in a Claude Code session to generate a starting CLAUDE.md from your codebase. If one already exists, /init suggests improvements instead of overwriting it. You can also write the file by hand at ./CLAUDE.md or ./.claude/CLAUDE.md.
How long should a CLAUDE.md file be?
Anthropic suggests keeping each CLAUDE.md under 200 lines. Longer files use more context and reduce how consistently Claude follows them. Be specific, for example use 2-space indentation, and move narrow instructions into rules or skills.
How do I view a CLAUDE.md file rendered instead of as raw text?
Open it in a Markdown viewer. TextEdit and other plain text editors show the raw symbols. OpenMark, which we make, is a native Mac, iPhone and iPad viewer that renders tables, Mermaid diagrams and highlighted code, costs $9.99 once and works offline.