Three-Layer Memory System for Claude Code

Enhance Claude Code's capabilities with a three-layer memory system for cross-session knowledge extraction, storage, and loading, designed for persistent context retention.

16 stars
Complexity: easy

About this skill

This AI Agent Skill addresses the critical challenge of Claude Code's ephemeral memory, where all context is lost between sessions. While official auto-memory features improve knowledge discovery, they often lack crucial lifecycle management, Git tracking for version control, and capabilities for team sharing. This skill provides a robust solution by introducing a management layer that seamlessly complements and extends official auto-memory functionalities. The core of this solution is a sophisticated three-layer memory system, each designed for a distinct purpose. Layer 1 uses JSON to store a knowledge graph, featuring lifecycle management to keep information fresh and automatically loading the last 10 active entries. Layer 2 captures daily notes in Markdown, summarizing 'what happened today' and loading the last 3 days. Layer 3 also uses Markdown, dedicated to 'tacit knowledge' — hard-won experience and insights — which is always fully loaded. Key features include zero dependencies for universal compatibility, automatic knowledge extraction via a PostToolUse hook, and seamless context injection at session start through a SessionStart hook. The system ensures knowledge remains current with lifecycle management, is fully Git-trackable as all files reside within the project directory, and is highly token-efficient, consuming only about 1500 tokens. It's also fully compatible with Claude Code's official auto-memory (v2.1.59+), working in tandem to provide a comprehensive and persistent memory solution.

Best use case

Developers, AI engineers, and power users working on long-term or complex projects within Claude Code will benefit most from this skill. It's ideal for scenarios where maintaining context, remembering past decisions, and accessing accumulated project knowledge across multiple coding sessions is essential. This allows the AI to learn and grow with the project, significantly reducing repetitive prompts and improving the efficiency and accuracy of its assistance.

Enhance Claude Code's capabilities with a three-layer memory system for cross-session knowledge extraction, storage, and loading, designed for persistent context retention.

Claude Code will automatically recall relevant past knowledge, daily notes, and accumulated experience from previous sessions, leading to more efficient and context-aware coding assistance without manual intervention.

Practical example

Example input

I'm resuming development on the `UserAuthenticationService`. We discussed a specific approach for token refresh last week. Can you outline that approach and help me implement the `refresh_token` endpoint?

Example output

Based on our previous discussions captured in your knowledge graph and daily notes, we decided on a rotating refresh token strategy with a 24-hour validity and immediate invalidation of the old token upon successful refresh. I've loaded the relevant context. Here's a Python skeleton for the `refresh_token` endpoint and an explanation of the design considerations we noted...

When to use this skill

  • When working on long-running or multi-session coding projects with Claude Code.
  • When you need Claude Code to consistently remember past discussions, decisions, and code snippets.
  • When you want to track Claude Code's learned knowledge and project context using Git.
  • When collaborating in a team environment where shared, persistent knowledge for Claude Code is beneficial.

When not to use this skill

  • If you do not use Claude Code or are using an unsupported version (older than 2.1.0).
  • For extremely short, one-off coding tasks where session persistence is not required.
  • If you strictly prefer manual memory management and explicit context provision in every session.

How Three-Layer Memory System for Claude Code Compares

Feature / AgentThree-Layer Memory System for Claude CodeStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

Enhance Claude Code's capabilities with a three-layer memory system for cross-session knowledge extraction, storage, and loading, designed for persistent context retention.

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as easy. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Three-Layer Memory System for Claude Code

A cross-session memory system that automatically extracts, stores, and loads knowledge across Claude Code sessions.

## Metadata

```yaml
name: claude-memory-3layer
version: 1.0.0
description: Three-layer memory system — knowledge graph + daily notes + tacit knowledge
author: LaojinAI
license: MIT
min_claude_code_version: 2.1.0
context: fork
```

## Trigger Words

- memory system
- three layer memory
- 三层记忆
- cross session memory
- 跨会话记忆

## What It Does

### The Problem
Claude Code forgets everything between sessions. Official CLAUDE.md requires manual maintenance. Official auto-memory (v2.1.59+) brilliantly solves knowledge discovery, but lacks lifecycle management, git tracking, and team sharing.

### The Solution
A management layer that complements official auto-memory. Three specialized memory layers, each serving a different purpose:

| Layer | Format | Purpose | Auto-loaded |
|-------|--------|---------|-------------|
| Layer 1 | JSON | Knowledge graph with lifecycle management | ✅ Last 10 active |
| Layer 2 | Markdown | Daily notes (what happened today) | ✅ Last 3 days |
| Layer 3 | Markdown | Tacit knowledge (hard-won experience) | ✅ Full file |

### Key Features
- **Zero dependencies** — Pure Python stdlib, works everywhere
- **Auto-extract** — PostToolUse hook captures knowledge automatically
- **Auto-load** — SessionStart hook injects context seamlessly
- **Lifecycle management** — `status` field (active/superseded) keeps knowledge fresh
- **Git-trackable** — All files in project directory, not hidden in `~/.claude/`
- **Token-efficient** — ~1500 tokens budget, <1% of 200K context window
- **Compatible** — Works alongside official auto-memory (v2.1.59+)

