← All posts

CLAUDE.md in Practice: What It Controls and What It Costs

In short

  • CLAUDE.md is the file Claude Code reads at the start of every session in a project. It is context, not configuration: Anthropic's docs say it is not enforced, and that rules which must always hold belong in hooks or permission settings.
  • Early research is mixed. On real coding tasks, context files did not reliably raise success and added over 20 per cent to cost; another study found shorter runs with similar results. Files written by people beat files generated by a model.
  • My two largest files, for Jile and FinTFM, reached 760 and 720 lines: 3.8 and 3.6 times Anthropic's target of 200. Most of their sections cite the incident that prompted them. The largest share of lines goes to releases in Jile and to rules about evidence in FinTFM.
  • Splitting FinTFM's file by the current guidance would keep 220 of its 712 section lines in every session and move the rest to path-scoped rules, skills, hooks, linter settings and docs.
  • The recipe: a short root file with commands and the facts the code hides; rules for one language or folder; skills for procedures; hooks and permissions for anything that must always happen.

A coding agent starts each session knowing nothing about your project. It does not know that the tests need a flag, that prices are stored as integers, or that it broke last week's release by staging the wrong files. CLAUDE.md is where Claude Code looks for that knowledge. It is a plain Markdown file, and it fails in two ways: too thin, and you repeat yourself every session; too long, and the rules that matter drown among the ones added once and forgotten.

This post covers how Claude Code loads the file, what published studies say about whether it helps, and what eleven of my own projects show, two of them far past the recommended size. It ends with recipes: templates, a path-scoped rule, a skill, a hook and a small CI check, each checked against the current documentation and tested where it can run.

What CLAUDE.md is, and what it is not

Anthropic calls it "a special configuration file that lives in your repository and provides Claude with project-specific context", and adds: "Your CLAUDE.md file becomes part of Claude's system prompt." Every session in the project starts with it loaded.

"Configuration" is the misleading word. The memory documentation is explicit: "Claude treats CLAUDE.md files and auto memory as context. They aren't enforced configuration. To block an action regardless of what Claude decides, use a PreToolUse hook instead." The best-practices page gives the consequence: "A line like Always typecheck before you finish in this file works most of the time, not every time." A line in CLAUDE.md is advice the model weighs against everything else in its context. That suits judgement calls and is weak for hard limits.

Two neighbours do similar jobs. AGENTS.md is an open format read by several coding agents; Claude Code reads it only as a fallback: "By default, Claude reads AGENTS.md only when you have no CLAUDE.md in your working directory or above it." And auto memory holds notes Claude writes for itself, covered near the end.

How Claude Code loads it

There are several CLAUDE.md files at different scopes, and they add up rather than replace each other: "All discovered files are concatenated into context rather than overriding each other." Files above the working directory load at launch. "Files in subdirectories load on demand", once Claude reads or edits a file there.

