ai-memory:让 AI 编程助手真正记住「上次做到哪了」,跨工具无缝交接,Rust 实现,Wiki 存 Git

ai-memory-long-term-memory-coding-agents-claude-codex-handoff-rust

Tech-News #AI工具#编程助手#长期记忆#跨工具#Claude Code#Codex#Rust#开源
更新于
🇨🇳 中文

by Mycelium Protocol


GitHub:akitaonrails/ai-memory
许可证:MIT
语言:Rust
Stars:3,953 · Forks:298
创建:2026-05-21 | 最近更新:2026-08-22


一、它解决的核心问题

AI 编程助手的上下文是会话级的——关掉 Claude Code,下次打开要重新讲一遍背景;换用 Codex 接着干,要再把架构、失败过的方案、当前卡点都解释一遍。

ai-memory 直接解决这个问题:

「关掉 Claude Code,在同一个目录开 Codex,继续工作——不用重新解释架构、走过的弯路、还开着的问题。」


二、工作机制

生命周期 Hook 自动捕获

安装后,ai-memory 为每个支持的客户端配置生命周期钩子(MCP config + 事件钩子)。钩子以「发出即忘」的方式,捕获有界、脱敏的提示词、工具调用事件和会话边界观察——不是完整的原始日志,而是精选的结构化快照。

会话结束时编译为 Wiki

会话结束(SessionEnd)或手动执行 ai-memory finalize-session 时,系统把当次会话的观察编译成一批 Markdown 页面,写入一个 Git 仓库。超版本链 + Git 历史意味着可以用 ai-memory checkpoints 或 restore-page 时间旅行。

下次开工时收到交接块

下次在同一个目录打开任何支持的客户端,会话开始前自动注入一个「从这里继续」的交接块,包含上次的进度、待解决的问题、未完成的决策——不管上次用的是哪个工具。

Wiki 是普通 Git 仓库

存储格式是纯 Markdown,按 <wiki_root>/<workspace_id>/<project_id>/ 组织。可以 grep、在 Obsidian 里打开、用 rsync 备份。没有向量数据库需要维护。


三、支持的客户端(20+)

客户端支持程度
Claude Code完整(MCP + 生命周期钩子)
OpenAI Codex完整(MCP + 生命周期钩子)
Command Code完整(4 种钩子事件)
Cursor完整
Gemini CLI完整
Devin CLI完整
Kiro CLI完整(v2 + 实验性 v3)
Kimi Code完整(10 种钩子事件)
OpenCode完整(生成 TypeScript 插件)
Oh My Pi / OMP完整
VS Code Copilot仅 MCP(无生命周期钩子)
Zed仅 MCP
Claude Desktop仅 MCP(via mcp-remote)
Grok Build CLI完整
Antigravity CLI完整

此外还有 OpenClaw、Zero、Swival CLI、Pi(通过生成的 bridge extension)等。


四、检索不依赖 LLM

零 LLM 模式下,ai-memory 提供三种检索通道:

  • FTS5 全文搜索:SQLite FTS5,响应快,无需 API Key
  • 实体辅助召回:每个 Wiki 页面存储最多 10 个规范实体名词(entities: 前置数据),支持精确/前缀/复合词匹配
  • 图邻居 RRF:基于知识图谱边的相关性评分

加了 LLM/Embedding 提供者之后,可以额外做语义检索和页面综合。支持 OpenAI、Voyage、Google Gemini 及任意 OpenAI 兼容端点(Ollama、LM Studio、vLLM)。


五、权威感知检索

检索结果有分层优先级:_rules/、decisions/、procedures/、gotchas/ 目录的页面在截断前会被上调权重。历史会话证据仍然可以被精确搜索到,不会因为优先级低而消失。

重要设计原则:这些优先级只影响检索排序,不赋予 Wiki 内容指令权威——从 Wiki 里读出来的代码主张在行动前仍然需要对照实际代码库验证。


六、opt-in 托管工作流

除了 Hook 捕获外,还有可选的「托管工作流」模式:

ai-memory run claude      # 启动 Claude Code(带完整上下文)
ai-memory run codex --yolo  # 无缝切换到 Codex
ai-memory run command-code  # 再切 Command Code