## Installation

```bash
# One-line install (Unix/macOS)
curl -fsSL https://raw.githubusercontent.com/KimYx0207/claude-memory-3layer/main/install.sh | bash

# Windows PowerShell
irm https://raw.githubusercontent.com/KimYx0207/claude-memory-3layer/main/install.ps1 | iex

# Manual install
git clone https://github.com/KimYx0207/claude-memory-3layer.git
cd claude-memory-3layer && ./install.sh
```

## Commands

| Command | Description |
|---------|-------------|
| `/memory-review` | Review recent memories, extract patterns, suggest permanent rules |
| `/memory-status` | Show memory system status and statistics |

## File Structure

```
.claude/
├── hooks/
│   ├── memory_loader.py      # SessionStart: load three layers
│   ├── memory_extractor.py   # PostToolUse: extract knowledge
│   ├── session_state.py      # Session lifecycle management
│   └── pre_compact.py        # PreCompact: save before compression
├── memory/
│   ├── MEMORY.md             # Layer 3: tacit knowledge
│   ├── memory/               # Layer 2: daily notes
│   │   └── YYYY-MM-DD.md
│   └── areas/                # Layer 1: knowledge graph
│       └── topics/
│           └── <topic>/
│               └── items.json
└── commands/
    ├── memory-review.md      # /memory-review command
    └── memory-status.md      # /memory-status command
```

Related Skills

Claude-Zeroclaw SKILL

109
from Crestdrasnip/Claude-Zeroclaw

## Overview

Workflow & ProductivityClaude

Claude Skill Development Guide

12
from rootvc/claude-apply-skill

This guide explains the architecture of Claude AI agent skills, demonstrating how to extend Claude CLI capabilities with new, modular actions like direct job applications.

Workflow & ProductivityClaude

ai-pair

169
from axtonliu/ai-pair

AI Pair Collaboration Skill. Coordinate multiple AI models to work together: one creates (Author/Developer), two others review (Codex + Gemini). Works for code, articles, video scripts, and any creative task. Trigger: /ai-pair, ai pair, dev-team, content-team, team-stop

Workflow & ProductivityClaude

review

167
from ArtemXTech/claude-code-obsidian-starter

Daily and weekly review workflows. USE WHEN user says "morning routine", "evening routine", "weekly review", "start my day", "end of day".

Workflow & ProductivityClaude

Beads Issue Tracking Skill

164
from maslennikov-ig/claude-code-orchestrator-kit

> **Attribution**: [Beads](https://github.com/steveyegge/beads) by [Steve Yegge](https://github.com/steveyegge)

Workflow & ProductivityClaude

prd

160
from react-native-vibe-code/react-native-vibe-code-sdk

Generate a Product Requirements Document (PRD) for a new feature. Use when planning a feature, starting a new project, or when asked to create a PRD. Triggers on: create a prd, write prd for, plan this feature, requirements for, spec out.

Workflow & ProductivityClaude

Skill: Runs

154
from ai-analyst-lab/ai-analyst

## Purpose

Workflow & ProductivityClaude

reprompter

97
from AytuncYildizli/reprompter

Transform messy prompts into structured, effective prompts — single, multi-agent, or reverse-engineered from great outputs. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags, "reprompter teams", "repromptverse", "run with quality", "smart run", "smart agents", "campaign swarm", "engineering swarm", "ops swarm", "research swarm", multi-agent tasks, audits, parallel work, "reverse reprompt", "reprompt from example", "learn from this", "extract prompt from", "prompt dna", "prompt genome", reverse-engineering prompts from exemplar outputs. Don't use for simple Q&A, pure chat, or immediate execution-only tasks (see "Don't Use When" section). Outputs: structured XML/Markdown prompt, before/after quality score, optional team brief + per-agent sub-prompts, Agent Cards, Extraction Card (reverse mode). Target quality score: Single ≥ 7/10; Repromptverse per-agent ≥ 8/10; Reverse ≥ 7/10.

Workflow & ProductivityClaudeCodex

session-pack

89
from ten-builder/ten-builder

세션 종료 시 Memory, Handoff를 자동 정리. /pack

Workflow & ProductivityClaude

execute

51
from vinzenz/prd-breakdown-execute

Main entry point for hierarchical task execution. Orchestrates layer-by-layer implementation of PRD tasks with parallel worktree execution.

Workflow & ProductivityClaude

textum

43
from snakeying/Textum

Textum PRD→Scaffold→Story workflow for Codex with low-noise outputs and gate checks.

Workflow & ProductivityClaude

sdd

40
from SpillwaveSolutions/agent_rulez

This skill should be used when users want guidance on Spec-Driven Development methodology using GitHub's Spec-Kit. Guide users through executable specification workflows for both new projects (greenfield) and existing codebases (brownfield). After any SDD command generates artifacts, automatically provide structured 10-point summaries with feature status tracking, enabling natural language feature management and keeping users engaged throughout the process.

Workflow & ProductivityClaude