Skip to content

A Practical Guide to Claude Memory Files

Claude memory files give an agent project-level persistence and steering, using CLAUDE.md and hooks to keep context lean and automate workflows.

Tuan Tran Van
6 min read
Contents (6 sections)
  1. Why you need memory files for Claude
  2. The types of Claude memory and steering files
  3. How CLAUDE.md works (for members)
  4. Choosing the right mechanism: rules, skills, subagents, or hooks? (for members)
  5. Best practices for setting them up (for members)
  6. References (for members)

Claude memory files are the architectural mechanism for giving an AI agent project-level persistence and steering.

Without a structured memory system, Claude Code starts every session from zero, wasting tokens and forcing you to repeat architectural constraints. A well-designed setup treats Claude as programmable infrastructure that keeps the context you care about across sessions, so you are not babysitting it by hand.

To stop Claude from forgetting context, you engineer three pillars of memory: storage, injection, and recall. Storage determines how information is written during a session; injection defines what is pushed into the system prompt at start; and recall establishes a framework for recovering long-term facts. Progressive disclosure keeps context lean — you retrieve information only when the task actually needs it.

Cover illustration: Claude Code steered by a stack of memory files — CLAUDE.md, rules, skills and hooks — keeping project context across sessions.

Why you need memory files for Claude

Out-of-the-box memory in Claude Code lags behind current open-source community solutions. Standard behavior is often selective, capturing only what the agent deems "important," which leads to lost decision-making context. A good setup solves this by answering three questions: how information is saved (storage), how it is pushed to the agent (injection), and how it is recovered (recall).

Efficient memory management relies on "frozen snapshots" and "progressive disclosure." Instead of loading tens of thousands of tokens, you provide lean, curated files as snapshots of the current state. Long-term recovery uses a four-tier recall system:

  • Tier 0: Check existing context (e.g., memory.md or daily logs).
  • Tier 1: Semantic match in a local vector database.
  • Tier 2: Metadata expansion for surrounding context.
  • Tier 3: Raw dialogue retrieval for exact transcripts.

This hierarchy lets Claude retrieve meaning — such as "monetization" when you ask about "pricing" — without cluttering the primary context window with raw logs.

The types of Claude memory and steering files

Instructional files follow a strict hierarchy of authority. Global files in ~/.claude/CLAUDE.md apply everywhere, while project-root and subdirectory files provide localized context. Use extreme caution with output styles; these carry the highest weight but will strip critical default engineering instructions — like security checks and test verification — unless you explicitly set keep-coding-instructions: true.

The following table summarizes the primary steering methods:

MethodWhen it's loadedCompaction behaviorContext costWhen to use
CLAUDE.md (root)Session startMemoized; re-read after compactionHighBuild commands, directory layout, team norms
CLAUDE.md (subdir)On-demand (dir touch)Lost until dir touched againLowModule-specific conventions
RulesStart or path-matchRe-injected on compactionMediumSpecific constraints (e.g., API validation)
SkillsName/desc at startOldest dropped first when budget exceededLowProcedural workflows (e.g., deploy checklists)
SubagentsMetadata at startOnly final summary returnsLowIsolated parallel tasks (e.g., security audits)
HooksLifecycle eventsBypass compaction entirelyLowDeterministic automation (e.g., linters)
Output stylesSession startNever compactedHighTotal role changes (e.g., teacher mode)

Diagram of the Claude steering spectrum, from advisory (soft) mechanisms like CLAUDE.md and skills to deterministic (hard) ones like hooks, settings.json and MCP.

Share this article