Claude · Setup

CLAUDE.md: the file that decides how good Claude Code is

One file explains why Claude Code is brilliant on one project and mediocre on another. Seven tips to write it, keep it short, and keep it alive.

QQuentin Megevand
July 19, 2026 · 10 min read

You open Claude Code on one project and it understands everything on the first try. You open it on another and it reinvents your folder structure, runs the wrong test command, and suggests a library you banned six months ago. Same tool, same model, opposite results.

The difference almost never comes from the model. It comes from a text file at the root of your project.

That file is CLAUDE.md. Claude Code reads it automatically at the start of every session, before you have typed anything. It is the one place where you can hand over, once and for all, what it cannot figure out by reading your code. Most people create it once, never reread it, and wonder why the agent keeps making the same mistakes.

Claude AI Lab

The Claude AI Lab is my Skool community where I share my Claude systems and the more advanced modules. Access is $67/month.

Join the Lab →
What you need
1
Claude Code installed. The CLI, in your terminal, on a project that already exists.
2
A project with some history. The file only has value if there are conventions worth writing down. On an empty folder, there is nothing to hand over.
3
Ten minutes. That is the real cost of the first version. The rest happens session by session.
The principle in one sentence

Anything you tell the agent more than once belongs in this file. If you are repeating it, it is not in there.

1

Understanding what it actually is

🗺️ Table of contents, not documentation

The starting mistake is treating CLAUDE.md as technical documentation. People dump the full architecture into it, the rationale behind every choice, the history of the project. The file swells, and its value drops.

This file is a table of contents. Its job is not to contain everything, it is to say where everything lives. Where the code sits, which commands to run, which conventions to respect, and which documents to open for the detail.

⚙️The right way to think about it
4
Write what the code does not say. The agent reads your code very well. It cannot guess why you abandoned an approach, or which unwritten rule the team agrees on.
5
Point, do not copy. One line saying "API specs live in docs/api.md" beats three hundred lines of specs pasted into the file.
6
Think about the new hire. The right test is the colleague who just joined: can they read this in two minutes and know how to work in your project?
The two-minute test

If a new developer cannot read your CLAUDE.md in two minutes and get to work, neither can the agent.

2

Letting Claude write the first draft

⌨️ The /init command

The blank page is the real reason this file does not exist in most projects. Nobody knows where to start, so nobody starts.

You do not have to write the first version yourself. From your project root:

claude

Then, inside the session:

/init

Claude Code walks the project, picks up the stack, the scripts, the folder layout and the recurring patterns, then generates a starting CLAUDE.md from it. You go from nothing to a structured base in one command.

Why it works

The agent is very good at describing what is observable in your code. That is exactly half the job. The other half, the one it cannot do, is the next tip.

3

Treating the output as a draft

✏️ The step almost everyone skips

This is where most people stop. They run /init, see a file appear, decide it is done, and move on. The result is a file that correctly describes the surface of the project and misses everything that matters.

What /init produces is a starting point, never a finished deliverable. It needs a line-by-line review.

⚙️The review pass
7
Fix what is wrong. The agent infers, so it sometimes gets it wrong. An outdated build command sitting in the file is a mistake you pay for in every single session.
8
Delete what is generic. "This project uses React" teaches nobody anything. Anything the agent can see by opening package.json does not belong there.
9
Add what it could not know. The decisions, the bans, the traps. "Never use library X, it breaks the production build." "Migrations always go through script Y, never by hand." That is where all the value is.
The habit to build

Maintain this file like code, not like a note. It gets reread, corrected, and committed with the rest.

4

What actually belongs in it

🧱 The four blocks that matter

A structure that holds on just about any project, in this order.

📌
The project summary
Three lines. What the product does, who for, and where it stands. It frames everything else.
🌳
The useful tree
Not the full tree. The five or six folders that matter, one line each on what they hold.
⌨️
The commands
Install, run, test, build. Your project's real commands, copyable as is.
🚫
The rules
Conventions and bans. The shortest section to write and the highest return in daily use.

At the end of the file, add the pointers to deeper documentation: the spec file, the contributing guide, the database schema. One line per pointer, with the exact path.

The section nobody writes enough of

The rules. It is the one that changes the agent's behaviour session after session, and the one /init cannot generate for you.

5

Keeping it short, no exceptions

📏 Around 200 lines, official target

The tip almost everyone ignores, and the one with the most impact.

A CLAUDE.md that swells dilutes its own instructions. When a critical rule is buried in six hundred lines of context, it carries less weight in the agent's attention than it would among eighty. You do not get more compliance by writing more, you get less.

