How to write a CLAUDE.md file for Claude Code

Day 4, 25 minutes · beginner

Goal of this lessonCreate a short CLAUDE.md with /init, cut it down to what Claude cannot see in your files, and check that a fresh session loads and follows it.

Why it matters

Every Claude Code session starts fresh. Claude does not remember yesterday's conversation, so the price format you explained on Monday is gone on Tuesday. You can repeat yourself every day, or you can write it down once in a place Claude reads at the start of every session.

That place is a file called CLAUDE.md: a short note in plain text in your project folder. It holds the things Claude cannot work out by reading your files, such as your rules, your way of checking a change and the mistakes you have already corrected twice.

Today you create one for Tilda's site with a single command, cut it down to what matters, and test that a new session follows it. At the end your practice repo has a CLAUDE.md of at most 20 lines that you wrote together with Claude and checked yourself.

What CLAUDE.md is

CLAUDE.md is a markdown file: plain text with a few marks for headings and lists. Claude Code loads it into the context at the start of every session. The memory page of the docs calls it persistent instructions: you write them once, and every new session gets them.

It is context, not a lock. Claude reads it and tries to follow it, and the docs are clear that there is no guarantee. For a rule that must never be broken, Claude Code has stronger tools, such as the permission rules in lesson 5.

Where CLAUDE.md files live

There are several places, each for a different reach. The two you need now:

  • Project: CLAUDE.md in the main folder of the project (or .claude/CLAUDE.md). It is meant to be shared: you commit it with the project, so everyone who works on it gets the same instructions.
  • User: CLAUDE.md inside the .claude folder in your home folder. Your personal preferences for every project on your computer.

There is also CLAUDE.local.md for personal notes about one project. The docs say to keep that file out of git.

What belongs in it, and what does not

The docs give one test for every line: could Claude find this by reading the files, and would it actually go and look? If both answers are yes, leave the line out. Claude reads your folder quickly and well.

What does belong:

  • How to check a change in this project: the exact command or steps.
  • Rules that are not in the files: decisions you made, the price format, what must never happen.
  • Places where the files mislead: an old pattern that new work must not copy.
  • Anything you had to correct twice.

Keep it short. The memory page recommends staying under 200 lines per file, because a long file costs space in every session and gets followed less well. For a one-page site, 20 lines is plenty. Write concrete rules ("prices in euros with a comma") rather than vague ones ("format prices nicely"), and do not let two rules contradict each other.

Three commands that help

  • /init writes a starting CLAUDE.md from what Claude finds in your project. If a CLAUDE.md already exists, it suggests improvements instead of overwriting it. The best practices page says the work after /init is mostly removing lines.
  • /memory lists your CLAUDE.md files and opens one in your editor. It also has the switch for auto memory.
  • /context all shows what is loaded in the current session. Your CLAUDE.md files appear under Memory files.

Auto memory in one paragraph

Besides CLAUDE.md, which you write, Claude Code keeps its own notes, called auto memory. While it works, Claude may save things that will help later, such as your preferences and the corrections you gave it. It decides itself what is worth saving, and skips what it can find in your files. Auto memory is on by default for sessions on your computer, stays on your machine and can be switched off in /memory. When you say "remember that ...", Claude saves it there. When you want a rule in CLAUDE.md, say "add this to CLAUDE.md".

The steps

  1. Generate a first version with /init and read it before you approve it.
  2. Cut it down to what Claude cannot see, and add your own rules.
  3. Read and edit it yourself in your editor through /memory.
  4. Start a fresh conversation with /clear and confirm the file is loaded.
  5. Test one rule with a question whose answer depends on it, then let Claude apply it to the page.

Follow the steps for Claude Code below.

Example: Tilda's CLAUDE.md

The first version from /init had 31 lines. It described the page sections, listed the files and explained the bread list. Claude can see all of that by itself, so Tilda asked for a rewrite with only her rules. What was left:

## Rules
- Plain HTML and CSS in index.html, no libraries, no build step.
- Prices in euros with a comma, for example 3,50 euros.
- Opening hours appear in one place only.

## Checking a change
- Open index.html in a browser and compare the page with the request.

## Commits
- Show me the list of files before every commit.

After /clear, she asked how cinnamon buns at 2,75 euros would look on the page. Claude showed a line with "2,75 euros". The rule worked. She let Claude add the line and fix the three old prices, which still had a full stop.

Common mistakes

  • Keeping everything /init wrote. A long file of things Claude can see for itself dilutes the rules that matter.
  • Writing rules in capitals to make them stronger. The docs say current models follow a plainly worded line. If a rule keeps being missed, the file is probably too long.
  • Putting secrets in CLAUDE.md. It is a shared file in your repository. No passwords, keys or private data.

Today's actions

Ticks are not saved without an account

Do it in Claude Code

Claude Code

  1. Start Claude Code in your practice folder in Manual mode.
    cd marlow-bakehouse
    claude --permission-mode manual
  2. Type /init and press Enter. Claude looks through the project and proposes a starting CLAUDE.md. Read what it wants to write in the prompt, then choose Yes.
  3. Ask Claude to cut the file down and add the rules only you know. Change the rules to your own if you like, then read the edit prompt before you choose Yes.
    Rewrite CLAUDE.md so it is at most 20 lines. Remove anything you can work out by reading the files. Keep or add only these: - Plain HTML and CSS in index.html, no libraries and no build step. - Prices in euros with a comma, for example 3,50 euros. - Opening hours appear in one place only. - How to check a change: open index.html in a browser and compare the page with the request. - Never commit a file without showing me the list of files first.
  4. Type /memory and select the project CLAUDE.md to open it in your editor. Read it once yourself and fix anything you disagree with. Save and close the editor.
  5. Type /clear to start a new conversation with an empty context. Then type /context all and look under Memory files: your CLAUDE.md should be listed.
  6. Test a rule with a question. The answer should follow your CLAUDE.md, for example a price with a comma.
    We start baking cinnamon buns at 2,75 euros. How would you add them to the bread list? Show me the line, do not change anything yet.
  7. If the answer follows your rule, ask Claude to add the line and to fix any old prices that break the rule. Read the edit prompt before you choose Yes. Then type /exit.
    Add the cinnamon buns to the bread list, and change any price on the page that does not use a comma yet.

Note: /init does not overwrite a CLAUDE.md that already exists: it suggests improvements instead. If you ask Claude to remember something ("remember that ..."), it goes into auto memory, not CLAUDE.md. To put it in CLAUDE.md, say "add this to CLAUDE.md".

Paid planNeeds a paid Claude plan (Pro, Max, Ultra, Team or Enterprise) or a Claude Console account. The free Claude plan does not include Claude Code.

Checked on 4 December 2026 · Source: Claude Code docs: How Claude remembers your project (opens in a new tab)

Create a free account to save your progress. Sign in or sign up