← All guides AI Release
RU Subscribe to @ai_releaseorg

How to Set Up CLAUDE.md in Claude Code: Repo Audit and Rules the Agent Actually Follows

Updated: 29.11.2026 · AI Release · @ai_releaseorg
How to Set Up CLAUDE.md in Claude Code: Repo Audit and Rules the Agent Actually Follows

TL;DR

What you'll get

Quick start

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.

Copy-paste prompt

Send this to Claude Code inside the repository root before Step 1. It produces the file content; you review and commit it.

PromptCopy the whole block — this is the ready-to-use system prompt
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.

Requirements and setup

claude --version

You 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.

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.

Step 1. Audit the repository before writing a single rule

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 -u

Example output for a repository with 312 tracked files:

312
     84 src
     51 tests
     33 docs
     19 scripts
package.json
dist

Why: 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".

Step 2. Write CLAUDE.md: repo map, commands, hard rules, report format

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
![Illustration: Report format](https://ai-release.org/guides/img/kak-nastroit-claude-md-v-claude-code-audit-repozitoriya-en-2.jpg?v=1795941925)

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-only

wc -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.

Step 3. Verify the agent actually follows the rules

Illustration: Step 3. Verify the agent actually follows the rules
Illustration: Step 3. Verify the agent actually follows the rules

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 --stat

Example: 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.

If any box fails, the document is guidance, not a contract — go back to Step 2 and tighten the wording.

Troubleshooting

Problem. The agent says "done" and the diff touches dozens of files.

git 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.

Problem. The agent edited files, but git status reports a clean tree.

git check-ignore -v dist/app.js   # prints the .gitignore line that matches
git checkout -- src
npm run build

Summary and next steps

You 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.

FAQ

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.

🤖 AI summary

AI Release Knowledge Layer
Machine-readable description · Version 1.0

Status: practical guide. Some statements come from vendors; verify in your environment.

1. Summary

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.

Inside: direct answers, key facts, entities, context, reliability, unknowns and sources.

Machine data: Citation Map JSON · JSON-LD · Semantic Embeddings — separate stage.

Full Knowledge Layer: sections 2–8

2. Direct answers

What is required?
macOS 13+, a modern Linux distribution, or Windows 10/11 with PowerShell 7.; Claude Code CLI installed and authenticated. Confirm with:; Git repository with a clean tree: git status --short prints nothing.; About 25 minutes. → details (AR-GUIDE-KAKNASTROI-003)
How to do it?
Step 1. Audit the repository before writing a single rule → Step 2. Write CLAUDE.md: repo map, commands, hard rules, report format → Step 3. Verify the agent actually follows the rules → details (AR-GUIDE-KAKNASTROI-004)
Which topics does it cover?
CLAUDE.md, claude-ready, Claude Code настройка, правила для Claude Code → details (AR-GUIDE-KAKNASTROI-002)
What are the key points?
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. → details (AR-GUIDE-KAKNASTROI-007)

3. Key facts

  1. Time to complete: 25 minutes — evidence; status: заявление источника.
  2. 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. — evidence; status: заявление источника.
  3. macOS 13+, a modern Linux distribution, or Windows 10/11 with PowerShell 7. — evidence; status: заявление источника.
  4. Claude Code CLI installed and authenticated. Confirm with: — evidence; status: заявление источника.
  5. Git repository with a clean tree: git status --short prints nothing. — evidence; status: заявление источника.

4. Entities

EntityTypeRole
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 или разделах гайда

5. Context

  • Guide — describes → How to Set Up CLAUDE.md in Claude Code: Repo Audit and Rules the Agent Actually Follows (AR-GUIDE-KAKNASTROI-001).
  • Guide — includes step → Step 1. Audit the repository before writing a single rule (AR-GUIDE-KAKNASTROI-001).

6. Reliability

Confirmed

No independent confirmation is provided; source claims and editorial conclusions are separated below.

Source claims

  • Product features, versions, prices and limits come from vendors and the guide.
  • Commands and steps are recommendations, not guaranteed results.

AI Release analysis

  • Structure, comparison and selection criteria are editorial.
  • The guide does not replace an independent audit or legal advice.

7. Unknowns

  • Current versions, prices and limits.
  • Independent benchmarks and quality checks.
  • Terms of use and data policy.

8. Sources

SourceTypeRole
No external links——

Cite as: AI Release. Как настроить CLAUDE.md в Claude Code: аудит репозитория и правила, которые агент соблюдает. ai-release.org.