Official Docs Breakdown: How Claude Remembers Your Project
💬 hippo: Every Claude Code session starts with a blank slate. Want Claude to remember your project conventions, coding habits, and everyday commands? This post covers how to give it persistent memory.
Core Concept: Two Memory Systems
Claude Code provides two complementary memory mechanisms:
| Feature | CLAUDE.md Files |
Auto Memory |
|---|---|---|
| Author | You | Claude |
| Contents | Instructions and rules | Learnings and patterns |
| Scope | Project, user, or organization | Per worktree |
| Load timing | Loaded in full every session | First 200 lines of MEMORY.md loaded every session; topic files loaded on demand |
| Typical use | Coding standards, workflows, project architecture | Build commands, debugging insights, preferences Claude discovers |
| Subagent support | Reads the main process’s CLAUDE.md |
Can maintain its own auto memory |
💬 hippo: Put simply—**
CLAUDE.mdis where you tell Claude what to do, and auto memory is what Claude learns on its own**. Both act as context rather than hard enforcement:CLAUDE.mdis delivered to Claude as a user message, not a system prompt.
1. Deep Dive into CLAUDE.md
1.1 File Locations and Loading Behavior
CLAUDE.md files can live at three distinct scopes:
| Scope | Location | Purpose | Use Cases | Shared With |
|---|---|---|---|---|
| Managed policy | macOS: /Library/Application Support/ClaudeCode/CLAUDE.mdLinux/WSL: /etc/claude-code/CLAUDE.mdWindows: C:\Program Files\ClaudeCode\CLAUDE.md |
Organization-wide IT-managed instructions | Banning specific tools, enforcing security policies | All users in the organization |
| Project instructions | ./CLAUDE.md or ./.claude/CLAUDE.md |
Project architecture, coding standards, common workflows | Code style, build commands, test conventions | Team members via git |
| User instructions | ~/.claude/CLAUDE.md |
Personal preferences across all projects | Personal coding habits, preferred workflows | Just you (all projects) |
Claude Code walks up the directory tree from the current working directory and loads every CLAUDE.md it finds along the way. CLAUDE.md files in subdirectories are loaded on demand when Claude reads files in those directories.
Special handling for HTML comments: Block-level HTML comments (<!-- ... -->) are stripped before the file is injected into Claude’s context, while comments inside code blocks are preserved. You can leave notes for human maintainers in CLAUDE.md without burning context tokens:
1 | <!-- Notes for human maintainers—stripped before entering Claude's context --> |
Loading from Additional Directories (--add-dir)
The --add-dir flag grants Claude access to directories outside the main working directory, but it does not load CLAUDE.md files from those directories by default. To include them as well, set the following environment variable:
1 | CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 claude --add-dir ../shared-config |
💬 hippo: Stripping HTML comments is surprisingly handy. I use them in
CLAUDE.mdto record when and why a section was added—easier for me to maintain, with zero wasted context window.
1.2 Writing Effective Instructions and Organizing Rules
CLAUDE.md is context, not a hard configuration constraint. Because it is passed to Claude as a user message, Claude does its best to follow it—and the more specific and concise your instructions are, the higher the adherence.
Four core principles:
| Principle | Guideline | Example |
|---|---|---|
| Size | Keep each file under 200 lines | Oversized files burn context and dilute compliance |
| Structure | Group rules with headings and bullet lists | Structured sections are far easier to follow than walls of text |
| Specificity | Write concrete, verifiable rules | “Use 2-space indentation” instead of “format code properly” |
| Consistency | Eliminate conflicting instructions | Two contradictory rules force Claude to pick arbitrarily |
@path Import Syntax
CLAUDE.md supports @path syntax to import external files:
1 | # Project Overview |
Import rules: both relative and absolute paths are supported, recursion is capped at 5 levels, and relative paths resolve against the importing file.
Modular Rules with .claude/rules/
Larger repositories can split instructions by topic inside .claude/rules/ and scope each rule file to specific file paths via paths frontmatter:
1 | # .claude/rules/typescript.md |
Glob matching examples:
| Pattern | Matches |
|---|---|
**/*.ts |
All TypeScript files in any directory |
src/**/* |
Every file under src/ |
*.{ts,tsx} |
.ts and .tsx files in the current directory (brace expansion) |
src/**/*.{ts,tsx} + tests/**/*.test.ts |
Multiple patterns combined across directories |
💬 hippo: Scoping with
pathsis the best way to cut context noise. In a mixed frontend/backend repo, scoping TypeScript rules tosrc/**keeps them out of context when you are editing Python files.
User-Level Rules and Symlinks
Rules in ~/.claude/rules/ apply to every project on your machine and load before project rules (project rules take higher precedence). .claude/rules/ also supports symlinks, so you can maintain one shared rule set and link it into multiple repositories.
1.3 Managing Large Teams
In team and enterprise environments, it helps to separate Managed Settings from Managed CLAUDE.md:
| Dimension | Managed Settings | Managed CLAUDE.md |
|---|---|---|
| Nature | Technical hard enforcement | Behavioral guidance |
| Typical use | Blocking specific tools, restricting permissions, enforcing proxies | Code style, workflows, architecture standards |
| Excludable? | Managed by IT | Cannot be excluded (ensures org policies always apply) |
| Distribution | Deployed via enterprise management tools | Placed as a system-level file |
💬 hippo: Managed
CLAUDE.mdcannot be excluded viaclaudeMdExcludes—that is an intentional security boundary so organizational compliance rules always remain active.
Excluding Unrelated CLAUDE.md Files
In a monorepo, you may want to ignore other teams’ CLAUDE.md files. claudeMdExcludes merges across layers; put it in .claude/settings.local.json to keep exclusions local without affecting teammates:
1 | { |
2. Deep Dive into Auto Memory
2.1 How It Works and Where It Lives
Auto memory lets Claude decide what is worth remembering—build commands, debugging insights, architecture decisions, and preferences you have corrected. Claude does not write memory on every session; it only saves notes when it encounters something worth retaining.
Directory layout:
1 | ~/.claude/projects/<project>/memory/ |
Key details:
- The first 200 lines of
MEMORY.mdare loaded at the start of every session; topic files are read on demand. - The
<project>directory is derived from the git repository, so all worktrees of the same repo share memory. - Auto memory is machine-local and is not synced via git. On a new machine, Claude has to re-learn from scratch.
autoMemoryDirectoryis rejected in project settings (.claude/settings.json) as a security safeguard, preventing a shared repo from redirecting memory writes to sensitive paths.
To customize the storage directory, configure it at the policy, local, or user level only:
1 | // ~/.claude/settings.local.json (local settings) |
💬 hippo: Whenever you see “Writing memory” or “Recalled memory” in the UI, Claude is updating or reading these memory files.
2.2 Settings and the /memory Command
| Setting | Supported Scopes | Default | Description |
|---|---|---|---|
autoMemoryEnabled |
User, local, project | true |
Enables or disables auto memory; can also be disabled with CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 |
autoMemoryDirectory |
Policy, local, user | ~/.claude/projects/<project>/memory/ |
Storage path for auto memory files; not accepted in project settings |
claudeMdExcludes |
Policy, user, project, local | [] |
Array of glob patterns for CLAUDE.md files to skip; merged across scopes; managed policy cannot be excluded |
Running /memory lets you:
- List loaded
CLAUDE.mdand rule files to verify what is actually active - Toggle auto memory on or off on the fly
- Open the memory folder to inspect and edit files directly
“Remember this” vs. “Add this to CLAUDE.md“: These are two different actions. Telling Claude to “remember this” writes to auto memory (Claude’s own notes), whereas saying “add this to CLAUDE.md“ edits your instruction file (your explicit rules). Claude maintains the former; you own the latter.
💬 hippo: To audit what auto memory has stored, run
/memoryand open the memory folder. I periodically prune stale or wrong entries to keep memory signal-to-noise high.
3. Troubleshooting and Comparisons
3.1 Quick Troubleshooting Guide
Claude ignores my CLAUDE.md
Checklist:
- Run
/memoryto confirm the file was actually loaded. - Check that the file sits in a valid location (repo root or
.claude/). - Make instructions concrete—“Use 2-space indentation” works far better than “format code nicely.”
- Check for conflicting rules—contradictions cause Claude to choose arbitrarily.
I don’t know what auto memory has saved
Run /memory, open the memory folder, and inspect MEMORY.md alongside the topic files. Delete anything outdated by hand.
CLAUDE.md has grown too large
- Move detailed sections into standalone files and import them via
@path. - Split rules by topic in
.claude/rules/withpathsfrontmatter. - Target under 200 lines per file.
Instructions disappear after /compact
CLAUDE.md is reloaded from disk after /compact, so it survives compaction intact. If a rule vanished, it was only mentioned in chat and never written to disk. Fix: explicitly tell Claude to “add this to CLAUDE.md.”
--append-system-prompt: System-Prompt-Level Enforcement
When you need Claude to strictly follow instructions rather than treat them as best-effort guidance, use --append-system-prompt. It appends text directly to the system prompt, making it ideal for scripts and automation:
1 | # Enforce a specific code style in CI scripts |
Comparison:
| Mechanism | Delivery | Enforcement Strength | Best For |
|---|---|---|---|
CLAUDE.md |
Sent as a user message | Best-effort adherence | Project conventions, coding standards, daily workflows |
--append-system-prompt |
Appended to the system prompt | Stronger enforcement | CI/CD scripts, automated jobs, non-negotiable constraints |
💬 hippo:
--append-system-promptmust be passed on every invocation, so it fits scripts and automation better than interactive daily work—stick toCLAUDE.mdfor interactive sessions.
4. Best Practices Summary
| Scenario | Recommended Approach |
|---|---|
| New project | Start with a CLAUDE.md documenting build commands and directory structure |
| Team collaboration | Put shared conventions in ./CLAUDE.md and commit it to git |
| Personal preferences | Store them in ~/.claude/CLAUDE.md to apply across all projects |
| Large codebase | Organize rules by topic under .claude/rules/ with paths scoping |
| Monorepo | Use claudeMdExcludes to skip unrelated teams’ files |
| Debugging rule loading | Run /memory to inspect active files |
| Maintainer notes | Put HTML comments in CLAUDE.md so they don’t consume context |
| Strict enforcement | Pass --append-system-prompt in scripts and automation |
CLAUDE.md is the employee handbook you write for Claude; auto memory is Claude’s own work notebook—used together, Claude gets sharper on your codebase with every session.
Series Navigation
- Index: Claude Code Complete Guide · Series Index
- Previous: Official Docs Breakdown: Common Workflows
- Next: Official Docs Breakdown: Agent Skills
Based on How Claude remembers your project - Claude Code Docs.
Last updated: 2026-03-31






