CLAUDE.md rules that actually change Claude Code's behavior

Fewer, sharper lines that Claude Code follows every session, tested one at a time.

By · Published

CLAUDE.md is the Markdown file Claude Code loads at the start of every session to learn how to work in your project: the commands it cannot guess, the conventions the code does not enforce and the actions it must never take. A rule works when it names an exact command, format or limit; a vague line gets ignored.

This guide shows what to include, weak instructions next to strong ones, how the file's scopes and imports work, and how to test each rule.

Where does CLAUDE.md live?

The Claude Code memory documentation lists several scopes: ~/.claude/CLAUDE.md for your preferences in every project, ./CLAUDE.md or ./.claude/CLAUDE.md for the project and its team, and ./CLAUDE.local.md for personal project notes kept out of Git. Files in subfolders load when Claude reads or edits files in that folder. All loaded files add up in the same context, so put narrow rules close to the code they govern.

A file can import another with @path/to/file, up to four levels deep. That keeps the root file short and lets you share one file between tools.

What should you put in CLAUDE.md?

Three kinds of facts earn their place:

  • Commands the agent cannot guess: how to run one test, the full suite, the deploy.
  • Conventions the repository does not enforce: naming, error handling, commit format.
  • Traps that already cost you a session: the test that needs a local database, the module that looks generated but is not.

Leave out anything a quick search finds: file listings, function signatures, recent changes. Claude Code's best practices put it simply: only write down what Claude cannot find by reading the repository. Keep each file under about 200 lines; past that, adherence drops and every turn pays for lines the agent mostly skips.

Weak versus strong instructions

Commits

Weak Likely result Strong Likely result
"Write good commit messages." Generic "Update files" "Conventional commits: feat:, fix:, chore:. Subject under 72 characters, imperative, no period. Body says why." fix: retry token refresh on 401

Tests

Weak Likely result Strong Likely result
"Run the tests before finishing." Guesses npm test, fails on missing variables, or skips "One package: pnpm test --filter <pkg>. Full suite: pnpm test. Read .env.example before inventing a variable." Runs the right command and reads the example file

Guardrails

Weak Likely result Strong Likely result
"Be careful with the database." Drops a table during a "cleanup" "Never run DROP, TRUNCATE or DELETE without WHERE. Schema changes only through prisma migrate dev --name <change>. Ask before editing docker-compose.yml." Proposes the migration and waits

How do CLAUDE.md and AGENTS.md fit together?

Claude Code reads AGENTS.md only when the project has no CLAUDE.md. If you keep both, put the shared rules in AGENTS.md, which Codex and Cursor read, and write @AGENTS.md in CLAUDE.md with any Claude-specific additions below it. The @ import is a Claude Code feature that other tools do not document, so the shared content must live in AGENTS.md itself, not the other way round. The guide How to write an AGENTS.md file covers that file.

How do you test whether a rule is followed?

Add one instruction, start a new session, and give a task that should trigger it. If the rule says "never edit migration files", ask for a schema change and read the diff. Test one rule at a time: with five new rules in play, you cannot tell which one changed the output.

  • Ignored: the agent follows the rule on easy tasks and drops it under load. Make the instruction more direct.
  • Misread: the agent does something close but wrong, such as renaming a migration instead of leaving it alone. Add an example.

Claude Code's guidance is to add a rule when you have had to correct the same thing twice, and to review the file regularly to remove outdated or conflicting lines.

Which mistakes waste context?

  • Changelogs: "we moved to pnpm in March" is history, not an instruction.
  • Copies of the README: the agent reads the same thing twice.
  • Adjectives: "write clean code" changes nothing; "use vitest, never jest" does.
  • Contradictions: a new rule added without deleting the old one. The agent follows whichever seems closer to the task. Delete the old line in the same commit.

How does CLAUDE.md relate to shared project memory?

CLAUDE.md is static instruction for Claude Code, written once and read every session. It does not hold yesterday's decision unless someone writes it in, and Codex or Cursor do not read it. For decisions, current state and history shared across tools, keep a decisions log the file points to ("read docs/decisions.md before non-trivial changes"), or a shared project record such as Fileaify, which agents read through its MCP connector and update through reviewed proposals. Rules in the file, history in the record.

Sources

Try it

The demo runs on a prepared project, with no account. To share decisions across Claude Code, Codex and Cursor, create a free workspace and give your agent https://fileaify.com/agent.

Common questions

Does Claude Code read AGENTS.md instead of CLAUDE.md?

Only when there is no CLAUDE.md. If you have both, write @AGENTS.md in CLAUDE.md so Claude Code imports the shared file.

How long should CLAUDE.md be?

Claude Code's documentation targets under about 200 lines per file. Longer files consume more context and reduce adherence; move detail into folder files or imported files.

Is CLAUDE.md sent on every turn?

It is loaded into the context at the start of the session and stays there; the project-root file is reloaded after compaction. Folder files load when Claude works in that folder.

Why does Claude ignore an instruction in CLAUDE.md?

Usually because it is vague or contradicted elsewhere. Rewrite it as an exact command with an example, remove the conflicting line, and test it alone in a new session.

Written with AI assistance, reviewed by Stéphane Mermet and checked against the product. Fileaify publishes this guide and sells the service it describes.