🧠 Claude-Mem:75K stars · AI Agent 的持久化记忆层,跨会话上下文永不丢失
中文 / English
AI 代理现在有了长期记忆。Claude-Mem 是一个持久化记忆压缩系统,专为 Claude Code、Gemini CLI、OpenClaw 等 AI 编码代理设计。它自动捕获会话期间的上下文,压缩为语义摘要,并在未来会话中注入相关信息——无需手动干预。
为什么需要这个?
用过 Claude Code 或 Gemini CLI 的人都知道,每次新会话都是从头开始。代理不记得你昨天做了什么、修了什么 bug、项目的架构决策是什么。Claude-Mem 解决的就是这个问题——它给 AI 代理装上一个「大脑」,让记忆跨会话延续。
快速开始
一条命令安装:
npx claude-mem install
为 Gemini CLI 安装(自动检测 ~/.gemini):
npx claude-mem install --ide gemini-cli
从 Claude Code 插件市场安装:
/plugin marketplace add thedotmack/claude-mem
/plugin install claude-mem
重启 Claude Code 后,上一会话的上下文会自动出现在新会话中。
核心工作原理
Claude-Mem 由 5 个生命周期钩子驱动:
2. UserPromptSubmit — 用户提交 prompt 时记录
3. PostToolUse — 工具调用后捕获观察结果
4. Stop — 停止时压缩当前上下文
5. SessionEnd — 会话结束时生成语义摘要并存入数据库
数据存储在 SQLite + Chroma 向量数据库中,支持混合检索(全文搜索 + 语义搜索)。
MCP 搜索工具:三层渐进式检索
Claude-Mem 提供 4 个 MCP 工具,采用 token 高效的 3 层工作流:
// 第 1 层:搜索索引(~50-100 tokens/结果)
search(query="authentication bug", type="bugfix", limit=10)
// 第 2 层:查看时间线
timeline(observationId=123)
// 第 3 层:获取完整详情(~500-1000 tokens/结果)
get_observations(ids=[123, 456])
这种渐进式披露(Progressive Disclosure)的设计,让 Claude 先看轻量索引,再决定是否获取完整详情——大约节省 10 倍 token 消耗。
关键特性
http://localhost:37777 标签排除敏感内容配置
在 ~/.claude-mem/settings.json 中配置:
{
"CLAUDE_MEM_MODE": "code--zh"
}
支持多语言模式,如 code--zh(中文)、code--ja(日语)等。
这个项目 2025 年 5 月才发布,一年内涨到 75K stars,是 AI 编码代理生态中最快的记忆层项目之一。如果你在用 Claude Code 或 Gemini CLI,这可能是你今年装的最值的插件。
🧠 Claude-Mem: 75K stars · Persistent Memory Layer for AI Agents
AI agents now have long-term memory. Claude-Mem is a persistent memory compression system built for Claude Code, Gemini CLI, OpenClaw, and other AI coding agents. It automatically captures session context, compresses it into semantic summaries, and injects relevant context into future sessions — no manual intervention required.
Why This Exists
Anyone who uses Claude Code or Gemini CLI knows the pain: every new session starts from zero. The agent doesn't remember what you worked on yesterday, what bugs you fixed, or the architectural decisions made. Claude-Mem solves this by giving AI agents a persistent brain that spans sessions.
Quick Start
Install with a single command:
npx claude-mem install
Install for Gemini CLI (auto-detects ~/.gemini):
npx claude-mem install --ide gemini-cli
Install from Claude Code plugin marketplace:
/plugin marketplace add thedotmack/claude-mem
/plugin install claude-mem
Restart Claude Code — context from previous sessions automatically appears in new ones.
How It Works
Claude-Mem is driven by 5 lifecycle hooks:
2. UserPromptSubmit — Records user prompts
3. PostToolUse — Captures observations after tool calls
4. Stop — Compresses current context on pause
5. SessionEnd — Generates semantic summaries, stores to database
Data lives in SQLite + Chroma vector database with hybrid retrieval (full-text + semantic search).
MCP Search: 3-Layer Progressive Disclosure
Four MCP tools with a token-efficient workflow:
// Layer 1: Search index (~50-100 tokens/result)
search(query="authentication bug", type="bugfix", limit=10)
// Layer 2: Timeline view
timeline(observationId=123)
// Layer 3: Full details (~500-1000 tokens/result)
get_observations(ids=[123, 456])
This progressive disclosure design lets Claude browse lightweight indexes first, then fetch details only for relevant items — saving ~10x token consumption.
Key Features
http://localhost:37777 tags to exclude sensitive contentConfiguration
Edit ~/.claude-mem/settings.json:
{
"CLAUDE_MEM_MODE": "code--en"
}
Supports multilingual modes: code--en (English), code--zh (Chinese), code--ja (Japanese), and more.
Released in May 2025, this project hit 75K stars in its first year — making it one of the fastest-growing memory layer projects in the AI coding agent ecosystem. If you use Claude Code or Gemini CLI daily, this might be the most valuable plugin you install all year.
Built with Claude Agent SDK | Works with Claude Code | Made with TypeScript