三者之间共享一个逻辑工作流,带有原生的每客户端会话恢复和完整的可见事件账本。


七、安装(macOS 原生二进制)

# 下载 macOS Apple Silicon 原生二进制
curl -L https://github.com/akitaonrails/ai-memory/releases/latest/download/ai-memory-macos-aarch64.tar.gz \
  | tar -xz
sudo mv ai-memory /usr/local/bin/

# 启动服务器(本地模式,无 LLM)
ai-memory start

# 为 Claude Code 安装 MCP 配置 + 钩子
ai-memory install-mcp --client claude
ai-memory install-hooks --agent claude

x86_64 Mac:把 aarch64 换成 x86_64。Linux 用 Docker:

docker run -d \
  -v ~/.ai-memory:/data \
  -p 3579:3579 \
  akitaonrails/ai-memory:latest

八、与 MemPalace、DeepTutor 等的定位区别

工具核心记忆内容适用场景
ai-memory编码会话的进度、决策、失败尝试、悬而未决的问题多工具协作的编程工作流
MemPalace结构化知识条目(用户主动归档)个人知识管理
DeepTutor学习轨迹、知识掌握度个性化学习

ai-memory 的记忆是被动的、会话级的、面向工程决策的,不需要用户手动写知识。


ai-memory 的核心赌注是:AI 编程助手的真正痛点不是单次会话的上下文长度,而是跨会话、跨工具的状态丢失。 把每次会话的精华编译成 Git 里的 Markdown,是目前最轻量、最可靠的解法——没有供应商锁定,没有黑盒向量库,随时可以 grep。


Mycelium Protocol — 追踪 AI 系统的底层演化


关于 Mycelium

菌丝协议。持续追踪 AI 工具、系统和实验的内容节点。


🇬🇧 English

ai-memory: Long-Term Memory for AI Coding Agents — Cross-Tool Handoff, Git-Backed Wiki, Rust

by Mycelium Protocol


GitHub: akitaonrails/ai-memory
License: MIT
Language: Rust
Stars: 3,953 · Forks: 298
Created: 2026-05-21 | Updated: 2026-08-22


The Core Problem

AI coding agents are session-scoped — close Claude Code and you start fresh; switch to Codex mid-task and you have to re-explain the architecture, the dead ends, and the open questions.

ai-memory directly addresses this:

“Quit Claude Code mid-task, start OpenAI Codex in the same directory, continue without re-explaining the architecture, the failed approaches, or the open questions.”


How It Works

Lifecycle hooks capture automatically. After installation, ai-memory configures lifecycle hooks (MCP config + event hooks) for each supported client. Hooks fire-and-forget bounded, sanitized observations of prompts, tool events, and session boundaries — not raw logs, but curated structured snapshots.

Session end compiles a wiki. On SessionEnd (or manual ai-memory finalize-session), the session’s observations are compiled into Markdown pages and written to a git repository. Supersession chains + git history mean you can time-travel with ai-memory checkpoints or restore-page.

Next session receives a handoff. The next agent in the same directory gets a “where you left off” block before its first prompt — regardless of which tool picks up the work.

The wiki is a plain git repo. Storage is pure Markdown organized under <wiki_root>/<workspace_id>/<project_id>/. Grep it, open it in Obsidian, back it up with rsync. No vector database to maintain.


20+ Supported Clients

ClientSupport
Claude CodeFull (MCP + lifecycle hooks)
OpenAI CodexFull (MCP + lifecycle hooks)
Command CodeFull (4 hook events)
CursorFull
Gemini CLIFull
Devin CLIFull
Kiro CLIFull (v2 + experimental v3)
Kimi CodeFull (10 hook events)
OpenCodeFull (generated TypeScript plugin)
Oh My Pi / OMPFull
VS Code CopilotMCP-only (no lifecycle hooks)
ZedMCP-only
Claude DesktopMCP-only (via mcp-remote)
Grok Build CLIFull
Antigravity CLIFull

Plus OpenClaw, Zero, Swival CLI, Pi (generated bridge extension), and more.


Retrieval Without LLM

Zero-LLM mode provides three retrieval channels:

  • FTS5 full-text search: SQLite FTS5, fast, no API key required
  • Entity-assisted recall: Each wiki page stores up to 10 canonical entity nouns (entities: frontmatter); exact, prefix, and compound-word matches form a project-scoped RRF stream
  • Graph-neighbor RRF: Relevance scoring via knowledge graph edges

