Glean 拾遗
日刊 /2026-07-19 / 持久化 AI 记忆压缩系统,赋予编码智能体跨会话上下文

持久化 AI 记忆压缩系统,赋予编码智能体跨会话上下文

原文 github.com 收录 2026-07-19 06:01 阅读 11 min
AI 解读

Claude-Mem 是一个专为 Claude Code 等编码智能体设计的长期记忆插件。它解决的核心问题是 AI 辅助编程时的上下文遗忘:智能体会话结束后便丢失对项目的一切了解。claude-mem 通过自动捕获智能体在会话中的所有操作,利用 AI 生成结构化语义摘要并存入 SQLite 数据库,在未来的会话中智能地将相关记忆注入上下文,从而实现跨会话的项目知识连续性。项目采用渐进式记忆检索,仅在需要时按层级加载详细记忆,显著节省 token 成本。内置 Web 界面可实时查看记忆流,并通过 MCP 工具提供自然语言搜索历史操作的能力。适合所有重度使用 Claude Code 并期望其能“记住”项目历史的一线开发者。

原文 11 分钟
原文 github.com ↗
§ 1

Claude-Mem is a persistent memory compression system built specifically for Claude Code. It automatically captures tool-use observations across sessions, generates semantic summaries, and injects them into future conversations. This allows your AI coding agent to remember project context, decisions, and debugging history even after a session ends or reconnects.

Claude-Mem 是一个专为 Claude Code 设计的持久化记忆压缩系统。它能自动跨会话捕获工具使用记录,生成语义摘要,并在未来的对话中注入这些上下文。这让 AI 编码助手可以记住项目背景、决策过程和调试历史,即便会话结束或重连后也不会丢失。

§ 2

Every coding agent session starts with a blank slate. When a session times out or drops, all understanding of the project structure, fixed bugs, and technical decisions are lost. Claude-Mem solves this by continuously capturing observations (PostToolUse), compressing memories at session end, and injecting token-efficient context on the next startup, creating continuity across sessions.

AI 编码助手每次连接都是“白纸一张”。一旦会话超时或中断,之前对项目结构的理解、修复的 bug、做的技术决策全部丢失。Claude-Mem 通过在后台持续捕获观察记录(PostToolUse),在会话结束时压缩生成记忆,下次启动时自动注入 Token 高效的上下文,实现跨会话的知识连续性。

§ 3

The system provides persistent memory, progressive disclosure to control token cost, skill-based search via mem-search, a real-time web viewer (localhost:37777), and privacy tags. Wrap sensitive content in <private> to exclude it from storage. A beta channel offers experimental features like Endless Mode for biomimetic long-term memory.

系统提供:持久记忆、控制 Token 消耗的逐步披露机制、基于技能的 mem-search 搜索、实时 Web 查看器(localhost:37777)以及隐私控制。用 <private> 包裹敏感内容即可阻止其存储。Beta 频道提供实验性的 Endless Mode,模拟生物式的长期记忆。

§ 4

Claude-Mem uses five lifecycle hooks (SessionStart, UserPromptSubmit, PostToolUse, Stop, SessionEnd) to observe agent activity. A Bun-managed Worker Service runs an HTTP API on port 37777, backed by an SQLite database for sessions, observations, and summaries, plus a Chroma vector database for hybrid semantic + keyword search. The mem-search skill implements a 3-layer token-efficient workflow (search → timeline → get_observations).

Claude-Mem 通过五个生命周期钩子(SessionStart, UserPromptSubmit, PostToolUse, Stop, SessionEnd)来观察 Agent 活动。一个由 Bun 管理的 Worker 服务在 37777 端口运行 HTTP API,后端是存储会话、观察记录和摘要的 SQLite 数据库,以及用于混合语义与关键词搜索的 Chroma 向量数据库。mem-search 技能实现了三层 Token 高效检索流程(search → timeline → get_observations)。

§ 5

Install with a single command:

npx claude-mem install

For Gemini CLI:

npx claude-mem install --ide gemini-cli

Or use the plugin marketplace inside Claude Code:

/plugin marketplace add thedotmack/claude-mem
/plugin install claude-mem

Restart Claude Code and previous context appears automatically. Remember: npm install -g claude-mem only installs the SDK. Always use npx or /plugin to set up hooks and the worker.

To switch to Simplified Chinese mode, edit ~/.claude-mem/settings.json and set "CLAUDE_MEM_MODE": "code--zh".

通过单个命令安装:

npx claude-mem install

若要安装到 Gemini CLI:

npx claude-mem install --ide gemini-cli

也可以在 Claude Code 插件市场直接安装:

/plugin marketplace add thedotmack/claude-mem
/plugin install claude-mem

重启 Claude Code 后,之前的会话上下文会自动出现在新会话中。注意:npm install -g claude-mem 只会安装 SDK 库,不会注册插件钩子或启动 Worker。请务必使用 npx/plugin 命令安装。

配置模式与语言示例:编辑 ~/.claude-mem/settings.json,设置 "CLAUDE_MEM_MODE": "code--zh" 即可切换为简体中文模式。

§ 6

Ideal for developers working across many sessions on the same project who need to retain context. Great for reviewing historical decisions or complex debugging histories. Operates automatically with no manual triggers.

Caveats: Requires Node.js ≥ 18 and latest Claude Code. On Windows, ensure Node.js is in PATH to avoid 'npm not recognized' errors. Beta features like Endless Mode may be unstable. Specific language support (e.g., Chinese) must be configured via CLAUDE_MEM_MODE (e.g., code--zh).

适合需要跨长时间、多个会话在同一个项目上持续工作的开发者;也适合需要回顾历史决策、复杂 bug 调试过程的团队场景。系统自动运行,无需手动触发记忆。

边界与注意:需要 Node.js ≥ 18、Claude Code 最新版,且在 Windows 上若遇到 npm 不被识别的问题,需确保 Node.js 已正确安装并加入 PATH。Beta 功能如 Endless Mode 可能不稳定。记忆检索对中文等特定语言的支持需要通过 CLAUDE_MEM_MODE 配置(如 code--zh)。

打开原文 ↗