All posts
AI-native method

What goes in CLAUDE.md? A real before-and-after

24 Nov 20265 min read21 views
What goes in CLAUDE.md? A real before-and-after

This note is about the CLAUDE.md file, but I will start with an experiment. I created an empty folder, added a Go module and told Claude Code: "build an appointment booking API". Just that one sentence. It worked for about three minutes, the tests passed and the code was clean. But when I read it, I found it had made seven important decisions, none of them mine.

The agent guesses whatever you did not write down

These are the decisions the agent made on its own:

  1. It kept the data in memory; restart the server and every booking is gone.
  2. It picked the working hours itself: Saturday to Wednesday, 9 to 13 and 16 to 20.
  3. It laid bookings out on 15-minute slots.
  4. It allowed cancelling only up to two hours before.
  5. It priced services in toman.
  6. It invented an admin token, read from the environment, for the business owner.
  7. It put the whole program in one package and one folder.

None of these is a technical mistake, and some are even good guesses. But they are all business decisions. How was the agent supposed to know? I had not written them anywhere, so it guessed. The problem is not the agent; it is the repository we gave it.

What is CLAUDE.md?

CLAUDE.md is a plain Markdown file that Claude Code reads at the start of every session. Whatever you write in it is part of the agent's context in every session. It can live in a few places:

  • ./CLAUDE.md at the project root: the team's shared rules. This one is committed.
  • ./CLAUDE.local.md: your personal preferences for this project. Put it in .gitignore.
  • ~/.claude/CLAUDE.md: personal preferences for every project.

If your project already has an AGENTS.md, Claude Code can read that too. In my own projects I keep the main rules in AGENTS.md, and CLAUDE.md just imports it with @AGENTS.md, so other tools read the same single source.

The same sentence, with a twenty-line file

I created a fresh folder and put this file in it:

# nobati

Appointment booking API for one small business. Go 1.24, net/http only, no web framework.

## Data
PostgreSQL through pgx/v5 (pgxpool) and hand-written SQL; no ORM.
Schema lives in migrations/NNNN_name.sql. Times are stored in UTC and shown in Asia/Tehran.

## Layout
cmd/nobati        the binary and its wiring
internal/<name>   one package per capability (booking, schedule, ...); a capability never imports another

## Business rules
Working hours, slot length and the cancel window are settings the owner edits, never constants.
Do not invent a business rule. If the task needs one, list it under "Open questions" in your answer.

## Before you finish
gofmt -l . && go vet ./... && go test ./...
Tests that need a database read DATABASE_URL and skip when it is empty.

Then I sent exactly the same sentence. This time:

  • It stored the data in PostgreSQL.
  • It built two separate packages, one for bookings and one for working hours, that never call each other.
  • It stopped two people booking the same slot with an EXCLUDE constraint in the database itself, not a lock in code. It also wrote a test that fires 20 requests at once and checks that only one succeeds.
  • It did not hard-code working hours. Until the owner saves the settings, the API refuses to hand out slots and says it is not set up yet.
  • And the best part: at the end of its answer, instead of guessing, it asked eight open questions. How much notice before a booking? How many days ahead can people book? How many bookings can one phone number hold? Should a text message go out on booking?
Claude Code output without CLAUDE.md and with CLAUDE.md, side by side
The same prompt, once without CLAUDE.md and once with it

As a result, the difference between the two runs was not the model, not the tool, and not the wording of the request. It was a twenty-line file.

What to write in CLAUDE.md

My rule is simple: only what the code does not show. The agent reads the code itself; you do not need to tell it what the internal folder is. But it cannot learn these from anywhere in the code:

  • Technical decisions you already made: "no ORM", "no web framework", "times are stored in UTC".
  • Architecture boundaries: "no module imports another". The agent looks for the shortest path, and unless you write the boundary down, it will cut straight through it.
  • Business rules, or that guessing them is forbidden: the most important line in the whole file is "do not invent a business rule; if you need one, list it as an open question".
  • The checks to run before finishing: lint, vet and tests. The agent runs them and does not consider the task done until they pass.

What to leave out

  • A tour of the folder structure: the code already says that, and you only spend tokens. When the code changes, your description goes stale and misleads.
  • Multi-step procedures: "to release, follow these ten steps". Those belong in a skill, which loads only when needed.
  • Rules for one part of the code: "always validate input in the api folder". Put those in path-scoped rules, which load only when the agent works on those files.
  • Vague instructions: "write clean code" cannot be checked. "Run go test ./... before committing" can.

Claude Code's own documentation suggests keeping the file under 200 lines; a longer file uses more context and is followed less reliably. Mine are usually much shorter.

When to add to CLAUDE.md

It does not need to be complete on day one. Add a line whenever one of these happens:

  • The agent repeats a mistake for the second time.
  • You type a correction you already typed in an earlier session.
  • A code review catches something the agent should have known.

The /init command writes a first version from your code. It is a good starting point, but afterwards delete everything the code already shows.

One important caveat

CLAUDE.md is guidance, not a lock. The agent usually follows it, but there is no guarantee. Anything that must never happen (an import between two modules, a dangerous migration) should be blocked by a static guard in CI or a hook. CLAUDE.md says what is right; the guard makes sure the wrong thing does not get through.

Comments

Sign in to leave a comment.

Sign in

Loading…

Related posts