Skip to main content
Advanced

Persistent memory across Claude Code sessions

  • Guide
  • Tooling

How to keep context from one Claude Code session to the next: claude-mem, graphify, SessionStart hooks, hierarchical CLAUDE.md patterns. Compare 4 approaches and when to pick which.

TL;DR

  • Claude Code has no native memory between two distinct sessions. At every startup, it forgets everything.
  • 4 dominant patterns fill this gap: hierarchical CLAUDE.md (native, simplest), SessionStart hooks (native, scriptable), claude-mem (community skill, capture-compress-replay), graphify (queryable knowledge graph).
  • Choose by need: stable project → CLAUDE.md. Session-to-session continuity → claude-mem. Massive codebase to explore → graphify. Custom per-project setup → SessionStart hook.
  • Combining patterns works very well: e.g. CLAUDE.md for project conventions + claude-mem for session history.

The problem

A new Claude Code session starts from scratch. No memory of:

  • What you've already tried (and what didn't work)
  • Conventions discovered while exploring in the previous session
  • Client/project context explained in a previous session
  • Architecture choices validated together

Consequence: you re-explain the same things, Claude re-explores the same files, you re-pay the tokens. On a multi-week project, this is the #1 source of waste.

Pattern 1: Hierarchical CLAUDE.md (native)

The simplest, and often sufficient. Claude Code automatically loads CLAUDE.md files at 3 levels:

  1. ~/.claude/CLAUDE.md — global instructions (all sessions)
  2. <project>/CLAUDE.md — project instructions (loaded when cwd is inside)
  3. <sub-folder>/CLAUDE.md — descendant instructions (loaded when cwd goes into the sub-folder)

This is structural memory: conventions, architecture, business constraints, user profile. See /prompting/claude-md for full syntax.

When to use: all the time. It's the foundation. All other patterns complement it.

Pattern 2: SessionStart hooks (native)

Since late 2025, Claude Code exposes a SessionStart hook that runs at every startup. It can:

  • Read a previous state file and inject it into the session
  • Run a recent git log and summarize what moved
  • Ping an internal API to retrieve project context
  • Launch a script that queries a knowledge graph

See /advanced/hooks for the config.

When to use: you want a scripted per-project setup (for example: "on every start, read the latest Linear sprint"). Doesn't replace CLAUDE.md but complements it.

Pattern 3: claude-mem (community skill)

thedotmack/claude-mem (ouvre un nouvel onglet) (74,832 ★ as of 2026-05-11). The dominant pattern for session-to-session memory.

How it works:

  1. During your session, the skill captures messages, edited files, executed commands.
  2. At the end, it AI-compresses everything into a structured summary (10-30 lines max).
  3. At the next startup, it injects the summary into the initial context.

Compatibility: Claude Code, OpenClaw, Codex, Gemini CLI, Hermes, Copilot, OpenCode, and more.

When to use: medium-duration project (weeks/months) with frequent sessions. You want Claude to remember what it did last time, not just what it should do (which is in CLAUDE.md).

Pattern 4: graphify (knowledge graph)

safishamsi/graphify (ouvre un nouvel onglet) (46,647 ★ as of 2026-05-11). Not a session memory tool but a codebase memory tool.

How it works:

  1. You point graphify at a folder (code, SQL, scripts, docs, papers, images, videos).
  2. It builds a typed, queryable knowledge graph.
  3. During the Claude session, the skill exposes queries to inspect the graph (e.g., "give me all the places where function X is called").

When to use: massive codebase (> 100k lines) where plain grep becomes slow and imprecise. Especially useful on heterogeneous infra (app code + database schema + Terraform in a single graph).

Express comparison

PatternCoversInit effortToken cost
CLAUDE.mdConventions, archi, constraintsVery low (markdown)Very low
SessionStart hookCustom scripted setupMedium (a script)Variable
claude-memSession-to-session historyLow (skill install)Moderate (compression)
graphifyMassive codebase navigationHigh (graph build)Low per query

When to combine

Recommended combo pattern for a serious project:

  1. Project CLAUDE.md + descendants → foundation
  2. Personal global CLAUDE.md → cross-project preferences (code style, language, etc.)
  3. claude-mem active on this project → session history
  4. SessionStart hook running git log --since="last week" and summarizing → recent context
  5. (Optional, large project) graphify initialized for deep queries

Next steps