Answers · Claude Code

What goes in a CLAUDE.md file?

In short

Put in what Claude cannot work out alone: exact build and test commands, house conventions, where things live, and what it must never do. Keep it under 200 lines, as Anthropic suggests; ours is under 150. Move rare procedures into skills, personal notes into CLAUDE.local.md, and enforce hard rules with hooks.

What should a CLAUDE.md include?

Claude Code loads your CLAUDE.md into every session. Anthropic's advice is to write instructions concrete enough to check: "Run npm test before committing", not "test your changes". In practice that means:

  • The exact commands to install, build, run one test, run all tests and lint.
  • Conventions a reviewer would flag: naming, error handling, the libraries you use and the ones you have dropped.
  • Where things live: "API handlers are in src/api/handlers", where migrations go, which folder is generated.
  • What never to do: push to main, edit generated files, read credentials.
  • What "done" means and how to report it.

What does that look like in ours?

Our own file is short and mostly rules a model would not guess. Paraphrased from the sanitised copy:

  • Two agents share one memory. Before deciding or planning, check what both already know. Each writes only its own memory.
  • A task is done when it works (checked, not assumed), is shipped, cleaned up and written down. When you stop, say which box is still open.
  • A rule saved to memory carries a source line: the owner's words and date, or a note that it is Claude's opinion.
  • Never read, print or copy a credential. If a hook blocks you, report "blocked by policy" and stop.

What should you leave out?

  • Anything Claude finds by reading the code. It costs context and lowers adherence.
  • Long procedures used once a month. Make them skills, which load only when a task needs them.
  • Personal preferences. They belong in your user file or CLAUDE.local.md.
  • Secrets, hostnames and account details. The file is committed.
  • Rules that must hold every time. Anthropic says Claude treats CLAUDE.md as context, not enforced configuration; use a PreToolUse hook to block an action. See hooks and guardrails.

How do imports, nested files and memory work?

A CLAUDE.md can import other files with @path, up to four hops deep. Imports keep a file tidy but do not save context, because imported files load with it. A CLAUDE.md in a subdirectory loads when Claude works on files there, and files in .claude/rules can be scoped to paths so they load only for matching files.

Auto memory is separate: notes Claude writes for itself in a per-repository folder, with an index, MEMORY.md, of which the first 200 lines or 25KB load each session. It stays on one machine. We give it a strict shape: one line per note in the index, one fact per note, each dated with a why and a how to apply.

How do you test that it works?

  • Run /context and check your file is listed under memory files.
  • Ask "how do I run the tests here?" in a fresh session. The answer should be your command, word for word.
  • Ask it to do something the file forbids and watch it refuse. If it does not, the rule belongs in a hook.
  • Read it every few months and delete rules that contradict each other; Claude may pick either one.

We write and test this file as part of our Claude Code setup.

Questions owners ask

Should I start with /init?

Yes. It reads the codebase and drafts build commands and conventions, or suggests improvements if a file exists. Then add what it could not discover and delete what is obvious.

Where does the file go?

At the repository root as CLAUDE.md or .claude/CLAUDE.md, committed so the team shares it. Your own preferences go in ~/.claude/CLAUDE.md or a gitignored CLAUDE.local.md.

Can one file serve Claude Code and other agents?

Yes. Claude Code can read an AGENTS.md, and a CLAUDE.md can import one with @AGENTS.md so both tools follow the same rules.

Want this set up in your repo?

We install the setup we run ourselves: rules, memory, guardrails and a review step, as one pull request, at a fixed price.