The one file that stops you re-explaining your codebase to Claude Code every single session.

CLAUDE.md: The Complete Guide

Sep Gaspari|May 29, 2026|14 min read
Share:

Every session, you tell the agent the same things. Use pnpm, not npm. Build with this command. Don't touch the parent theme. Deploy goes through Hostinger, not Vercel. The CLAUDE.md file exists so you stop repeating yourself. It is Claude Code's project-memory file: a Markdown document that loads automatically at the start of every session and tells Claude how your codebase works before you type a word.

Get the CLAUDE.md file right and the agent already knows your stack, your conventions, your exact commands, and your guardrails. Get it wrong, or skip it, and you burn tokens and patience re-briefing a fresh context every time. This guide covers what to put in it, where it lives, and the Claude Code best practices that keep it lean.

We will work from real files, not theory: an annotated example, six stack templates (Next.js, WordPress, Node, Python, monorepo, agency-client), and the token-saving rules that separate a CLAUDE.md that helps from one that quietly bloats every prompt. This is the deepest spoke in our Claude Code guide, so if you are new to the tool, start there first.

What Is a CLAUDE.md File?

A CLAUDE.md file is Claude Code's project-memory file: a Markdown document the agent loads automatically at the start of every session so you never have to re-explain your stack, conventions, commands, and guardrails. It functions like a system prompt scoped to one project, except you own it, you version it with git, and you edit it whenever the project changes.

Without a claude md file, every session starts cold. Claude opens your repo with zero context about which package manager you use, how you run tests, or what it must never break. You spend the first few exchanges briefing it, and you do that again tomorrow. With a CLAUDE.md, that briefing is permanent and shared with every teammate who clones the repo.

The mental model that helps most: CLAUDE.md is the contract between you and the agent. It states three things clearly.

  • What this project is: the stack, the framework, the deploy target
  • How to operate it: the exact build, test, lint, and deploy commands
  • What the rules are: the conventions to follow and the lines never to cross

Why it matters now: as agents take on multi-step work across many files, the cost of a vague briefing compounds. A precise CLAUDE.md is the cheapest, highest-leverage change you can make to the quality and consistency of every Claude Code session. It is the difference between an agent that guesses and one that follows your house rules.

Where CLAUDE.md Lives and How It Loads

CLAUDE.md is read from a few locations, each with a different scope. Knowing which file does what keeps personal preferences out of shared repos and shared rules out of your personal config.

LocationScopeCommitted to git?Use it for
./CLAUDE.md (project root)This project, all teammatesYesStack, commands, conventions, deploy method
~/.claude/CLAUDE.md (global)Every project, just youNoPersonal style, default tools, your preferences
subdir/CLAUDE.md (nested)One package in a monorepoYesPer-package overrides that beat the root file

The loading rule is simple: project root and global both load at session start, and nested files apply when Claude is working inside that subtree. A per-package CLAUDE.md overrides the root file for that package, which is exactly what you want in a monorepo where the frontend and the API have different commands.

There is a real cost to remember here. The full contents of every applicable CLAUDE.md are loaded into context on every session and re-loaded after each compaction. The file's length is a recurring token cost, not a one-time setup. That single fact drives most of the Claude Code best practices below.

Quickest way to create one

Run /init inside Claude Code. It scans the repo and drafts a starter CLAUDE.md. Then edit it down hard. The auto-draft is a starting point, not the finished file. For a full rundown of pre-built starter files, our Claude Code token optimization guide pairs well with this section.

What to Put in Your CLAUDE.md

A useful CLAUDE.md is short and concrete. Aim for roughly 30 to 80 lines for most projects. Here is a real, annotated example for a statically exported Next.js site, the kind of file that earns its place in context:

# Project Config — Acme Marketing Site

## What this is
A statically-exported Next.js site (output: 'export') for Acme.
Built once, deployed as plain HTML to Hostinger. No server runtime.