Two hundred lines is the official target, and the stated reason is exactly that trade-off: longer files eat more context and reduce adherence. Past that point, you have started pasting documentation instead of pointing to it.

⚙️When the file overflows
10
Move the detail into a dedicated file. API specs, test conventions, decision history go to docs/. The CLAUDE.md keeps one line pointing there. You can even import it explicitly with the @docs/api.md syntax, which pulls the file's content in at load time (imports chain, up to four levels deep).
11
Cut anything inferable. If the agent can learn it by reading a config file, the line earns nothing.
12
Keep the rules, sacrifice the explanations. "Never commit straight to main" is enough. The paragraph justifying the rule can go.
The real trade-off

A short file the agent follows beats an exhaustive file it follows loosely. The most productive version is always the leanest.

6

Using the three memory levels

🧩 Global, project, subfolder

Here is the point guides on this topic almost always skip, and it completely changes how you hold the previous tip. CLAUDE.md is not a single file, it is a layered system where every level stacks.

🌍
Global level
~/.claude/CLAUDE.md. Loaded on every project you own, no exceptions. This is where your personal preferences live: your language, your response style, your security rules.
📁
Project level
./CLAUDE.md at the repo root. Committed, shared with the team. Everything specific to this project.
🔍
Subfolder level
A CLAUDE.md inside src/api/, for example. It carries the context specific to that part of the code without polluting the root file.

The benefit is immediate: your root file no longer has to carry the rules of every sub-area of the project. You push the detail down to the level where it applies, and the root stays under your two hundred line ceiling.

The detail that makes this genuinely pay off: subfolder files are not loaded at startup. They enter the context only when the agent touches files in that folder. In other words, you can be precise and detailed in src/api/CLAUDE.md without spending a single line of context on the sessions where you are not working on the API.

⚙️How to split it
13
What follows you everywhere goes global. "Answer me in French." "Never paste an API key value into the chat." That has no business sitting in a client's repo.
14
What concerns the team goes in the repo. Conventions, commands, project bans. This file gets reviewed in code review like everything else.
15
What concerns one folder stays in that folder. The rules for your migrations folder have no reason to be read while you work on the front end.
The most useful side effect

The global level is what makes Claude Code consistent from one project to the next. You write your preferences once, they apply everywhere, including on projects you will open six months from now.

7

Maintaining it without thinking about it

🔄 Turning it into a living system

A CLAUDE.md written once and then forgotten goes stale within weeks. Commands change, conventions evolve, and the file turns into a source of errors instead of a source of truth. The problem is not willpower, it is timing: nobody opens their editor to document a rule in the middle of a task.

The fix is to capture the rule at the exact moment it shows up, without leaving your session. There is nothing special to learn: ask in plain language, and the agent saves it to memory.

Remember that tests run with npm run test:unit, never with npx jest directly.

That is three seconds instead of a round trip through your editor, and it is the whole difference between a living file and a dead one.

⚙️The maintenance loop
16
Every correction becomes a rule. The moment you correct the agent is the best signal there is: it just did something your file should have prevented. Have the rule saved right then.
17
Review your files with /memory. The command lists your memory files and opens them in your editor. One cleanup pass every few weeks is enough to cut the rules that went stale.
18
Have the agent audit it. Paste your file into a session and ask: "What in here is generic, wrong, or inferable from the code? What is missing for a new developer to be autonomous?" It cuts efficiently.
The signal that it is current

If you have not had to repeat the same instruction twice this month, your file is doing its job. If you are repeating it, you just found the next line to write.

What this file will not do for you

Two points of honesty.

The first: CLAUDE.md steers, it does not constrain. A written rule is a strong instruction, not a technical barrier. For things that must never happen, a line in a file does not replace a real safeguard on your project's side.

The second: it does not make up for an unreadable project. If your structure is incoherent and your commands are broken, describing that mess cleanly does not tidy it. The file speeds up a healthy project, it does not rescue a sick one.

Where to start

Open your most active project, run /init, and give yourself ten minutes of serious review. Cut the generic lines, add the three bans you repeat the most, and check that you are under two hundred lines.

Then build the habit that actually matters: next time you correct the agent, do not just correct it. Have the rule written down.

The takeaway

How good Claude Code is on your project is not a property of the model. It is a property of what you wrote for it before you started.

Want to go further?

And day-to-day, I post one reel a day on Instagram: @quentin_iamarketing