LLM/embedding providers (OpenAI, Voyage, Gemini, or any OpenAI-compatible endpoint including Ollama) are opt-in additions for semantic retrieval and page consolidation.


Authority-Aware Retrieval

Retrieval has tiered priority: _rules/, decisions/, procedures/, and gotchas/ pages are bumped above session evidence before truncation. Historical session records remain findable via targeted search — they’re not filtered out.

Key design principle: priority affects ranking, not authority. Wiki content is historical evidence — verify code claims against the actual checkout before acting on them.


Opt-In Managed Workstreams

Beyond hook capture, an optional managed mode:

ai-memory run claude       # start Claude Code with full context
ai-memory run codex --yolo  # seamlessly switch to Codex
ai-memory run command-code  # switch again

All three share one logical workstream with native per-harness session resume and a portable visible-event ledger.


Install (macOS native binary)

# Apple Silicon
curl -L https://github.com/akitaonrails/ai-memory/releases/latest/download/ai-memory-macos-aarch64.tar.gz \
  | tar -xz
sudo mv ai-memory /usr/local/bin/

# Start server (local mode, no LLM required)
ai-memory start

# Install MCP config + hooks for Claude Code
ai-memory install-mcp --client claude
ai-memory install-hooks --agent claude

For x86_64 Mac: replace aarch64 with x86_64. For Linux, use Docker:

docker run -d \
  -v ~/.ai-memory:/data \
  -p 3579:3579 \
  akitaonrails/ai-memory:latest

Positioning vs. MemPalace, DeepTutor

ToolCore Memory ContentFor
ai-memorySession progress, decisions, dead ends, open questionsMulti-tool coding workflows
MemPalaceStructured knowledge entries (user-curated)Personal knowledge management
DeepTutorLearning traces, mastery statePersonalized learning

ai-memory’s memory is passive, session-scoped, engineering-decision-focused — no manual knowledge writing required.


ai-memory’s core bet: the real pain for AI coding agents isn’t context length within a session — it’s state loss across sessions and across tools. Compiling each session’s essence into Markdown in a git repo is the lightest, most reliable solution available today: no vendor lock-in, no black-box vector store, always grep-able.


Mycelium Protocol — tracking the deep evolution of AI systems

© 2026 Mycelium Protocol. All rights reserved.

💬 评论与讨论

使用 GitHub 账号登录后发表评论

关于本站 · 免责声明

🍄 Mushroom Research Blog 是非营利、免费公开的个人科技观察博客与公众号 XStack18,不接受商业合作、不代表任何企业或机构立场,也不谋求商业利益。我们以个人视角客观中立地记录和分析 AI、Web3 等领域的最新模型发布与技术动态——不止转述新闻标题或二手信息,而是给出有独立思考的深入分析,希望帮更多人获得有价值的一手科技认知。

⚠️ 文中介绍的开源代码与模型,仅供学习交流与技术借鉴。它们大多仍处于早期阶段,有待进一步研究和验证,请勿直接用于工作或生产环境;如需采用,请先自行充分测试,并核实其许可证与安全性。
Open-source code and models featured here are shared for learning and reference only. Most are early-stage and still need further study and verification — please don't use them directly in your work or in production. Test them thoroughly and check their licenses and security first.

  1. 本站文章均为作者基于公开信息的个人研究与观点整理,不代表文中提及的任何公司、产品、模型的官方立场,未与其构成商业关联或合作关系。
  2. 科技行业信息更新极快,我们尽力保证内容准确、及时,但不对完整性、实时性做绝对保证,具体请以相关企业/项目官方公告为准。
  3. 文中引用的第三方商标、产品名称、图片、数据等版权归原权利人所有,我们会尽量注明来源;如你认为存在版权疑问或侵权,请通过下方邮箱联系我们,收到通知后会尽快核实处理(更正、加注来源或删除)。
  4. 文章内容仅为技术科普与个人观点,不构成投资、法律或其他专业建议,据此进行任何决策的后果需自行判断和承担。

📮 侵权 / 勘误 / 合作咨询:hello@mushroom.cv