## Stack
- Next.js 15, App Router, output: 'export' -> static /out
- Tailwind CSS · TypeScript · pnpm
- Forms: Web3Forms (no API routes — static export can't run them)

## Commands
pnpm dev        # local dev at http://localhost:3000
pnpm build      # static export -> ./out
pnpm lint       # ESLint
pnpm typecheck  # tsc --noEmit

## Conventions
- Smallest reasonable diff. Match existing style and naming.
- grep before reading; read specific line ranges, not whole files.
- Images: WebP, explicit width/height, hero loading="eager", rest lazy.
- No secrets in the client bundle (only NEXT_PUBLIC_* reaches it).

## Gotchas
- No API routes / getServerSideProps — static export breaks on them.
- Test against ./out (npx serve out), not the dev server. They differ.

## Deploy method
This project deploys via: pnpm build, then upload ./out to Hostinger
public_html. Never deploy without confirmation. Verify the live URL after.

Notice what is and is not in there. Every command is exact and copy-pasteable. The gotchas are things that have actually broken builds, not generic advice. The deploy method is spelled out so the agent does not invent one. And there is a hard rule about reading behavior that saves tokens on every single task. Each line either changes what the agent does or stops it from doing something wrong.

Here is the checklist of sections worth including, in priority order:

  • What this is: one or two lines on the project and deploy target so the agent has orientation.
  • Commands: exact build, test, lint, typecheck, and run commands. This is the highest-value section.
  • Conventions: code style, naming, diff size, and the grep-before-read rule.
  • Gotchas: real footguns that have bitten this project before, not hypotheticals.
  • Deploy method: the exact steps, plus "confirm before deploying" for anything outward-facing.

What to leave out matters just as much. No credentials, no API keys, no long explanations of code the agent can read for itself, and no aspirational rules you do not actually enforce. If a section never changes the agent's behavior, it is dead weight loaded into context on every prompt.

CLAUDE.md Best Practices (Token-Saving Rules)

Because CLAUDE.md loads on every session and after every compaction, the most important Claude Code best practices are about keeping context lean. A bloated file does not just waste tokens once. It taxes every prompt for the life of the project. These rules pay off continuously.

1. Tell Claude to grep before it reads

The single biggest token sink is reading whole files to find one function. Add a rule that makes the agent search first, then read only the match. A line like the one below changes default behavior across every task:

## Reading the codebase
- grep/search for the symbol first; do NOT read whole files to find one thing.
- Read specific line ranges around the match, not the entire file.
- Map structure with a search before opening files speculatively.

This is grep-before-read, and it is the highest-leverage rule in any CLAUDE.md. On a large file, reading a 40-line range instead of 2,000 lines can cut a task's context use by an order of magnitude.

2. Prefer pointers over content

Do not paste your full coding standards or a long architecture doc into CLAUDE.md. Point to it. "Detailed standards in docs/STANDARDS.md, read on demand" keeps the long content out of every-session context while still making it reachable when a task actually needs it. The file holds rules and pointers; the rules pull in content only when relevant.

3. Scope instructions to the right file

Personal preferences (your editor, your default package manager, your tone) go in the global ~/.claude/CLAUDE.md. Project rules go in the committed repo file. Mixing them bloats the shared file with things only you care about and pollutes teammates' context. Scope keeps both files short.

4. Make standards concrete and enforceable

"Write clean code" does nothing. "Smallest reasonable diff, match existing naming, run the check and paste the output before claiming a pass" changes behavior. Standards that are specific and verifiable get followed. Vague aspirations get ignored and still cost tokens.

Warning: a long CLAUDE.md is not a thorough one.

Teams often grow CLAUDE.md to 300+ lines thinking more rules means more control. The opposite happens: the signal drowns, the agent skims, and you pay the full length on every prompt. If a line has not changed an outcome, cut it. A tight 50-line file outperforms a sprawling one almost every time.

Want a Battle-Tested CLAUDE.md to Start From?

Grab the free Agent Team Starter Pack. It ships with a ready-to-use CLAUDE.md, a set of stack templates (Next.js, WordPress, Node, Python, monorepo, agency-client), and a 5-agent team config you drop straight into any repo. No fluff, no signup wall beyond an email.

Get the Free Agent Team Starter Pack

CLAUDE.md Templates by Stack

The sections that matter shift by stack. A static site cares about export rules; a Node API cares about migrations and auth; an agency-client repo cares about deploy safety. Here is what each template emphasizes so you can lift the right starting point:

StackCLAUDE.md emphasizesSignature gotcha
Next.js (static)Export rules, image handling, sitemap/metaNo API routes or SSR in output: 'export'
WordPressEdit transport, Gutenberg blocks, cache purgeNever edit the parent theme; dry-run search-replace
Node APIValidation at the boundary, authz, migrationsMigrations additive-first; confirm before prod
PythonUse the project interpreter, ruff, mypy, pytestMutable defaults, naive datetime.now()
MonorepoPackage boundaries, scoped commands, nested filesA passing app build does not prove dependents pass
Agency / clientDeploy safety, scope, "local files are truth"Never git checkout/restore to fix production

Two patterns are worth copying regardless of stack. First, the agency-client template treats the live site as the source of truth and leans conservative: confirm before anything outward-facing, back up before risky changes, and never use git to drive a deploy. Second, the monorepo template uses nested CLAUDE.md files so each package overrides the root with its own commands. The root holds only what is true repo-wide.

All six templates ship in the free starter pack, with the deploy-method slot left blank for you to fill per project. They pair naturally with skills and MCP servers, which we cover in our Claude Code skills and MCP servers guides.

CLAUDE.md + Subagents and MCP

CLAUDE.md does its best work as the shared rulebook for a team of agents, not just a single thread. When you run subagents, each one operates in its own context window. The standards in your CLAUDE.md, smallest diff, evidence before claims, stay in scope, confirm before destructive actions, apply to every agent in the chain. The file is the constitution they all follow.

This is also where the token math gets interesting. A researcher subagent can sweep 40,000 tokens of codebase, then hand the orchestrator only a distilled summary. The main thread stays clean, and your CLAUDE.md rules ensure each specialist behaves consistently without you re-briefing it. Memory (CLAUDE.md) plus a team (subagents) is a multiplier, not just a convenience.

Where MCP fits

MCP (Model Context Protocol) servers give the agent tools: a database it can query, a browser it can drive, a deploy API it can call. CLAUDE.md is where you tell Claude which MCP tools this project uses and when to reach for them. A line like "deploy via the Hostinger MCP tool, never bare CLI flags" turns an available capability into a reliable habit.

Together the three layers form a stack: CLAUDE.md is the memory and the rules, subagents are the labor split across clean contexts, and MCP is the set of hands that reach outside the codebase. The agency-client template wires this up explicitly, routing deploys through the shipper agent under the "confirm before outward-facing actions" rule. To build the team side out fully, our free Claude Code agent team starter pack includes the CLAUDE.md plus the agent definitions that read it.

Common CLAUDE.md Mistakes

After writing and auditing a lot of these files, the same mistakes show up over and over. Avoid them and your CLAUDE.md stays an asset instead of becoming a tax.

1. Letting it grow unbounded

The most common failure is a CLAUDE.md that only ever grows. Every incident adds a rule, nothing is ever removed, and a year later it is 400 lines loaded on every prompt. Prune it like code. If a rule has not changed an outcome recently, cut it.

2. Vague rules that change nothing

"Follow best practices" and "write good tests" are noise. They cost tokens and steer nothing. Replace every vague line with a concrete, verifiable instruction or delete it.

3. Putting secrets in the file

CLAUDE.md is committed to git and read into context constantly. Credentials, API keys, and tokens do not belong in it. They belong in a password manager or environment variables. The file should reference where creds live, never contain them.

4. Missing the deploy method

If the file does not state how the project ships, the agent will guess, and a wrong guess on deploy is expensive. Every CLAUDE.md should fill its deploy-method slot with exact steps and a "confirm first" rule for anything outward-facing.

5. Skipping the grep-before-read rule

Without an explicit reading rule, the agent defaults to opening whole files to find one symbol. On a large codebase that quietly burns your context budget all day. One line fixes it. Leaving it out is the most expensive omission in this list.

Frequently Asked Questions

What is a CLAUDE.md file?

A CLAUDE.md file is Claude Code's project-memory file. It is a Markdown document Claude Code loads automatically at the start of every session, so you do not have to re-explain your stack, conventions, commands, and guardrails each time. Think of it as a persistent system prompt scoped to one project: it tells the agent how this codebase works and how you want it to behave.

Where does the CLAUDE.md file go?

The main CLAUDE.md lives in your project root and is committed to git so the whole team shares it. Claude Code also reads a global file at ~/.claude/CLAUDE.md for personal preferences that apply across every project, and it will pick up nested CLAUDE.md files in subdirectories for monorepos. Project root is the one almost every repo needs.

How do I create a CLAUDE.md file?

Run the /init command inside Claude Code and it scans your repo and drafts a starter CLAUDE.md. Then edit it by hand: trim it to what actually matters, add your exact build and test commands, document your deploy method, and list any non-obvious gotchas. A hand-tuned 30 to 60 line file beats an auto-generated 300 line one.

Does CLAUDE.md use up my token budget?

Yes. The entire file is loaded into context on every session and every compaction, so its length is a recurring cost, not a one-time one. That is why the best CLAUDE.md files are short and high-signal. Put rules and pointers in the file, not the content those rules point to, and let Claude grep and read on demand instead of pre-loading everything.

What is the difference between CLAUDE.md and a system prompt?

A system prompt is set by the application and is invisible to you. CLAUDE.md is a file you own, version with git, and edit freely. It layers on top of Claude Code's built-in behavior to give project-specific instructions. Functionally it acts like a per-project system prompt that travels with the repository.

What are the most important Claude Code best practices for CLAUDE.md?

Keep it short and high-signal. Tell Claude to grep before reading and to read specific line ranges instead of whole files. Include exact commands (build, test, lint, deploy). Document gotchas that have actually bitten you. Define a clear deploy method. And scope instructions: global preferences go in ~/.claude/CLAUDE.md, project rules go in the repo file.

How is CLAUDE.md different from .cursorrules or other AI config files?

They serve the same purpose, persistent project instructions for an AI coding agent, but each tool reads its own filename. CLAUDE.md is Claude Code's file. The principles transfer: be concrete, give commands, state guardrails. If you migrate from Cursor, you can usually port the substance of a .cursorrules file into CLAUDE.md with light editing.

Should I commit CLAUDE.md to git?

Yes, commit the project-root CLAUDE.md so every teammate and every Claude Code session shares the same instructions. Keep secrets and personal preferences out of it: credentials belong in a password manager, and your individual style settings belong in the global ~/.claude/CLAUDE.md, which is not committed to the project.

Go From CLAUDE.md to a Full Agent Workflow

A great CLAUDE.md is the foundation. The next level is a repeatable system: subagents that split the work across clean contexts, MCP servers that reach outside the codebase, and skills that package your repeatable tasks. That is the entire Build With Claude Code course.

It is a $299 hands-on course that takes you from a single-thread user to running an agent team on real projects. Founding members get early access and lifetime updates. Join the waitlist and you will be first in when enrollment opens.

Join the Founding Member Waitlist

Want it done for you? If you would rather have your repos set up with a tuned CLAUDE.md, an agent team, and a clean workflow without learning all of it yourself, we run a hands-on workflow audit.

Book a $750 Workflow Audit

Related reading:

Last updated: May 2026

Sep Gaspari

Written by

Sep Gaspari

Founder & Digital Marketing Strategist, Zio Advertising | Kelowna, BC

15+ years in digital marketing, Google Ads, and SEO. I've helped businesses across 12+ industries generate qualified leads and grow revenue through data-driven strategies. I don't just run campaigns—I obsess over results, test relentlessly, and treat your budget like it's my own.

Connect on LinkedIn
Zio team member

Got a quick question?

Sep usually replies within a few hours

Or email us at sep@zioadvertising.com