Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Claude Code Memory System: Progressive Loading & Bidirectional Markdown Knowledge Graph

This article dissects Claude Code's memory system, revealing how it uses Markdown files with progressive loading, bidirectional links, and typed memory categories to create a project-isolated knowledge graph that loads indexes at session start and recalls full memories on demand with timestamps.

Reading hint: This dissection of Claude's memory mechanism is based on direct inspection of Claude Code runtime memory files and personal practical experience, supplemented by prompt techniques to extract context information. It is not a source-code analysis of the Harness layer. Treat it as a set of notes shared for discussion.

Credibility Markers

✅ — Supported by file structure and runtime evidence; safe to cite.

🔶 — Reasonable inference from evidence, but no direct documentation confirmation.

❓ — Internal Harness implementation detail; completely unobservable.

One observation: In Claude's memory system, deciding whether to record is almost certainly done by the model itself, while where to store, how to read, and adding timestamps are infrastructure handled by the Harness. Separating these two concerns avoids confusion.

Core Idea: Treat Memory Like a Code Repository

Claude Code's memory is not a mysterious blob in a SQLite database. It is a stack of Markdown files on your disk, readable with any text editor. It follows a few simple principles:

One file per memory. Each memory lives in its own .md file; edits and deletions are isolated.

Index and content are separate. MEMORY.md holds one line per memory pointing to the content file. At session start only the index is loaded; content is read on demand.

Every memory must explain "what, why, how". Not just a chronological log.

Recall includes a timestamp warning. The system tells you "This is a snapshot from N days ago; verify before use."

Project memories are isolated. Isolation is by working-directory path.

Where Files Live

✅ Confirmed location:

<your-user-dir>\.claude\projects\<project-key>\memory\
Directory screenshot
Directory screenshot

Only two kinds of files exist: MEMORY.md — the index, one line per memory. Every new session injects this entire file into context.

All other .md files — individual memory content. Loaded only when needed.

.claude/projects/
├── [Project A]/
│   └── memory/
│       ├── MEMORY.md          ← index, always resident
│       ├── user-profile.md
│       ├── feedback-code-style.md
│       └── ...
└── [Project B]/
    └── memory/
        └── ...

Project Isolation

✅ Confirmed: Isolation uses the absolute working-directory path. The path string is sanitized: non-alphanumeric characters are replaced with -, producing the "project key".

Sanitization example
Sanitization example

Example (fictional path):

Working dir:  C:\Dev\Sample_App\core_lib
               │  │       │       │
               ▼  ▼       ▼       ▼
Project key:  C--Dev-Sample-App-core-lib

🔶 The replacement rule was reverse-engineered from real files; characters : \ _ are confirmed to become -. Other special characters not individually verified.

❓ No evidence of a cross-project "global memory" layer observed.

Four Memory Types

✅ Every memory must belong to one of four types:

user — Who you are: role, expertise, preferences. No extra requirement.

feedback — Your work guidance (corrections, confirmed practices). Must include Why and How to apply.

project — Ongoing goals, constraints (not inferable from code or git). Relative dates must be converted to absolute dates.

reference — External resource links: URLs, boards, ticket numbers. No extra requirement.

✅ Explicitly not to be put in memory:

Code structure, bug-fix history, git logs, anything already in CLAUDE.md.

Information only useful in the current conversation, no cross-session value.

If you ask the model to record the above, it will push back: "What is the non-obvious point here?" — and only record that.

Anatomy of a Memory File

A typical feedback memory (abstracted from real files):

---
name: feedback-code-style
description: "Prefer composition over inheritance here; run the linter before commit"
metadata:
  node_type: memory
  type: feedback
  originSessionId: <session UUID>
  modified: <ISO-8601 timestamp>
---

Body content…
**Why:** Reduce coupling, enable isolated testing.
**How to apply:** Run lint and unit tests before every commit.
See also [[user-profile]]

Field provenance: name, description, type, body, [[links]] — ✅ Written by the model. node_type, originSessionId, modified — 🔶 Appear to be auto-populated by Harness at save time (precise timestamp and session UUID). The concise spec docs don't require the model to write these.

Interesting detail: Actual files contain more metadata fields than the concise spec lists. The spec only mentions type , but real files consistently include node_type , originSessionId , modified . This shows "model-written semantic fields" and "system-maintained infrastructure fields" are two separate layers.

Index line format in MEMORY.md ✅:

- [Title](filename.md) — one-sentence hook

When Memories Are Written

Current assessment: No automatic trigger is configured. Whether to write, and when, is decided by the model during conversation — not event-driven, not a background daemon.
Write trigger diagram
Write trigger diagram