Two columns. At session start: the managed policy file, the user's files in ~/.claude, every CLAUDE.md from the root down to the working directory, CLAUDE.local.md and rules without paths, and the first 200 lines or 25 KB of the auto-memory index. On demand: subdirectory CLAUDE.md files, rules with paths front matter, skills, imported files with their parent, and subagents in their own context. A note says hooks and permission rules are run by the harness and are not context. What Claude Code puts in context, and when At session start, every session Managed policy CLAUDE.md set by an organisation; cannot be excluded ~/.claude/CLAUDE.md and ~/.claude/rules/ your preferences, every project CLAUDE.md files from / down to the working dir concatenated, closest read last CLAUDE.local.md, rules without paths: personal and always-on project rules Auto memory: MEMORY.md index first 200 lines or 25 KB only On demand, only when needed Subdirectory CLAUDE.md when Claude reads or edits a file there Rules with paths: front matter when a matching file is opened Skills when invoked or judged relevant Imported files (@path) load with the file that imports them Subagents their own context; main memory not loaded Hooks and permission rules are not context at all: the harness runs them, every time.
Figure 1. What loads at the start of every session, and what waits until it is needed.
FileForLoadedIn git
Managed policy file (a system path)Everyone on the machineEvery session; cannot be excludedNo, set by IT
~/.claude/CLAUDE.md, ~/.claude/rules/You, in every projectEvery sessionNo
CLAUDE.md in the project root or .claude/The teamEvery session, with each CLAUDE.md above the working directoryYes
CLAUDE.local.mdYou, in this projectEvery sessionNo, ignored
.claude/rules/*.mdThe teamEvery session; with paths:, only for matching filesYes
A subdirectory's CLAUDE.mdOne part of the treeWhen Claude reads or edits a file thereYes
Auto memory MEMORY.mdYou, in this projectEvery session: the first 200 lines or 25 KBNo, stays on the machine

Six details from the documentation shape how to write the file:

  • Size. "target under 200 lines per CLAUDE.md file. Longer files consume more context and reduce adherence." Claude Code warns at startup when a file passes that. The only hard limit is far away: it "skips a file over 4 MiB".
  • Imports. A line such as @docs/testing.md pulls in another file, up to "a maximum depth of four hops". Imports organise text but save nothing: imported files "load together with the CLAUDE.md that imports them."
  • Path-scoped rules. Files in .claude/rules/ with a paths: list "only load into context when Claude works with matching files, reducing noise and saving context space."
  • Contradictions. "if two instructions contradict each other, Claude may pick one arbitrarily." With several files concatenated, this happens by accident.
  • Checking. /memory lists the instruction files and opens them for editing. /context all shows what is actually loaded, under "Memory files"; a file missing there does not exist for Claude.
  • Starting. /init drafts a file from the codebase. Anthropic's advice: "Think of /init as a starting point, not a finished product."

What it costs

Everything that loads at session start is paid for in every session, relevant or not. The best-practices page says so directly: "every line in it takes a little of Claude's attention on every task, whether it's relevant or not." A rough measure is size. At about four characters per token, my 760-line file is roughly 12,700 tokens; on a 200,000-token context window, that is about 6 per cent used before the first question. A 22-line file is a few hundred tokens.

Tokens are the smaller cost. The larger one is attention. Anthropic's engineering post on context describes the goal as "the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome", and notes that "CLAUDE.md files are naively dropped into context up front" while other information is fetched when needed. A rule that applies to one folder, loaded for every task, dilutes the rules that apply everywhere.

What the evidence says

Research on context files is new. Most of it is preprints from 2025 and 2026 with small samples, so treat the table as early results.

StudySampleFinding
Chatlatanagulchai et al., 2025 (preprint)253 Claude.md files, 242 repositoriesBuild and run commands in 77.1 per cent, implementation details in 71.9, architecture in 64.8; security in 8.7
Chatlatanagulchai et al., 2025 (preprint)2,303 context files, 1,925 repositoriesFiles "evolve like configuration code through frequent, small additions"
Gloaguen et al., 2026 (preprint)SWE-bench tasks and a new 138-instance benchmarkNo reliable gain in success; cost up by over 20 per cent; hand-written files beat generated ones
Lulla et al., 2026 (preprint)10 repositories, 124 pull requestsWith AGENTS.md: median runtime down 28.64 per cent, output tokens down 16.58 per cent, similar completion
Jaroslawicz et al., 2025 (preprint)500 keyword instructions, 20 modelsThe best models stayed near-perfect to about 150 instructions, then declined; 68 per cent at 500
Liu et al., 2023Question answering over long contextsAccuracy is highest when the relevant text is at the start or end, lowest in the middle

What people write. In 253 public files, the most common content was how to build and run the project, then implementation notes and architecture; security and performance were rare. A later study of 2,303 files describes them as artifacts "that evolve like configuration code through frequent, small additions." My files grew the same way.

Whether they help. Gloaguen and colleagues ran coding agents on real tasks with and without context files: "providing context files does not generally improve task success rates, while increasing inference cost by over 20% on average." Files written by developers did better than generated ones, and the authors found the files useful "for specifying non-standard coding practices", but not as overviews of the repository. Lulla and colleagues, measuring efficiency, found shorter runs and fewer output tokens with an AGENTS.md. Read together: a file that states what the agent cannot discover saves it searching; a file that repeats what it could read anyway only costs.

Why length hurts. Liu and colleagues found that models use information best at the start or end of a long context and worst in the middle. Jaroslawicz and colleagues gave models up to 500 simple instructions at once; the strongest stayed near-perfect to about 150 and then declined. That benchmark asks for keywords in a report, not for following coding rules, so it is an analogy, not a limit. The widely quoted claim that models follow "~ 150-200 instructions" comes from a practitioner blog's reading of that paper, not from the paper.

What eleven of my files show

Each of my projects that uses Claude Code has a CLAUDE.md. Nine are small. Two are not:

ProjectLinesWordsTokens (rough)Commits
Jile (Y-DNA tree)7607,689about 12,70049
FinTFM (research model)7206,917about 10,90041
Santa 2026 (Kaggle)70806about 1,40014
Smart buildings (Kaggle)61548about 9003
Quantum circuits (Kaggle)62563about 1,0002
CASMI 2026 (Kaggle)58592about 1,0008
PLE agent harness (Kaggle)76808about 1,3002
CircassianDNA site35706about 1,3007
Citewatch (VS Code)14156about 2001
Jobwatch (VS Code)15167about 3001
Tokenwatch (VS Code)10117about 2002

The token column divides characters by four, so it is rough; the exact count depends on the tokeniser.

A line chart from August to December 2026. Jile's file starts at 213 lines in early August and grows in steps to 760 by late November; FinTFM's starts at 95 lines in September and reaches 720 by mid-November. A horizontal line marks Anthropic's 200-line target. Nine smaller projects sit between 10 and 76 lines. Lines in CLAUDE.md after each commit that changed it 0 200 400 600 800 Anthropic's target: under 200 lines Aug Sep Oct Nov Dec jile (760) fintfm (720) nine smaller projects, 10 to 76 lines
Figure 2. Both large files passed the 200-line target within weeks and kept growing.

Neither was planned at that size. Jile's file started at 213 lines and FinTFM's at 95. Both grew by small additions after something went wrong. The commit messages read like an incident log: "Document today's session as a postmortem", "Fix the openspec test I pushed broken, and the habit that hid it", and one recording that a fetch job died after its script was edited while it ran. A pattern search finds a dated incident, a version or a failure in 13 of Jile's 19 sections and 24 of FinTFM's 29.

Horizontal bars comparing the share of lines per category in Jile and FinTFM. Evidence and claims takes 18 per cent of Jile's file and 30 per cent of FinTFM's. Releases take 29 per cent of Jile's and 10 of FinTFM's. Agent workflow, machine and environment, safety and licensing, tests, design choices and conventions take the rest. Share of lines by kind of rule (my classification of each section) Evidence and claims 18% 30% Releases 29% 10% Agent workflow 17% 10% Machine and environment 13% 15% Safety, identity, licensing 11% 16% Tests and gates 8% 4% Design choices 6% 8% Conventions 0% 6% jile, 760 lines fintfm, 720 lines
Figure 3. My two large files spend the most lines on releases and on rules about evidence.

The content is less typical than the growth. Both files have build and test commands, as three files in four do in the large study. But the largest category in FinTFM, and the second largest in Jile, is rules about evidence: label every number by how it was produced, re-read a figure before quoting it, score on the benchmark the project claims before the convenient one. In research code the costly failures were rarely crashes. They were plausible numbers that were wrong, and the files grew where that happened.

Anatomy of a rule that works

The sections that worked best share a shape. One from FinTFM, whose repository is public, shortened:

## A backgrounded shell command does not inherit your `cd`

**Symptom: a background job you just launched fails instantly with `ModuleNotFoundError`
or `No such file or directory`, or a running job's PID reads as dead when it is not.**
On 2026-09-26 this hit three times in one session ...

The tool's own `cd` inside a foreground command does not persist to a background one
issued later in the same turn ... **Put `cd /absolute/path &&` inside the backgrounded
command itself**, every time, rather than relying on an earlier `cd` in the transcript.

A second example comes from Jile, whose code is private, so I describe it rather than quote it. The rule says never to edit a shell script while it runs. It explains why (Bash reads a script by byte offset, so an in-place edit moves the point where the running shell resumes), records the date a fetch job died from it, gives a one-line pgrep check, and names the safe alternative: write a new file and mv it into place, which leaves the running copy untouched.

Both have five parts: the symptom as the agent will see it, the incident with a date, the cause in a sentence or two, the rule in bold, and a check or safe alternative. The symptom lets the rule fire at the right moment. The cause lets the agent apply it to cases the author did not foresee. The date lets a later reader judge whether it still applies. Anthropic's test for what earns a place is the same idea in one line: "Anything you've had to correct twice already".

Rewriting weak rules

Most weak lines fail the same way: they state a value the model already holds, or an aim with nothing to check. A stronger line names a boundary, a command, a hidden fact or a pointer.

WeakStrongerWhat changed
Write clean, maintainable code.Domain code in api/domain/ imports no web framework or database driver; import-linter enforces it.A boundary, and the tool that checks it
Always run the tests.Run make check before saying a change is done; it runs what CI runs.An exact command, and a definition of done
Be careful with money.Prices are integers in minor units; never use floats for money.The fact the code hides
IMPORTANT: never touch production.A permission rule that denies the deploy command, or a hook that blocks it.A must-rule moved out of prose
Follow our release process.Releases: use the /release skill.A pointer instead of a procedure
Don't break background jobs.The symptom, the cause and the fix, as in the FinTFM example above.Something the agent can recognise and act on

What to put in, and what to leave out

For each line, ask whether Claude could find it by reading the code. If it could, the line costs attention and buys nothing.

Put in CLAUDE.mdLeave out
Exact commands to build, test, lint and type-checkWhat Claude can read from the code itself
Facts the code hides: units, frozen folders, generated filesStandard conventions of the language or framework
Decisions made outside the repository, with a pointer to the ADRLong procedures (make them skills)
Anything you have had to correct twiceRules a linter, type checker or hook can enforce
How to report results: measured, simulated or estimatedSecrets, and anything you would not publish
Where the other instructions live (rules, skills)Personal preferences (they belong in your user file)

A root file that follows this can be short. This one covers a service in three languages in 22 lines:

# Project: ledger service (Python API, Rust pricing core, TypeScript UI)

## Commands
- Python: `uv run pytest -q` · `uv run ruff check .` · `uv run mypy src`
- Rust: `cargo test --workspace` · `cargo clippy --all-targets -- -D warnings`
- TypeScript: `pnpm test` · `pnpm lint` · `pnpm typecheck` (run from `web/`)
- Everything CI runs: `make check`. Run it before saying a change is done.

## Layout and boundaries
- `core/` (Rust) prices trades; `api/` (Python) calls it through `api/pricing.py` only.
- Domain code in `api/domain/` imports no web framework or database driver; import-linter enforces it.
- Architecture decisions live in `docs/adr/`; read the relevant one before changing a boundary.

## Things the code will not tell you
- Prices are integers in minor units everywhere; never use floats for money.
- `legacy/` is frozen: read it, do not edit it.
- Test data in `tests/fixtures/` is generated by `scripts/make_fixtures.py`; regenerate, never hand-edit.

## Working agreements
- State how every number you report was produced: measured, simulated or estimated.
- Ask before deleting data, rewriting history, or anything that leaves this machine.
- Language rules are in `.claude/rules/`; procedures (release, migration) are skills.

Every line is a command, a boundary or a fact the code hides. There is no "write good code", no tour of the folders and no procedure longer than one line.

CLAUDE.md is one tool among eight

Most of the length in my large files came from asking one file to do several jobs. Claude Code and the repository's own tooling have a separate mechanism for each. They differ in two ways that matter: when they act, and whether they are enforced.

MechanismWhen it actsEnforcedUse it for
CLAUDE.mdEvery sessionNoCommands, boundaries, facts the code hides
Path-scoped rule, in .claude/rules/When matching files are touchedNoOne language's or one folder's conventions
Skill, in .claude/skills/When invoked or relevantNoProcedures: release, migration, review
Subagent, in .claude/agents/When delegated, in its own contextNoA separate investigation or review
Hook, in settings.jsonAt set points, such as before a tool callYesBlocking risky commands, formatting after edits
Permission rule, in settings.jsonBefore every tool callYesFiles and commands that are off limits
Auto memory, in ~/.claude/Index loaded every sessionNoCorrections and preferences Claude saves
Linter, tests, CIOn every runYesStyle, types and behaviour a tool can check

The "Enforced" column is the one to read. Anthropic: "If something has to happen every time, make it a hook, a deny rule, or a managed setting. CLAUDE.md is for guidelines, and Claude is allowed to decide a guideline doesn't apply." Hooks give "deterministic control: certain actions always happen rather than relying on the LLM to choose to run them." And when a rule keeps being ignored, "adding IMPORTANT probably won't fix it. Either the file has grown long enough that the line gets lost, or the line is a rule that can't have exceptions, in which case it belongs in a hook."

A decision flow of six questions, each with a yes branch. Must it happen every time: hook, permission rule or managed setting. Is it a check a tool can do: linter, type checker, test or CI gate. Does Claude need it in every session: CLAUDE.md in one or two lines. Only when touching certain files: a path-scoped rule or subdirectory CLAUDE.md. Is it a multi-step procedure: a skill. Is it your own preference in every project: the user file or auto memory. Otherwise leave it out. Where an instruction belongs Must it happen every time, without exception? Hook, permission rule or managed setting yes no Is it a check a tool can do? Linter, type checker, test or CI gate yes no Does Claude need it in every session? CLAUDE.md, in one or two lines yes no Only when touching certain files? Path-scoped rule or subdirectory CLAUDE.md yes no Is it a multi-step procedure? Skill, loaded when used yes no Is it your preference, in every project? ~/.claude/CLAUDE.md or auto memory yes Otherwise: leave it out. Claude can read the code.
Figure 4. Ask the questions in order; the first yes decides where the instruction goes.

Order matters. A rule that must always hold should not be a sentence in a prompt if a tool can enforce it, and the tool need not belong to Claude Code. A rule about commit authorship can be a sentence in several CLAUDE.md files, or one git commit-msg hook that refuses a commit with the wrong author address. The sentence competes with everything else in context; the hook does not.

A worked split

To see what the guidance means for a real file, I assigned each of FinTFM's 29 sections to the mechanism the flow suggests. It is a plan on paper, not a change to the repository, and the assignments are my judgement.

Six horizontal bars for the destinations of 712 lines: 220 stay in CLAUDE.md, 258 become skills, 89 path-scoped rules, 73 are replaced by hooks and permissions, 44 move to docs and 28 to linter configuration. Where fintfm's 712 lines of sections would go (a proposed split, not applied) stays in CLAUDE.md 220 lines (31%) skills 258 lines (36%) path-scoped rules 89 lines (12%) hooks and permissions 73 lines (10%) docs, with a pointer 44 lines (6%) linter config 28 lines (4%) Loaded every session: 712 lines today, 220 after the split, before any rewording.
Figure 5. Under current guidance, less than a third of the file needs to load every session.

The 220 lines that stay are the core rules: how to report a number, which Python to use, that the machine is shared, never to truncate a validator's output. Tightened, they fit under 200. Procedures (releases, environment setup, evaluating a model, closing a spec task) become skills. Two rules become enforcement, because they guard against expensive mistakes: a training launch without checkpoints, and reading the credentials file.

The permission rule and the hook take a few lines of settings:

{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./.env.*)"]
  },
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/require-checkpoint.sh" }
        ]
      }
    ]
  }
}

The hook receives the tool call as JSON on standard input; exit code 2 blocks the call and returns the message to Claude:

#!/bin/bash
# PreToolUse hook: refuse a training launch that would lose all progress if the job is cut off.
# Claude Code passes the tool call as JSON on stdin; exit 2 blocks it and shows stderr to Claude.
cmd=$(jq -r '.tool_input.command // empty')
if [[ "$cmd" == *"hf jobs"* && "$cmd" == *"train"* && "$cmd" != *"--checkpoint-every"* ]]; then
  echo "Blocked: every HF Jobs training launch needs --checkpoint-every (see CLAUDE.md, Machine)." >&2
  exit 2
fi
exit 0

Tested on three commands: a launch without the flag was blocked with exit code 2; the same launch with --checkpoint-every 500 passed; an unrelated pytest -q passed.

A path-scoped rule carries conventions that matter for one part of the tree. Its front matter decides when it loads:

---
paths:
  - "src/**/*.py"
