Claude Memory
Overview
Persistent context = markdown loaded into every new context. Two sources: you (CLAUDE.md, rules) and Claude (auto memory).
CLAUDE.md Locations
| Scope | Path |
|---|---|
| Managed policy | macOS /Library/Application Support/ClaudeCode/CLAUDE.md; Linux/WSL /etc/claude-code/CLAUDE.md; Windows C:\Program Files\ClaudeCode\CLAUDE.md |
| Project (shared) | ./CLAUDE.md or ./.claude/CLAUDE.md (the .claude/ one is expected) |
| User | ~/.claude/CLAUDE.md |
| Local (not in git) | ./CLAUDE.local.md |
CLAUDE.md/CLAUDE.local.mdin the working directory and every directory above load at launch, concatenated root-down. Subdirectory ones load on demand when Claude touches files there.AGENTS.mdis read instead when there's noCLAUDE.md/CLAUDE.local.md(v2.1.277+). Change via/config→ Project instructions (claude-md-or-agents-mddefault,claude-md-and-agents-md,claude-md,managed-only).~/.claude/rules/holds personal rules for all projects. Managed CLAUDE.md can also be set via theclaudeMdkey in managed settings./initscans the project and writes one for you./memoryshows what's loaded and opens files.
Writing Good Ones
- Under 200 lines. Longer = less adherence.
- Be concrete: "Use 2-space indentation", "Run
npm testbefore committing", "API handlers live insrc/api/handlers/". - Contradictions → Claude picks arbitrarily. Review periodically.
- It's context, not enforced config.
Split it up
| Tool | Use | Strength |
|---|---|---|
@path/to/file.md imports | Docs and context ("developer handbook") | Guidance, not hard rules. Relative to the importing file, max 5 hops |
.claude/rules/*.md | Rules to always follow, one topic per file | Same priority as .claude/CLAUDE.md; symlinks allowed |
| Auto memory | Claude's own learned preferences | Best guesses |
Scoped rule:
---
paths:
- "src/api/**/*.ts"
---
# API rules
- All endpoints validate input
Skip files in monorepos: "claudeMdExcludes": ["**/monorepo/CLAUDE.md"] in .claude/settings.local.json.
Auto Memory
- On by default; machine-local; one dir per git repo (worktrees share it).
- Path:
~/.claude/projects/<project>/memory/withMEMORY.md(index, first 200 lines or 25KB loaded each session) plus topic files loaded on demand. - Disable:
{"autoMemoryEnabled": false}orCLAUDE_CODE_DISABLE_AUTO_MEMORY=1. - Custom location:
autoMemoryDirectory(user/policy settings only). - Plain markdown, so read/edit/delete freely via
/memory.
Troubleshooting
| Problem | Fix |
|---|---|
| Not following CLAUDE.md | /memory to confirm it's loaded; make rules specific; look for conflicts |
| Don't know what was saved | /memory → open auto-memory folder |
| File too large | Move to imports/rules |
| "Lost after /compact" | It isn't compact: CLAUDE.md is re-read from disk, so it probably wasn't saved |
Related: Claude Settings, Claude Skills, Claude Sessions and Context