claude-memory-3layer
Health Pass
- License รขโฌโ License: MIT
- Description รขโฌโ Repository has a description
- Active repo รขโฌโ Last push 0 days ago
- Community trust รขโฌโ 32 GitHub stars
Code Fail
- rm -rf รขโฌโ Recursive force deletion command in install.sh
Permissions Pass
- Permissions รขโฌโ No dangerous permissions requested
No AI report is available for this listing yet.
๐ง Claude Code ไธๅฑ่ฎฐๅฟ็ณป็ป | ็ปๆๅๅญๅจ + ็ๅฝๅจๆ็ฎก็ + Git่ฟฝ่ธช | ๅฎๆนAuto Memory็็ฎก็ๅฑ | ไธ่กๅฝไปคๅฎ่ฃ ้ถไพ่ต
Three-Layer Memory System for Claude Code
Give Claude Code a real memory โ structured, git-trackable, and token-efficient.
This repository has been merged into Kim Service and no longer publishes standalone releases. Please use Kim Service for new versions, installation instructions, and release notes.
:brain: The management layer that official auto-memory doesn't have
:zap: One-command install | Zero dependencies | ~1500 tokens budget
:handshake: Coexists with official auto-memory (v2.1.59+) โ they complement each other
:link: GitHub: https://github.com/KimYx0207/claude-memory-3layer
:telephone_receiver: Contact
Get more AI tips and technical support
:globe_with_meridians: aiking.dev | :bird: @KimYx0207 | WeChat Official Account: ่้ๅธฆไฝ ็ฉAI
:coffee: Buy Me a Coffee
If this project helped you, consider supporting it!
WeChat Pay |
Alipay |
:book: Why This Exists
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.
:dna: Official + Three-Layer: Better 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 | :x: ~/.claude/projects/ (hidden) |
:white_check_mark: .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 | :x: Local only | :white_check_mark: Via git | Three-Layer only |
| Knowledge cleanup | :x: None | :white_check_mark: Auto-suggest via /memory-review |
Three-Layer only |
:sparkles: Core Features
- :brain: Three-Layer Architecture โ Knowledge Graph (JSON) + Daily Notes (MD) + Tacit Knowledge (MD)
- :recycle: 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 - :dart: Token-Efficient โ ~1500 tokens per topic (<1% of 200K context), fully configurable
- :package: Zero Dependencies โ Pure Python stdlib, no pip install needed
- :electric_plug: Hook-Powered โ SessionStart / PostToolUse / PreCompact lifecycle hooks
- :broom: Smart Cleanup โ
/memory-reviewfinds outdated entries and suggests cleanup - :handshake: Coexists with Official โ Works alongside auto-memory and CLAUDE.md
:rocket: Quick Start
One-Line Install
# 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 | iex
Manual Install
git clone https://github.com/KimYx0207/claude-memory-3layer.git
cd claude-memory-3layer
./install.sh # or .\install.ps1 on Windows
What Gets Installed
your-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
:gear: How It Works
Architecture Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Three Layers, Three Purposes
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Layer 1: Knowledge Graph (JSON)
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
Layer 2: Daily Notes (Markdown)
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?")
Layer 3: Tacit Knowledge (Markdown)
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
:wrench: Hook Registration
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"
}
]
}
]
}
}
:hammer_and_wrench: Commands
/memory-review
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
/memory-status
Show memory system statistics โ item counts, date ranges, token estimates.
:control_knobs: Configuration
Environment Variables
| 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) |
Custom Topics
Set MEMORY_TOPICS to define custom keyword-to-topic mappings:
export MEMORY_TOPICS="fastapi:backend,react:frontend,stripe:payments"
:recycle: Lifecycle Management
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.
:chart_with_upwards_trend: Token Budget Analysis
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.
:white_check_mark: Compatibility
- 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
:file_folder: Project Structure
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
:bar_chart: Project Statistics
| 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) |
:busts_in_silhouette: Target Users
- :white_check_mark: Claude Code power users โ Want structured, persistent memory across sessions
- :white_check_mark: Team developers โ Need git-trackable, shared knowledge base
- :white_check_mark: Token-conscious users โ Want precise control over context window usage
- :white_check_mark: Multi-project developers โ Need per-project knowledge management
- :white_check_mark: DIY enthusiasts โ Want full control over what Claude remembers
:handshake: Contributing
Issues and PRs welcome! Please:
- Keep zero-dependency policy (Python stdlib only)
- Test on macOS + Windows
- Follow existing code style
:page_facing_up: License
This project is licensed under the MIT License.
:pray: Acknowledgments
- Anthropic for building Claude Code
- The Claude Code community for feedback and ideas
- Everyone who contributed to the official auto-memory discussion
:bust_in_silhouette: Author
KimYx0207 (่้ / LaojinAI) โ Building tools for Claude Code power users.
:globe_with_meridians: aiking.dev | :bird: @KimYx0207 | WeChat: ่้ๅธฆไฝ ็ฉAI
:memo: Changelog
v1.0.0 (2026-02-27) โ Initial Release
- 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)
Reviews (0)
Sign in to leave a review.
Leave a reviewNo results found