---
# Python in src/

- A correction (a base rate, a unit, a clip) lives in one function that every caller uses.
  A fix inside one method will be bypassed by the next caller.
- Experiment settings come from the validated config in `config/`, not module constants.
- Run `uv run ruff check src` and `uv run pytest -q tests/unit` before saying a change works.

A procedure becomes a skill, loaded when the task calls for it or when you type /release:

---
name: release
description: Cut a fintfm release. Use when the user asks to release, tag or publish a version.
---
# Release

1. Confirm `main` is clean and CI is green for its last commit.
2. Bump the version in `pyproject.toml` only, and move the CHANGELOG `[Unreleased]` section under it.
3. Run the full gates: `uv run ruff check . && uv run pytest -q`.
4. Create the release with the CHANGELOG section as the notes, unwrapped, as a draft.
5. Publish the draft, then check that the Zenodo record appeared.

Stop and ask before step 5 if any gate failed.

None of this is in context while Claude fixes a typo in the README. That is the saving.

Treat it like code

The second study's phrase, files that "evolve like configuration code", suggests the remedy: manage them like code.

  • Review changes. Put CLAUDE.md, rules and skills in pull requests like any other change, with an owner who reads them.
  • Date each rule. A date makes pruning quick: when the cause is gone, the rule goes.
  • Search before adding. Look for an existing rule on the same topic, so you change one line instead of adding a contradiction.
  • Test what can be tested. Commands are the most common content and the first to rot when a tool is renamed. This script checks that every command under ## Commands still exists:
