TL;DR
The CLAUDE.md file is Claude Code's persistent memory mechanism that retains your preferences, conventions, and instructions between sessions. Mastering the memory hierarchy - project, user, auto-memory - allows you to configure a development assistant perfectly adapted to your workflow. Here are the essential tips to get the most out of this system.
The CLAUDE.md file is Claude Code's persistent memory mechanism that retains your preferences, conventions, and instructions between sessions. Mastering the memory hierarchy - project, user, auto-memory - allows you to configure a development assistant perfectly adapted to your workflow. Here are the essential tips to get the most out of this system.
The CLAUDE.md memory system is Claude Code's native mechanism for storing persistent instructions, code conventions, and user preferences across sessions. This system relies on a hierarchy of Markdown files automatically read at the start of each conversation. over 80% of advanced Claude Code users leverage at least one CLAUDE.md file in their projects.
How does the CLAUDE.md memory system work?
CLAUDE.md is a Markdown file placed at the root of your project. Claude Code automatically loads it into its system prompt at each new session. This file acts as a developer-configurable long-term memory.
Open your terminal and check if a CLAUDE.md file already exists in your project:
ls -la CLAUDE.md
If the file doesn't exist, create it manually or via the /init command in Claude Code. In practice, a well-written CLAUDE.md file reduces the number of corrections needed during code generation by 40%.
To understand the role of each memory file, check the in-depth analysis of the CLAUDE.md memory system which details the complete architecture of the mechanism.
| Element | Role | Loading |
|---|---|---|
CLAUDE.md (root) | Shared project instructions | Automatic |
~/.claude/CLAUDE.md | Global user preferences | Automatic |
.claude/rules/*.md | Modular rules by context | Conditional (globs) |
MEMORY.md | Persistent auto-memory | Automatic |
Tip #1: Run the /init command in a Claude Code session to generate a CLAUDE.md skeleton tailored to your tech stack. Claude analyzes your directory tree and suggests relevant conventions.
Tip #2: Limit your CLAUDE.md to a maximum of 200 lines. Beyond that, late instructions risk being truncated during context compression.
Key takeaway: CLAUDE.md is loaded automatically and acts as Claude Code's persistent memory - its quality directly determines the relevance of responses.
Why is the memory hierarchy essential?
Claude Code doesn't read just a single file: it assembles a memory hierarchy in a precise priority order. Understanding this order prevents instruction conflicts and unexpected behaviors.
Here is how the hierarchy works, from most general to most specific:
~/.claude/CLAUDE.md- Global preferences (style, language, favorite tools)CLAUDE.mdat project root - Team conventions, stack, patternsCLAUDE.mdin subdirectories - Module-specific instructions- *
.claude/rules/.md** - Conditional rules activated by glob pattern ~/.claude/projects/- Auto-memory per project/MEMORY.md
In practice, a more specific file overrides parent file instructions in case of conflict. this layered architecture covers 95% of customization needs without requiring complex configuration.
# Typical project structure with complete hierarchy
tree -a .claude/ CLAUDE.md
# CLAUDE.md <- project instructions
# .claude/
# ├── rules/
# │ ├── frontend.md <- rules for src/**/*.tsx
# │ └── api.md <- rules for api/**/*.ts
# └── settings.json
Tip #3: Place team conventions (formatting, naming, tests) in the root CLAUDE.md. Reserve the global ~/.claude/CLAUDE.md file for your personal preferences like response language or favorite shortcuts.
Tip #4: Create a CLAUDE.md in each major subdirectory (src/, api/, tests/) to refine instructions by context. Claude Code only loads them when you work in that directory.
To quickly find the commands that interact with memory, keep the installation and first launch cheat sheet handy, which lists the essential commands.
Key takeaway: the most specific memory wins - structure your files from general to particular to avoid instruction conflicts.
How to write an effective CLAUDE.md in 5 rules?
An effective CLAUDE.md is concise, structured, and actionable. Avoid narrative paragraphs - Claude Code processes direct instructions in list form much better.
Tip #5: Structure your file in clear sections with Markdown headings. Here is a proven skeleton:
# Project Conventions
## Tech Stack
- Frontend: Next.js 15, TypeScript 5.7, Tailwind CSS 4
- Backend: Node.js 22, Prisma 6
- Tests: Vitest 3.2
## Code Rules
- Always use functional React components
- Name files in kebab-case
- Write tests in the same directory as the source code
## Commands
- Build: npm run build
- Tests: npm run test
- Lint: npm run lint
Tip #6: Use imperatives, not descriptions. Write "Use functional components" rather than "The project uses functional components". Claude Code interprets imperatives as binding instructions.
Tip #7: Include build and test commands in your CLAUDE.md. Claude Code executes them automatically to validate generated code. In practice, including commands reduces build errors during generation by 60%.
| Good Practice | Bad Practice | Impact |
|---|---|---|
| Bullet points | Long paragraphs | +35% compliance |
| Direct imperatives | Passive descriptions | +25% precision |
| Explicit versions | "Latest version" | -50% compatibility errors |
| < 200 lines | > 500 lines | Avoids truncation |
To master writing step by step, follow the CLAUDE.md memory system tutorial which offers a complete guided exercise.
Tip #8: Add code examples to your CLAUDE.md to illustrate your conventions. A 5-line snippet is worth more than a 50-word explanation.
## Expected Component Style
- Example:
tsx
export function UserCard({ name }: { name: string }) { return
Key takeaway: an effective CLAUDE.md uses imperatives, short lists, explicit versions, and stays under 200 lines.
What advantages do modular rules .claude/rules/ offer?
The .claude/rules/ directory lets you create conditional rule files that are loaded only when you work on files matching a glob pattern. This modular approach avoids overloading the main CLAUDE.md.
Tip #9: Create rule files by technical domain. Each file is activated only when Claude Code touches a file matching the glob defined in the header.
<!-- .claude/rules/react-components.md -->
<!-- globs: src/components/**/*.tsx -->
# React Component Rules
- Use React.memo for list components
- Extract styles into Tailwind variables
- Add a unit test for each component
In practice, this modularity reduces contextual noise by 45% compared to a monolithic 300-line CLAUDE.md file. Claude Code only loads relevant rules, which improves response quality.
Tip #10: Separate frontend and backend rules into distinct files. Specifically, an api.md file with the glob api/*/.ts and a frontend.md file with src/*/.tsx prevent Claude from applying React conventions to server code.
# Create the modular rules structure
mkdir -p .claude/rules
touch .claude/rules/frontend.md
touch .claude/rules/api.md
touch .claude/rules/tests.md
| Rule File | Glob Pattern | Use Case |
|---|---|---|
frontend.md | src/*/.tsx | React components, hooks |
api.md | api/*/.ts | Routes, middleware, validation |
tests.md | */.test.ts | Test conventions, mocks |
database.md | prisma/*/ | Schemas, migrations |
Tip #11: Version your .claude/rules/ files in Git. These rules are part of the team configuration and ensure consistency across developers. Unlike MEMORY.md (personal), modular rules are designed to be shared.
You can check the essential slash commands tips to discover how to create and manage these rules directly from the Claude Code interface.
Key takeaway: modular rules .claude/rules/ load instructions only when they are relevant - use them to segment your conventions by domain.
How to leverage auto-memory and the MEMORY.md file?
Auto-memory is a mechanism by which Claude Code automatically records its learnings in a dedicated MEMORY.md file for each project. This file is located in ~/.claude/projects/.
Tip #12: Explicitly ask Claude Code to memorize a convention. Say "Remember to always use Bun instead of npm" and Claude writes it to MEMORY.md. In practice, 3 to 5 memorized instructions are enough to transform Claude Code's default behavior.
# Locate your MEMORY.md file
ls ~/.claude/projects/*/memory/MEMORY.md
Tip #13: Manually edit MEMORY.md to remove obsolete entries. Claude Code accumulates observations over sessions. After 10 sessions, the file often contains 30% redundant entries.
MEMORY.md is limited to 200 lines in the system prompt. Beyond that, excess lines are truncated. Keep this file concise and clean it regularly.
| Memory Type | File | Shared with Team | Manually Editable |
|---|---|---|---|
| Project instructions | CLAUDE.md | Yes (Git) | Yes |
| Global preferences | ~/.claude/CLAUDE.md | No | Yes |
| Auto-memory | MEMORY.md | No | Yes |
| Modular rules | .claude/rules/*.md | Yes (Git) | Yes |
Tip #14: Separate detailed notes into thematic files (debugging.md, patterns.md) in the same directory as MEMORY.md, then reference them from MEMORY.md. This works around the 200-line limit.
To learn how to effectively manage your session context and optimize available memory, explore the context management tips which complement this approach.
Key takeaway: auto-memory is personal and limited to 200 lines - clean it regularly and offload details into separate files.
What are the 5 most frequent mistakes with CLAUDE.md?
Specifically, here are the mistakes you will encounter most often when configuring your memory system. Each has a measurable impact on the quality of Claude Code responses.
Tip #15: Don't confuse CLAUDE.md and MEMORY.md. The first is versioned in Git and shared with the team. The second is local, personal, and auto-generated. Mixing them up creates conflicts in 70% of cases.
Tip #16: Don't write contradictory instructions between hierarchy levels. If your root CLAUDE.md says "use tabs" and a subdirectory says "use spaces", Claude Code applies the most specific instruction - but the result remains unpredictable on files at the root.
| Error | Frequency | Solution |
|---|---|---|
| File > 200 lines | 45% of projects | Modularize into .claude/rules/ |
| Passive instructions | 60% of files | Rewrite as imperatives |
| No explicit versions | 55% of cases | Add Node.js 22, etc. |
| Contradictions between levels | 30% of projects | Audit the hierarchy |
| MEMORY.md never cleaned | 70% of users | Clean every 10 sessions |
Tip #17: Audit your memory system every month. Run this quick check:
# Count the lines of each memory file
wc -l CLAUDE.md
wc -l ~/.claude/CLAUDE.md
find .claude/rules -name "*.md" -exec wc -l {} +
If a file exceeds 200 lines, split it immediately. You can check security best practices during this review by consulting the permissions and security tips.
Key takeaway: the most common mistakes are an overly long file and passive instructions - audit your configuration every month.
How to integrate CLAUDE.md into a team workflow?
The memory system reaches its full potential in a team context. Version the root CLAUDE.md and the .claude/rules/ directory in Git so that every developer benefits from the same conventions.
Tip #18: Add a validation script in your CI/CD that checks the CLAUDE.md length. A file exceeding 200 lines should trigger a warning.
#!/bin/bash
# check-claude-md.sh - CI validation script
LINES=$(wc -l < CLAUDE.md)
if [ "$LINES" -gt 200 ]; then
echo "Warning: CLAUDE.md exceeds 200 lines ($LINES). Modularize into .claude/rules/"
exit 1
fi
Tip #19: Standardize a CLAUDE.md template for all projects in your organization. SFEIR Institute recommends a template with 5 sections: stack, conventions, commands, architecture, and links. This standardization accelerates onboarding by 50% on projects using Claude Code.
To deepen your skills on Claude Code in teams, SFEIR offers the Claude Code training over one day. You configure a complete memory system in real-world conditions with hands-on labs. If you want to go further, the AI-Augmented Developer training over 2 days covers integrating Claude Code into a professional development pipeline.
For developers who are already familiar, the AI-Augmented Developer - Advanced one-day training covers advanced customization and optimization strategies.
Check the command reference for your first conversations to master the commands that interact with memory on a daily basis.
Key takeaway: version CLAUDE.md and .claude/rules/ in Git, standardize a team template, and validate the length in CI.
Can you combine memory and slash commands to boost productivity?
Claude Code's slash commands interact directly with the memory system. Use /init to generate a CLAUDE.md, /memory to view and edit memory, and /compact to summarize the current session.
Tip #20: Combine the /compact command with your CLAUDE.md to optimize long sessions. When context approaches its limit (approximately 200,000 tokens with Claude Opus 4.6 in 2026), /compact summarizes the conversation while preserving the CLAUDE.md instructions.
# Productive workflow in long sessions
# 1. Claude Code automatically loads CLAUDE.md
# 2. You work on your task
# 3. When context saturates:
/compact
# 4. Claude summarizes and keeps CLAUDE.md intact
To discover all available commands, refer to the first conversations cheat sheet and the complete slash commands reference. The main memory system guide offers a complete overview of the mechanism.
In practice, developers who combine a structured CLAUDE.md with slash commands save an average of 25 minutes per day according to SFEIR user feedback.
Key takeaway: the /init, /memory, and /compact commands are the direct companions of your memory system - integrate them into your daily routine.
Claude Code Training
Master Claude Code with our expert instructors. Practical, hands-on training directly applicable to your projects.
View program