claude --version), Git 2.x, a repository with a clean working tree, a text editor. Optional: an MCP client if you later add a memory server.CLAUDE.md at the repository root with a repo map built from real git ls-files output, the exact build/test commands, and 6–10 hard rules.git diff --stat block you can compare against the task.git checkout -b chore/claude-md
git ls-files | cut -d/ -f1 | sort | uniq -c | sort -rn | head -10
printf '# CLAUDE.md\n\n## Repo map\n\n## Commands\n\n## Rules\n\n## Report format\n' > CLAUDE.md
git add CLAUDE.md && git commit -m "chore: add CLAUDE.md skeleton"Details and checks are in the steps below.
Send this to Claude Code inside the repository root before Step 1. It produces the file content; you review and commit it.
You are auditing the repository <repo-name>, branch <branch>, to produce CLAUDE.md.
Modify no file except CLAUDE.md. If a fact is missing from the repository, write
"check the docs" instead of guessing. Never invent flags, script names or ports.
1. Repo map: list top-level directories with tracked file counts taken from
`git ls-files`. Mark generated/vendored directories and say which must never be
edited by hand.
2. Commands: quote the install, build, lint and test commands verbatim from
<package.json / Makefile / pyproject.toml>. Copy the strings; do not paraphrase.
3. Rules: write 6-10 rules as hard constraints, each with a command that proves it.
The first three must be:
- edit only the files named in the task and their direct importers; stop and ask
before touching anything else;
- never reformat, rename, reorder imports or bump dependencies unless asked;
- never edit paths matched by .gitignore.
The last rule must be: before reporting completion, print `git diff --stat`.
4. Report format: a fixed block with Done, Changed files, Not changed but related,
Open questions.
Output the whole file as one markdown block.Replace <repo-name>, <branch> and the manifest file name with your values; delete the manifest you do not have.
claude --versionYou should see a version string. If the command is not found, install the CLI for your platform; if your build rejects the flag, check the documentation. If you work in the desktop build instead, the setup flow differs — see Claude Code Desktop: setup, limits and how it differs from the CLI.
git status --short prints nothing.Why rules must live in the repo: a year-long review published on caleb.software counted 244 Claude Code releases in one year, and more than three quarters of them changed the system prompt or tool descriptions. Anything you say once in chat is not durable; CLAUDE.md is the part you control.
Example: the same review notes that the Bash tool description alone runs to roughly 3000 tokens — the built-in instructions are already long, so your file has to be short and specific to win attention.
What to do: collect four lists — size and shape, build/test entry points, hottest files, generated paths. Run these four commands at the repo root.
# 1. Size and top-level shape
git ls-files | wc -l
git ls-files | cut -d/ -f1 | sort | uniq -c | sort -rn | head -10
# 2. Build and test entry points
git ls-files | grep -E '(^|/)(package\.json|Makefile|pyproject\.toml|go\.mod|Cargo\.toml)$'
# 3. Hottest files over the last 60 days
git log --since="60 days ago" --name-only --pretty=format: | grep -v '^$' | sort | uniq -c | sort -rn | head -15
# 4. Generated and vendored paths
git ls-files | grep -E '^(dist|build|vendor|generated)/' | cut -d/ -f1 | sort -uExample output for a repository with 312 tracked files:
312
84 src
51 tests
33 docs
19 scripts
package.json
distWhy: rules written from memory are wrong — they name directories that do not exist and scripts that were renamed. The audit gives the agent facts it can act on, and command 3 shows which files are risky to touch, because that is where edits collide.
How to check: you end up with one number (tracked files), one short directory list, at least one manifest path, and an explicit list of generated directories. If command 3 prints nothing, the repository is younger than 60 days — rerun with --since="1 year ago".
What to do: fill the skeleton with the four audit lists, then add the rules that stop scope creep. Use this template and replace every path with a path from your audit.
# CLAUDE.md
## Repo map
- `src/` — application code (84 tracked files). Entry point: `src/main.ts`.
- `tests/` — test suites (51 files). Single file: `npx vitest run tests/<name>.test.ts`.
- `dist/`, `build/` — generated. Never edit by hand; rebuild with `npm run build`.
## Commands
- Install: `npm ci`
- Dev server: `npm run dev` → http://localhost:3000
- Test: `npm test`
- Lint: `npm run lint`
## Rules
1. Edit only the files named in the task and their direct importers. Before touching any other file, stop and ask.
2. Never reformat, rename, reorder imports or bump dependencies unless the task says so.
3. Never edit a path matched by `.gitignore` (`dist/`, `build/`). Change the source and rebuild.
4. Run `npm test` after any change under `src/`.
5. Before saying "done", print `git diff --stat`.
## Report format