"""Check that every command listed under a "## Commands" heading in CLAUDE.md still exists.

Reads the backticked commands in that section and checks the first word of each is on PATH.
Run it in CI so the file fails loudly when a tool is renamed or removed.
Usage: python check_commands.py [path/to/CLAUDE.md]
"""
import re
import shutil
import sys
from pathlib import Path


def commands(text: str) -> list[str]:
    """Backticked commands in the "## Commands" section, which ends at the next "## " heading."""
    section = re.search(r"^## Commands\n(.*?)(?=^## |\Z)", text, re.M | re.S)
    spans = re.findall(r"`([^`]+)`", section.group(1)) if section else []
    return [s for s in spans if not s.endswith("/")]  # a folder such as `web/` is not a command


def missing(cmds: list[str]) -> list[str]:
    return [c for c in cmds if shutil.which(c.split()[0]) is None]


if __name__ == "__main__":
    found = commands(Path(sys.argv[1] if len(sys.argv) > 1 else "CLAUDE.md").read_text())
    gone = missing(found)
    for c in gone:
        print(f"not on PATH: {c}")
    print(f"{len(found)} commands, {len(gone)} missing")
    sys.exit(1 if gone or not found else 0)

On the 22-line template it found nine commands, all present, and exited 0. With a stripped-down PATH it reported eight missing and exited 1, and on a file with no Commands section it also failed, so a CI job notices when the section disappears.

