๐ง The management layer that official auto-memory doesn't have
โก One-command install | Zero dependencies | ~1500 tokens budget
๐ค Coexists with official auto-memory (v2.1.59+) โ they complement each other
๐ GitHub: https://github.com/KimYx0207/claude-memory-3layer
Get more AI tips and technical support
๐ aiking.dev | ๐ฆ @KimYx0207 | WeChat Official Account: ่้ๅธฆไฝ ็ฉAI
Claude Code forgets everything between sessions. Anthropic provides two solutions:
- CLAUDE.md โ manual rules file, you write and maintain it
- Auto-memory (v2.1.59+) โ AI-powered, Claude decides what to remember
Official auto-memory solves knowledge discovery brilliantly. But discovery is only half the problem.
The other half โ lifecycle management, git tracking, team sharing, precise token control โ is what this project handles.
This is not a replacement. It's the management layer that official auto-memory doesn't have. Use both together.
| Dimension | Official v2.1.59 | Three-Layer Memory | Best for |
|---|---|---|---|
| Knowledge discovery | AI semantic understanding | Keyword matching (rules) | Official wins |
| Install cost | Zero config | One command | Official wins |
| Storage format | Markdown (flat text + topic files) | 3 layers (JSON + MD + MD) | Three-Layer more flexible |
| Git tracking | โ ~/.claude/projects/ (hidden) |
โ
.claude/memory/ (in project) |
Three-Layer only |
| Lifecycle | Write-only, grows forever | status field (active/superseded) |
Three-Layer only |
| Token control | Truncate at 200 lines (unknown tokens) | ~1500 tokens per topic (configurable) | Three-Layer more predictable |
| Team sharing | โ Local only | โ Via git | Three-Layer only |
| Knowledge cleanup | โ None | โ
Auto-suggest via /memory-review |
Three-Layer only |
- ๐ง Three-Layer Architecture โ Knowledge Graph (JSON) + Daily Notes (MD) + Tacit Knowledge (MD)
- โป๏ธ Lifecycle Management โ Facts can expire (
activeโsuperseded), keeps knowledge lean - :git: Git-Trackable โ All memory lives in
.claude/memory/, commit and share with your team - ๐ฏ Token-Efficient โ ~1500 tokens per topic (<1% of 200K context), fully configurable
- ๐ฆ Zero Dependencies โ Pure Python stdlib, no pip install needed
- ๐ Hook-Powered โ SessionStart / PostToolUse / PreCompact lifecycle hooks
- ๐งน Smart Cleanup โ
/memory-reviewfinds outdated entries and suggests cleanup - ๐ค Coexists with Official โ Works alongside auto-memory and CLAUDE.md
# macOS / Linux
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 | iexgit clone https://github.com/KimYx0207/claude-memory-3layer.git
cd claude-memory-3layer
./install.sh # or .\install.ps1 on Windowsyour-project/
โโโ .claude/
โโโ hooks/
โ โโโ memory_loader.py # SessionStart: load 3 layers
โ โโโ memory_extractor.py # PostToolUse: extract knowledge
โ โโโ session_state.py # State management
โ โโโ pre_compact.py # PreCompact: save before compression
โโโ memory/
โ โโโ MEMORY.md # Layer 3: tacit knowledge
โ โโโ memory/ # Layer 2: daily notes
โ โโโ areas/topics/ # Layer 1: knowledge graph
โโโ commands/
โ โโโ memory-review.md # /memory-review command
โ โโโ memory-status.md # /memory-status command
โโโ settings.json # Hook registration
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Claude Code Session โ
โ โ
โ SessionStart โโโ memory_loader.py โโโ Load 3 layers โ
โ โ โ โ
โ โผ โผ โ
โ [Context injected with ~1500 tokens of memory] โ
โ โ
โ ... working ... โ
โ โ
โ PostToolUse โโโ memory_extractor.py โโโ Save to L1 + L2 โ
โ โ โ
โ PreCompact โโโ pre_compact.py โโโ Save session state โ
โ โ โ
โ (State auto-persisted via PreCompact for next session) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Session Start โ
โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Layer 1 โ โ Layer 2 โ โ Layer 3 โ โ
โ โ JSON โ โ Markdown โ โ Markdown โ โ
โ โ โ โ โ โ โ โ
โ โ Knowledge โ โ Daily โ โ Tacit โ โ
โ โ Graph โ โ Notes โ โ Knowledge โ โ
โ โ โ โ โ โ โ โ
โ โ Last 10 โ โ Last 3 โ โ Full file โ โ
โ โ active โ โ days โ โ โ โ
โ โ per topic โ โ โ โ โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ โ
โ โ โ
โ ~1500 tokens per topic โ
โ (<1% of 200K context) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Structured facts with lifecycle management.
{
"id": "fact-20260227143022",
"fact": "Use pnpm instead of npm for this project",
"timestamp": "2026-02-27",
"status": "active"
}- Stored in
.claude/memory/areas/topics/<topic>/items.json - Each fact has a
statusfield:activeorsuperseded - Only
activeitems are loaded at session start - Auto-extracted by PostToolUse hook
What happened today โ auto-appended, never edited.
# 2026-02-27
## 14:30
Refactored auth module to use JWT instead of sessions
Topics: authentication, refactoring
## 16:45
Fixed N+1 query in user list endpoint
Topics: performance, postgres- Stored in
.claude/memory/memory/YYYY-MM-DD.md - Last 3 days loaded at session start
- Provides temporal context ("what was I doing yesterday?")
Hard-won experience that can't be auto-extracted.
## Architecture Decisions
- Chose FastAPI over Flask for async support
## Gotchas & Pitfalls
- Redis connection pool must be closed explicitly on shutdown
- Never use `datetime.now()` in tests, always mock it
## Tool Preferences
- Use ruff instead of flake8+black- Stored in
.claude/memory/MEMORY.md - Manually maintained (similar to official CLAUDE.md)
- Full file loaded at session start
The installer auto-registers hooks in .claude/settings.json. If you need to add them manually:
{
"hooks": {
"SessionStart": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python .claude/hooks/memory_loader.py"
}
]
}
],
"PostToolUse": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python .claude/hooks/memory_extractor.py"
}
]
}
],
"PreCompact": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python .claude/hooks/pre_compact.py"
}
]
}
]
}
}Periodic knowledge hygiene โ find patterns worth promoting, and outdated entries worth cleaning up.
- Scans all 3 layers for recurring patterns (high-frequency, trending, decaying)
- Suggests promoting patterns to
CLAUDE.mdas permanent rules - Suggests marking outdated entries as
superseded - Both "add" and "remove" โ keeps your knowledge base lean
Show memory system statistics โ item counts, date ranges, token estimates.
| Variable | Default | Description |
|---|---|---|
MEMORY_DIR |
.claude/memory/ |
Override memory directory path |
MEMORY_MAX_ITEMS |
10 |
Max active items loaded per topic |
MEMORY_DAILY_DAYS |
3 |
Days of daily notes to load |
MEMORY_TOPICS |
(auto-detect) | Custom topic mapping (key:topic,key:topic) |
Set MEMORY_TOPICS to define custom keyword-to-topic mappings:
export MEMORY_TOPICS="fastapi:backend,react:frontend,stripe:payments"The key feature official auto-memory doesn't have: knowledge can expire.
Active โโโโโโโโ Used normally, loaded at session start
โ
โผ
Superseded โโโโ Outdated, NOT loaded, kept for reference
To mark a fact as outdated, change its status in items.json:
{
"id": "fact-20260101",
"fact": "Use Flask for the API server",
"status": "superseded"
}Or use /memory-review to auto-detect and clean up outdated entries.
The system is designed to stay under ~1500 tokens at session start (single topic):
| Component | Estimated Tokens |
|---|---|
| Layer 3 (MEMORY.md, typical) | ~300 |
| Layer 2 (3 days x ~3 entries) | ~400 |
| Layer 1 (10 facts per topic x ~15 words) | ~600 |
| Headers and formatting | ~100 |
| Total (single topic) | ~1400 |
Multiple topics scale linearly. Configure via MEMORY_MAX_ITEMS env var.
This is <1% of Claude's 200K context window.
- Claude Code: v2.1.0+ (hooks support required)
- Python: 3.8+ (stdlib only, zero dependencies)
- OS: macOS, Linux, Windows
- Coexists with: Official auto-memory (v2.1.59+), CLAUDE.md
claude-memory-3layer/
โโโ SKILL.md # Claude Code Skill manifest
โโโ README.md # English documentation
โโโ README_CN.md # Chinese documentation
โโโ LICENSE # MIT
โโโ install.sh # Unix/macOS installer
โโโ install.ps1 # Windows installer
โโโ images/ # Images and QR codes
โโโ hooks/
โ โโโ memory_loader.py # SessionStart: load 3 layers
โ โโโ memory_extractor.py # PostToolUse: extract knowledge
โ โโโ session_state.py # Session lifecycle state
โ โโโ pre_compact.py # PreCompact: save before compression
โโโ commands/
โ โโโ memory-review.md # /memory-review command
โ โโโ memory-status.md # /memory-status command
โโโ templates/
โ โโโ MEMORY.md # Layer 3 template
โ โโโ items.json # Layer 1 template
โโโ docs/
โโโ quickstart.md # Getting started guide
โโโ architecture.md # System architecture deep-dive
โโโ vs-official.md # Detailed comparison with official
| Metric | Value |
|---|---|
| Hook Scripts | 3 (SessionStart, PostToolUse, PreCompact) + 1 utility (session_state) |
| Memory Layers | 3 (Knowledge Graph + Daily Notes + Tacit Knowledge) |
| Commands | 2 (/memory-review, /memory-status) |
| Dependencies | 0 (pure Python stdlib) |
| Token Budget | ~1500 per topic (configurable) |
| Python Version | 3.8+ |
| Claude Code Version | v2.1.0+ (tested on v2.1.59) |
- โ Claude Code power users โ Want structured, persistent memory across sessions
- โ Team developers โ Need git-trackable, shared knowledge base
- โ Token-conscious users โ Want precise control over context window usage
- โ Multi-project developers โ Need per-project knowledge management
- โ DIY enthusiasts โ Want full control over what Claude remembers
Issues and PRs welcome! Please:
- Keep zero-dependency policy (Python stdlib only)
- Test on macOS + Windows
- Follow existing code style
This project is licensed under the MIT License.
- Anthropic for building Claude Code
- The Claude Code community for feedback and ideas
- Everyone who contributed to the official auto-memory discussion
KimYx0207 (่้ / LaojinAI) โ Building tools for Claude Code power users.
๐ aiking.dev | ๐ฆ @KimYx0207 | WeChat: ่้ๅธฆไฝ ็ฉAI
- Three-layer memory architecture (Knowledge Graph + Daily Notes + Tacit Knowledge)
- 3 lifecycle hooks (SessionStart, PostToolUse, PreCompact) + 1 utility module (session_state)
- One-command installer for macOS/Linux/Windows
/memory-reviewand/memory-statuscommands- Complementary design with official auto-memory (v2.1.59+)
- Zero dependencies (pure Python stdlib)
- Full documentation (quickstart, architecture, comparison)

