Every new Claude Code session in your repo loads a short CLAUDE.md with your commands and rules, and you add one line to it whenever Claude repeats a mistake.
Start Claude Code in your project
Open a terminal. If you don't have Claude Code yet, run the install command below, then open a new terminal window and run 'claude --version'. You should see a version number. Go into your project folder and type 'claude'. The first time, you log in and accept the trust dialog for the folder. You should now see the Claude Code prompt inside your project.
curl -fsSL https://claude.ai/install.sh | bash claude --version cd your-project claude
Run /init to get a first draft
In the session, type /init and press Enter. Claude reads your codebase and writes a starting CLAUDE.md in the project root. If it finds rules from other tools, such as .cursorrules or .github/copilot-instructions.md, it pulls those in too. When it's done, open CLAUDE.md in your editor. Expect it to be too long. That's fine, because the next step is mostly deleting lines.
/init
Cut it down to what Claude can't see
Every line in CLAUDE.md takes up a bit of Claude's attention on every task, so keep only what it can't work out by reading the code. Anthropic suggests keeping four kinds of lines. First, the exact test, typecheck and lint commands, plus how to run a single test file. Next, places where the code is misleading, like an old pattern new code must not copy. Then, decisions that live outside the repo, like which error helper the team picked or how deploys work. Last, anything you've already had to correct twice. Delete folder trees, dependency lists and architecture overviews, because Claude finds those on its own. Write each rule so it can be checked: 'Run pnpm test before committing' instead of 'Test your changes'. Group the rules under short headings and stay under 200 lines. For help with the cuts, run /doctor, which suggests what to remove. You can also paste the prompt below.
Trim CLAUDE.md. Keep only: exact build, test, lint and typecheck commands (and how to run one test file), places where the code is misleading, team decisions that aren't in the repo, and things I had to correct more than once. Remove anything you can learn by reading the code, such as folder trees and dependency lists. Use short headings and bullets, and keep it under 200 lines. Show me the diff before saving.
Add one line each time Claude repeats a mistake
When Claude gets something wrong for the second time, put the fix in the file right away. Ask in plain words and start with 'add this to CLAUDE.md', as in the example below. You can also run /memory, pick the project CLAUDE.md and edit it yourself. One catch: if you just say 'remember ...', Claude saves it to its auto memory, its own notes on your machine, and not to CLAUDE.md. Use the words 'add this to CLAUDE.md' when you want the rule in the shared file.
Add this to CLAUDE.md under Conventions: we use pnpm, never npm or yarn. Tests live next to each package in test/ and run with pnpm test.
Keep personal notes out of the shared file
CLAUDE.md is committed to git, so your whole team gets it. Put things that only matter to you, like your sandbox URL or test account, in CLAUDE.local.md in the project root. It loads together with CLAUDE.md. Add it to .gitignore so it never gets committed. For preferences you want in every project, use ~/.claude/CLAUDE.md in your home folder instead.
echo "CLAUDE.local.md" >> .gitignore
Turn must-never-happen rules into hooks (optional)
Claude follows CLAUDE.md almost every time, but it's still guidance and not a hard lock. For the few rules that can have no exceptions, like 'never edit the migrations folder', use a hook. Claude Code runs a hook every time, whatever Claude decides. You don't have to write it yourself. Ask with the prompt below, then type /hooks to see the result. Keep this list short. A rule like 'prefer named exports' has exceptions, so it stays in CLAUDE.md.
Write a hook that blocks edits to the migrations folder.
Check it works in a fresh session
Type /exit, then start 'claude' again in the same folder. Run /context all and look for CLAUDE.md (and CLAUDE.local.md if you made one) in the list under Memory files. If a file isn't there, Claude can't see it. Then test a rule by asking something like 'How do I run the tests here?'. Claude should answer with the command from your file. When it does, commit CLAUDE.md so your teammates get the same rules. Every few weeks, run /doctor prompt-audit (Claude Code v2.1.283 or later) to find rules that are out of date, point to files that are gone or contradict each other. It only suggests edits and changes nothing until you say so.
/exit claude /context all git add CLAUDE.md .gitignore git commit -m "Add CLAUDE.md project rules"
Get the next automation before it's posted.
One short email with the AI stories that matter. What happened in AI, why it matters, one tool worth trying. Free. Unsubscribe anytime.