Recipes

Start from /init, then cut. Let Claude draft the file, then delete what it could have read from the code. Anthropic notes that the draft "captures obvious patterns but may miss nuances" of your project. Keep commands, boundaries and hidden facts, and add what the draft missed.

Turn repeated corrections into rules. The second time you correct the same mistake, ask Claude to propose a rule with the five parts above, and use the flow to decide where it goes. A one-off does not need a permanent line.

Split by language. In a repository with Python, Rust and TypeScript, put each language's conventions in .claude/rules/python.md, rust.md and typescript.md with matching paths:. The root file keeps only what is shared.

Keep preferences personal. Spelling, commit address, how you like questions asked: these go in ~/.claude/CLAUDE.md, not in the team's file. A few lines are enough:

# My preferences (every project)

- British spelling in prose; no em dashes.
- Commits use my personal address and carry no AI attribution lines.
- Before a long or expensive command, say what it will cost and how long it will take.
- When unsure which of two designs I want, ask once, with your recommendation first.

One source for several agents. If the team also uses other coding agents, keep shared instructions in AGENTS.md and make CLAUDE.md a short file that imports it with @AGENTS.md and adds what is specific to Claude Code.

In a monorepo, push rules down. A team repository I worked in kept a short root file and more than twenty small CLAUDE.md files in its packages and services, most a few dozen lines, plus skills for recurring procedures. Subdirectory files load only when Claude works there, so a frontend change did not pay for the worker's rules. It was the opposite of my two research projects, and every file stayed small.