Inferred flow:

Information surfaces in conversation.

Model judges: cross-session value? → If no, skip.

If yes: already in code/git/CLAUDE.md? → If yes, skip.

If not: existing memory covers it? → Update if yes, create new if no.

Either way, sync the index line in MEMORY.md.

Practical verification: To guarantee the model remembers something, explicitly say "Remember …". Otherwise recording is entirely at the model's discretion. Direct refusal can also block a write.

How Memories Are Recalled

✅ Two-layer mechanism:

Layer 1: Session start — always happens MEMORY.md index is fully injected into context. Every new conversation, the model knows "which memories are available to look up".

Layer 2: During conversation — on demand

Harness likely uses the description field to judge relevance to the current topic. Relevant memories have their full content injected via system-reminder, accompanied by a freshness warning: "This is a snapshot from N days ago, involves file:line, verify before use."

The model can also proactively Read or Grep the memory directory, independent of Harness auto-push.

MEMORY.md index — Every session start, always loaded (full text into context)

Individual memory body — On demand , only when relevant (not loaded at session start)

❓ The exact recall algorithm (semantic similarity? keyword scoring?) is internal Harness implementation and unobservable.

Maintenance Lifecycle

Deduplication on write — Check for same-name file first; update instead of creating duplicates.

Delete on error — If a memory is wrong, delete the file.

Common pattern: Body contains a paragraph like "CORRECTED … supersedes my earlier belief" — the model self-corrects in later sessions, overwriting the old understanding.

Bidirectional links — Use [[name]] to connect memories into a knowledge graph; this is genuinely powerful.

Freshness guardrails — Every recall carries an "N days ago / timestamp / verify first" warning.

consolidate-memory skill — A manually triggered cleanup tool that scans the entire memory store, merges duplicates, corrects stale content, and prunes the index.

Maintenance diagram
Maintenance diagram

Tooling: No Dedicated API

✅ Memory operations use only generic file tools ; there is no "memory-specific interface":

Create — Write (write .md, then update MEMORY.md index)

Find — Read / Glob / Grep (read or search memory directory)

Modify — Edit (partial) / Write (full rewrite); prefer updating existing file

Delete — Shell ( Remove-Item / rm); only when memory is confirmed wrong

The memory\ directory already exists; no manual mkdir needed.

Why This Design Works

File-based, pure Markdown — Can be git managed, diffable, human-readable.

One memory per file — Edit, delete, link without side effects.

Resident index + on-demand body — Saves tokens — doesn't stuff entire knowledge base into every prompt.

Recall driven by description — Summary matching is more precise than full-text matching.

Freshness guardrails — Mechanically prevents stale info from being treated as fact.

Typed + Why/How — Records actionable guidance, not diaries.

Bidirectional links — Memories form a graph, not isolated islands.

Project isolation — Multiple projects stay clean.

Self-correction — Later evidence can overturn earlier beliefs.

Open Questions

❓ Recall algorithm internals completely invisible.

🔶 node_type, originSessionId, modified are inferred as Harness-auto-written; not directly confirmed.

🔶 Path sanitization rule reverse-engineered from samples; not all special characters covered.

❓ Existence of a global (cross-project) memory layer — no evidence found.

✅ No auto-write trigger — fully model-judged, so possible omissions or over-recording. "Explicitly say 'remember'" is most reliable.

Appendix: Generalized Samples from Real MEMORY Files

Below are fictional demo data, not from any real project.

Index MEMORY.md :

# Memory Index
- [User profile](user-profile.md) — User role and preferences
- [Code style guidance](feedback-code-style.md) — Coding conventions and pre-commit checks

Memory user-profile.md (type: user):

---
name: user-profile
description: User is a backend engineer who prefers explicit error handling and thorough unit testing
metadata:
  node_type: memory
  type: user
  originSessionId: <session UUID>
  modified: <ISO-8601 timestamp>
---

User is a backend engineer responsible for server-side modules…

Memory feedback-code-style.md (type: feedback):

---
name: feedback-code-style
description: "This project prefers composition over inheritance; must run lint and tests before commit"
metadata:
  node_type: memory
  type: feedback
  originSessionId: <session UUID>
  modified: <ISO-8601 timestamp>
---

In this project prefer composition over inheritance…
**Why:** Reduce coupling, ease testing.
**How to apply:** Run lint and unit tests before every commit. See also [[user-profile]]
About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

AI AgentKnowledge GraphMarkdownContext ManagementClaude Codememory systemprogressive loadingbidirectional links

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion