CLAUDE.md: How to Teach Claude Code Your Project's Rules

CLAUDE.md is your project's manual. With a few well-chosen lines, Claude Code stops repeating mistakes and follows your rules.

Updated · 2 min read

If you keep making the same corrections in Claude Code, that knowledge belongs in a file. That's what CLAUDE.md is for.

What it is

It's a Markdown file at your project root that Claude Code reads at the start of each session. Use it to record coding standards, architecture decisions, preferred libraries and review checklists.

If your repository already has an AGENTS.md for other coding agents, Claude Code can use that instead.

A lean example

# Online Store

## Commands
- Install: npm ci
- Run: npm run dev
- Test: npm test

## Standards
- Strict TypeScript; avoid `any`
- Components live in app/components
- Dates are always UTC in the database

## Before finishing
- Run npm test and the type checker

## Never
- Edit migrations/ files that were already applied

What's worth including

  • Commands to install, run and test.
  • Conventions that aren't obvious from the code.
  • Decisions that look odd, with the reason.
  • What must never be changed.

What to leave out

  • Anything you can learn by reading the code.
  • Long explanations.
  • Passwords, keys and tokens. This file usually goes into the repository.

Smaller is better. Every line competes for the model's attention.

How to maintain it

When you correct Claude a second time on the same point, add a rule. When a rule stops making sense, remove it. Treat the file like code and have the team review it.

When to use other features

Feature Best for
CLAUDE.md Rules that apply to every session
Skills Repeatable workflows you call when needed
Hooks Automatic commands before or after actions
Auto memory Learnings Claude saves between sessions

If a rule must always happen, such as formatting after edits, a hook is more reliable than a written instruction.

Frequently asked questions

Do I have to write the file by hand?

No. You can ask Claude Code to analyze the project and generate a first version with the /init command.

What's the ideal length?

As short as possible. Focus on what prevents real mistakes.

Is it useful for non-developers?

Yes. For a simple website, it can hold your brand, tone and publishing process.

Keep reading

Independent content. Claude is a trademark of Anthropic. This article is not affiliated with Anthropic.