Check what loaded. After a change, run /context all and look under Memory files.

The personal layer: auto memory

Some lessons belong to no single project: a pgrep -f loop that matches its own wrapper and never ends, a backgrounded job whose "exit code 0" is the wrapper's, not the job's. Claude Code keeps these in auto memory: "notes Claude writes itself based on your corrections and preferences", one file per memory with a MEMORY.md index, per project under ~/.claude/projects/.

Two limits make the index behave like a small CLAUDE.md. Only "the first 200 lines or 25KB of MEMORY.md, whichever comes first, load at session start", and auto memory "is machine-local": it does not reach another machine or a teammate. An index that grows by one line per lesson reaches the limit sooner than expected, and anything past it is silently not loaded. Prune it the same way: delete an entry when it stops being true.

Mistakes to avoid

MistakeWhat happensFix
One file for everythingEvery rule costs context in every session; adherence dropsRoot under 200 lines; move the rest to rules, skills, hooks
Emphasis instead of enforcementIMPORTANT in capitals still works only most of the timeMake must-rules hooks or permissions
Contradictions between filesClaude "may pick one arbitrarily"One owner per topic; search for duplicates when adding a rule
Stale rulesThe file describes a codebase that no longer existsDate each rule's incident; prune when the cause is gone
Generated and never editedOverviews Claude could have read anyway, at a costTreat /init as a draft; keep only what the code hides
Secrets or private contextThe file is part of the prompt and of the repositoryWrite it as if it were public

