Claude Code Memory

Definition

Claude Code has two complementary memory systems — CLAUDE.md (instructions you write) and auto memory (notes Claude writes from your corrections) — both loaded at the start of every conversation and treated as context, not enforced configuration.

Key Points

  • CLAUDE.md vs auto memory: CLAUDE.md = explicit instructions, scoped project/user/org, loaded every session; auto memory = machine-generated notes from corrections/preferences, per-repository (shared across worktrees).
  • CLAUDE.md hierarchy (load order, broadest→most specific): managed policy (C:\Program Files\ClaudeCode\CLAUDE.md on Windows, cannot be excluded) → user ~/.claude/CLAUDE.md → project ./CLAUDE.md or ./.claude/CLAUDE.md → local ./CLAUDE.local.md (gitignored).
  • Modular rules: .claude/rules/ holds topic files discovered recursively, scoped via paths YAML frontmatter (glob, brace expansion, 1,000-pattern / 4MiB budget); supports symlinks; user-level ~/.claude/rules/ load before project rules.
  • AGENTS.md: Claude reads CLAUDE.md, not AGENTS.md; import via @AGENTS.md or symlink (ln -s AGENTS.md CLAUDE.md; Windows needs admin/Developer Mode, so use import).
  • Auto memory: on by default; stores MEMORY.md index + topic files in ~/.claude/projects/<project>/memory/; first 200 lines / 25KB loaded per session (writes past limit error); Claude reads topic files on demand; toggle via /memory, autoMemoryEnabled, or CLAUDE_CODE_DISABLE_AUTO_MEMORY=1.
  • Token/context: target under 200 lines per CLAUDE.md; imports load at launch (don’t reduce context); path-scoped rules save context; HTML comments stripped; CLAUDE.md loads in full regardless of length (only MEMORY.md is capped).

Implications

Memory is a context-budget resource, not a configuration store. Keeping CLAUDE.md under ~200 lines and pushing workflow detail to on-demand skills (per token-usage-reduction) bounds the fixed cost every session pays. Auto memory’s 200-line/25KB cap on MEMORY.md is the token-visible limit; the tool itself is the compiler that turns corrections into a durable, machine-local index. Path-scoped rules are the surgical lever for large monorepos.

Open Questions

  • How auto memory’s per-repo sharing behaves across worktrees in practice.
  • Whether the 200-line / 25KB MEMORY.md cap is configurable.

token-usage-reduction — why keeping memory files small matters claude-code-system-prompt — the agent these memory files configure anthropic-tool-use-api — how instructions become tool-driving context

Sources

  • raw/external/code-claude-com-memory-09a26217.md