Memory files
Memory files are Markdown files that Claude reads at the start of every session. They let you give Claude standing instructions about your project — coding conventions, build commands, architecture notes — without repeating them in every conversation.File hierarchy
Claude loads memory files in this order, from lowest to highest priority:| Priority | File | Description |
|---|---|---|
| 1 (lowest) | /etc/claude-code/CLAUDE.md | Managed memory — organization-wide instructions |
| 2 | ~/.claude/CLAUDE.md | User memory — your global personal instructions for all projects |
| 3 | CLAUDE.md (project root) | Project memory — team-shared instructions checked into source control |
| 3 | .claude/CLAUDE.md (project root) | Alternate project memory location |
| 3 | .claude/rules/*.md | Rule files — modular project instructions |
| 4 (highest) | CLAUDE.local.md (project root) | Local memory — your private project-specific instructions (gitignored) |
Files are loaded in reverse priority order so that higher-priority files appear later in the context, which makes the model more attentive to them.
CLAUDE.md — project memory
CLAUDE.md is the primary place for project instructions. It is typically checked into source control so all contributors share the same baseline.
A well-written CLAUDE.md includes:
- Build, test, and lint commands
- Project architecture overview
- Non-obvious conventions or gotchas
- Required environment variables
CLAUDE.local.md — local private memory
CLAUDE.local.md stores instructions specific to your local setup that you do not want to commit. Add this file to your .gitignore.
User memory — ~/.claude/CLAUDE.md
~/.claude/CLAUDE.md applies to all projects. Use it for preferences that are about you, not any specific project.
Rules — .claude/rules/*.md
The.claude/rules/ directory lets you split project instructions into separate files. All .md files in this directory are loaded automatically.
Rules support frontmatter paths: to apply them conditionally to specific file patterns:
src/api/.
@include directives
Memory files can include other files using the@ syntax:
@path/to/file.md— relative to the memory file’s directory@./relative/path.md— explicit relative path@~/home/path.md— relative to your home directory@/absolute/path.md— absolute path
.md, .ts, .json, etc.) can be included; binary files are skipped.
The maximum recommended size for a memory file is 40,000 characters. Larger files are loaded but may reduce the effectiveness of the instructions.
Editing memory with /memory
The/memory command opens an interactive file selector for editing memory files:
$VISUAL or $EDITOR). If the file does not exist, Claude Code creates it before opening. After saving and closing the editor, changes take effect on the next context reload.
Creating CLAUDE.md with /init
The/init command analyzes your project and generates or improves CLAUDE.md:
package.json, README.md, build configs, CI definitions, and existing memory files — then asks clarifying questions before writing the file. You can choose to generate a project CLAUDE.md, a personal CLAUDE.local.md, or both.
Adding working directories with /add-dir
By default, Claude’s working directory is the directory where you launchedclaude. Use /add-dir to grant access to additional directories in the current session:
CLAUDE.md file (if present) is loaded into context.
Context window management
The context window is the live conversation: your messages, Claude’s responses, tool calls, and file reads all consume tokens. Larger contexts cost more and can eventually hit the model’s limit.Viewing context usage
Compacting with /compact
When the conversation is long, use/compact to summarize it:
Automatic compaction warnings
Claude Code tracks remaining context. When context is running low, it displays a warning:/compact suppresses the warning for the rest of the session.
Clearing the conversation with /clear
To start completely fresh, use/clear:
/clear is also available as /reset and /new.
Memory file precedence summary
When the same instruction appears in multiple files, the file with higher priority wins. For example,CLAUDE.local.md instructions override conflicting instructions in CLAUDE.md.
This means you can commit safe defaults in CLAUDE.md and override them personally in CLAUDE.local.md without touching the shared file.