One more: Anthropic advises, "Since CLAUDE.md becomes part of Claude's system prompt, treat it as documentation that could be shared publicly." FinTFM's history has a commit doing exactly that, some weeks after the repository went public: it removed references to private sibling projects and local machine details from CLAUDE.md.

A checklist

  • Is the root file under 200 lines, and does /context all list everything you expect?
  • Does every line say something Claude could not learn from the code?
  • Are the build, test, lint and type-check commands exact, and checked in CI?
  • Is every rule that must always hold enforced by a hook, a permission rule or a tool?
  • Do language- or folder-specific conventions live in path-scoped rules?
  • Are procedures longer than a few lines skills?
  • Does each rule name the symptom, the cause and a check, and carry a date?
  • Did you search for a rule that contradicts the one you are adding?
  • Would you be comfortable if the file were public?

Limits of this post

The research is young: mostly preprints, small samples, different measures, and none of it tests the advice here directly. My files come from eleven projects by one person. The categories in Figure 3 and the split in Figure 5 are my classification, the incident count comes from a pattern search, and token counts are estimates. The documentation quoted is a living document, read on 2 December 2026; check the current version before relying on a detail such as a size limit.

Sources and further reading

Anthropic documentation

Research

Formats and practice

  • AGENTS.md, the open format, and Agent Skills, the open standard that Claude Code skills follow.
  • HumanLayer, Writing a good CLAUDE.md (November 2025): a practitioner's account, and the source of the "150 to 200 instructions" figure.
  • FinTFM's CLAUDE.md, one of the two large files discussed here, in a public repository.