Claude Code CLAUDE.md File

Claude Code starts every session with no memory of earlier conversations. The CLAUDE.md file solves that gap. It stores your project rules, commands, and preferences in plain text, and Claude Code reads it at the start of each session. One well-written file saves you from repeating the same instructions again and again.

The Sticky Note Idea

Imagine a new teammate who arrives each morning with no memory of yesterday. A sticky note on their desk says how your team works: which commands to run, which style to follow, which folders to avoid. CLAUDE.md is that sticky note for Claude Code.

Session starts
     ↓
Claude Code reads CLAUDE.md
     ↓
Rules and commands enter its memory
     ↓
Every answer follows your project habits

Creating the File

Type /init inside a session. Claude Code scans your project and drafts a CLAUDE.md file with the commands and structure it discovers. Review the draft and trim anything you do not need. You can create the file by hand in the project root.

What to Put Inside

SectionExample Content
Build and test commandsnpm run build, npm run test
Code styleUse two spaces; prefer arrow functions
Project layoutAPI code lives in /server; pages live in /web
WarningsNever edit files inside /generated
Team habitsWrite commit messages in present tense

A Sample File

# Shop Website

## Commands
- Run tests: npm run test
- Start dev server: npm run dev

## Style
- Use two-space indentation
- Name files in lowercase with hyphens

## Rules
- Never edit anything inside /generated
- Add a test for every new function

Short bullet lines work best. Claude Code follows direct statements more reliably than long paragraphs.

Where CLAUDE.md Files Live

Claude Code loads more than one file when they exist. Each location serves a different audience.

~/.claude/CLAUDE.md        → personal rules for every project
project-folder/CLAUDE.md   → shared rules for this project
project-folder/web/CLAUDE.md → rules for one sub-folder only

Commit the project file to version control so the whole team benefits. Keep personal habits, such as your favorite explanation style, in the home-folder file.

Editing Memory During a Session

Run /memory to open the memory files in your editor. Add a rule the moment you notice a repeated correction. A rule like "Always use the existing logger instead of print statements" prevents the same mistake tomorrow.

Writing Rules That Work

Be Specific

"Format code properly" leaves too much room for guessing. "Use two-space indentation and single quotes" gives a clear target.

Stay Short

A long file crowds the context window and dilutes important rules. Aim for the essentials. Move rarely used details into separate documents and point to them.

Update Regularly

Old rules cause confusion. Review the file whenever the project changes direction.

Rules Versus Enforcement

CLAUDE.md guides behavior, but it does not force it. Claude Code usually follows the file, and occasional misses happen. Use permission rules or hooks when an action must never occur.

A Starter Checklist

Beginners often wonder what belongs in a first CLAUDE.md. Start with three items: the command that runs tests, the command that starts the project, and one sentence about the project's purpose. Add rules only when Claude Code repeats a mistake. Small files grow naturally from real needs, and every line earns its place through experience. Review the file monthly and delete anything that no longer helps.

Key Points

  • CLAUDE.md gives Claude Code lasting memory across sessions.
  • The /init command drafts the file automatically.
  • Project, personal, and sub-folder files each serve a different audience.
  • Short, specific bullet lines work better than long paragraphs.
  • Permission rules and hooks enforce what CLAUDE.md only suggests.