💬 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.md is 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.md is 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.md
Linux/WSL: /etc/claude-code/CLAUDE.md
Windows: 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
2
3
4
5
6
<!-- Notes for human maintainers—stripped before entering Claude's context -->
<!-- Use for maintenance reminders or TODOs, e.g., Last updated: 2026-03 -->

## Build Commands
- Dev: `npm run dev`
- Test: `npm test`

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.md to 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
2
3
4
5
6
7
8
9
10
# Project Overview
See @README.md for project background
See @package.json for available commands

# Detailed Guidelines
- Git workflow: @docs/git-workflow.md
- API design: @docs/api-design.md

# Personal Preferences (not committed to git)
- @~/.claude/my-preferences.md

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
2
3
4
5
6
7
8
9
10
11
# .claude/rules/typescript.md
---
paths:
- "src/**/*.{ts,tsx}"
- "lib/**/*.ts"
- "tests/**/*.test.ts"
---

# TypeScript Development Rules
- All public functions must include JSDoc comments
- Use strict null checks

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 paths is the best way to cut context noise. In a mixed frontend/backend repo, scoping TypeScript rules to src/** keeps them out of context when you are editing Python files.

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.md cannot be excluded via claudeMdExcludes—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
3
4
5
6
{
"claudeMdExcludes": [
"**/monorepo/CLAUDE.md",
"/home/user/monorepo/other-team/.claude/rules/**"
]
}

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
2
3
4
5
~/.claude/projects/<project>/memory/
├── MEMORY.md # Index file; first 200 lines loaded every session
├── debugging.md # Debugging notes
├── api-conventions.md # API conventions
└── patterns.md # Discovered code patterns

Key details:

  • The first 200 lines of MEMORY.md are 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.
  • autoMemoryDirectory is 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
2
3
4
5
// ~/.claude/settings.local.json (local settings)
{
"autoMemoryEnabled": true,
"autoMemoryDirectory": "~/my-custom-memory-dir"
}

💬 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.md and 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 /memory and 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:

  1. Run /memory to confirm the file was actually loaded.
  2. Check that the file sits in a valid location (repo root or .claude/).
  3. Make instructions concrete—“Use 2-space indentation” works far better than “format code nicely.”
  4. 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/ with paths frontmatter.
  • 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
2
3
4
5
# Enforce a specific code style in CI scripts
claude --append-system-prompt "All generated code must use 4-space indentation"

# Enforce output format in automated tasks
claude --append-system-prompt "Output must be valid JSON with no markdown wrapper"

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-prompt must be passed on every invocation, so it fits scripts and automation better than interactive daily work—stick to CLAUDE.md for 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


Based on How Claude remembers your project - Claude Code Docs.

Last updated: 2026-03-31