Done: <one line>
Changed files:
<git diff --stat output>
Not changed but related: <paths>
Open questions: <list or "none">If a script from the template does not exist in your package.json, delete that line — do not invent a replacement.
Why: the report format is the actual enforcement. The channel covered an r/AI_Agents case where a request to change one button color ended with CSS variables renamed in 40 files and the test suite reformatted, while the agent's report said only "done". Rule 5 makes that visible in one screen of output, and rules 1–3 forbid it up front.
If the repository already keeps an AGENTS.md, pick one source of truth. Anthropic announced support for AGENTS.md in Claude Code; the precedence between the two files is version-dependent, so check the documentation before keeping both. The safe pattern is to keep the rules in one file and make the other a one-line pointer.
How to check:
wc -l CLAUDE.md
grep -nE 'try to|be careful|if possible|when appropriate' CLAUDE.md
git diff --name-onlywc -l should print a number under 120. The grep must print nothing — any hedge word means the rule cannot be verified. git diff --name-only must list only CLAUDE.md.
Once the rules are stable and repetitive procedures appear, move them out of the file and into separate agents — see Claude Code for Teams: Setting Up Subagents and a Shared AI Superagent.

What to do: run one controlled task that a rule-following agent finishes with a single-file diff. Start a fresh session in the repo root and send:
Change the primary button color in src/components/Button.tsx from #1f6feb to #0b5cad. Edit no other file.Then check the result yourself:
git diff --name-only
git diff --statExample: a compliant run prints exactly one path from git diff --name-only (src/components/Button.tsx) and a git diff --stat line such as 1 file changed, 2 insertions(+), 2 deletions(-), plus the same stat block pasted into the agent's report.
Why: the check tests the rule, not the answer. A color value can be right while the diff is wrong, and the diff is what you merge. Diff discipline pays off more as repositories grow — if you want a version-control layer built for agent changes, compare options in Jujutsu or Git: What to Choose for AI Agent Workflows.
How to check: run the checklist.
git diff --name-only outputs exactly the file named in the taskgit diff --stat blockgit diff contains no reordering, renaming or whitespace-only hunksgit status --short shows no changes inside dist/ or build/If any box fails, the document is guidance, not a contract — go back to Step 2 and tighten the wording.
Problem. The agent says "done" and the diff touches dozens of files.
git diff --stat ends with 40 files changedgit checkout -- src tests
# add rules 1-3 and 5 to CLAUDE.md, commit, then resend the original task
git add CLAUDE.md && git commit -m "docs: harden CLAUDE.md rules"Problem. The audit commands fail before printing anything.
bash: rg: command not foundripgrep is not installed on the machine, and a snippet that uses rg was copied instead of the Git-only version.git. Either install ripgrep or keep using git ls-files | grep ..., which produces the same lists.Problem. The agent edited files, but git status reports a clean tree.
nothing to commit, working tree clean, while ls -l dist/app.js shows a fresh timestamp.gitignore, so the change never appears in a diff and you cannot review it. The agent fixed the build output instead of the source.git check-ignore -v dist/app.js # prints the .gitignore line that matches
git checkout -- src
npm run buildYou now have a CLAUDE.md built from real audit output, with rules that are checkable by command and a report format that exposes every touched file. Next, keep the file under 120 lines — when it grows past that or you need context to survive between sessions, look at kaeru, a local MCP memory server for Claude Code and other clients, or automate long sessions with claude-code-unlimited.
Does CLAUDE.md replace AGENTS.md?
No. Anthropic announced AGENTS.md support in Claude Code, so both files can exist. Keep the rules in one of them to avoid contradictory instructions, and make the other file a pointer. Check the documentation for the precedence order in your build.
How long should CLAUDE.md be?
Short enough to be read in one pass — keep it under roughly 120 lines, checked with wc -l CLAUDE.md. Move long procedures into separate agents, and move session-to-session context into a memory server.
Will my rules still hold after a Claude Code update?
Your file is not rewritten by updates, but agent behavior shifts: of 244 releases counted over one year, more than three quarters changed the system prompt or tool descriptions. Rerun the Step 3 check after each update.
Why does the agent still reformat code if the rule exists?
Because "be careful with formatting" is advice. Replace it with a constraint that produces output you can inspect — "never reformat unless asked" plus "print git diff --stat before saying done" — and verify with git diff --name-only.
Status: practical guide. Some statements come from vendors; verify in your environment.
Time to complete: 25 minutes You will need: Claude Code CLI installed and signed in (claude --version), Git 2.x, a repository with a clean working tree, a text editor. Optional: an MCP client if you later add a memory server.
Machine data: Citation Map JSON · JSON-LD · Semantic Embeddings — separate stage.
| Entity | Type | Role |
|---|---|---|
| CLAUDE.md | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| claude-ready | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| Claude Code настройка | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| правила для Claude Code | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| Git | платформа/технология | упоминается в заголовке, TL;DR или разделах гайда |
| CLAUDE. | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| Claude | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
No independent confirmation is provided; source claims and editorial conclusions are separated below.
| Source | Type | Role |
|---|---|---|
| No external links | — | — |
Cite as: AI Release. Как настроить CLAUDE.md в Claude Code: аудит репозитория и правила, которые агент соблюдает. ai-release.org.