I Built Persistent Memory for AI Coding Assistants — Here's How It Works
I Built Persistent Memory for AI Coding Assistants — Here’s How It Works
我为 AI 编程助手构建了持久化记忆——它是如何工作的
Every time you open a new AI chat, your assistant forgets everything. I fixed that. The Problem If you use Cursor, Claude Code, or Amazon Q regularly, you’ve probably hit this wall: You explain your project architecture in Monday’s chat. On Tuesday, you open a new session and start from scratch. You paste the same context, re-explain the same patterns, and re-describe the same service boundaries — every single time. This isn’t a minor inconvenience. For large codebases, every AI interaction starts with 10 minutes of context-loading before you can ask anything useful. For teams, every developer builds their own mental model of the codebase in isolation, while the AI assistant knows none of it.
每当你开启一个新的 AI 对话,你的助手就会忘记之前的一切。我解决了这个问题。问题在于:如果你经常使用 Cursor、Claude Code 或 Amazon Q,你可能遇到过这样的障碍:你在周一的对话中解释了项目架构,到了周二,你开启新会话时又得从头开始。你不得不一次又一次地粘贴相同的上下文、重新解释相同的模式、重新描述相同的服务边界。这绝非小事。对于大型代码库,每次 AI 交互都需要花费 10 分钟加载上下文,才能开始有意义的沟通。对于团队而言,每位开发者都在孤立地构建自己的代码库心智模型,而 AI 助手对此一无所知。
I’ve been building production systems on Azure for several years — .NET microservices, KEDA autoscaling, Azure Service Bus pipelines. Our codebase has 40+ services, clean architecture patterns, vendor integration handlers, and years of architectural decisions that live entirely in people’s heads. Every time I opened a new AI chat, I was manually transferring that knowledge into a chat window. So I built Mnemo.
我多年来一直在 Azure 上构建生产系统,涉及 .NET 微服务、KEDA 自动扩缩容以及 Azure Service Bus 管道。我们的代码库包含 40 多个服务、整洁架构模式、供应商集成处理程序,以及多年来仅存在于开发人员脑海中的架构决策。每次开启新的 AI 对话,我都得手动将这些知识输入到聊天窗口中。于是,我构建了 Mnemo。
What Mnemo Does: Mnemo is a local MCP (Model Context Protocol) server that gives AI coding assistants persistent, structured knowledge about your codebase. One command initializes it. After that, every AI chat automatically knows: Your project’s architecture and patterns, Your API endpoints, Your engineering decisions, Who owns which part of the codebase, Errors you’ve already debugged and how you fixed them, Incidents, code reviews, and team knowledge. It works with Cursor, Claude Code, Amazon Q, and any MCP-compatible AI client. The moment a new AI chat session starts, Mnemo automatically loads your project context. You never paste architecture descriptions again.
Mnemo 的功能:Mnemo 是一个本地 MCP(模型上下文协议)服务器,它为 AI 编程助手提供关于你代码库的持久化、结构化知识。只需一条命令即可初始化。此后,每次 AI 对话都会自动获知:你的项目架构和模式、API 端点、工程决策、代码库各部分的负责人、已修复的错误及其解决方法、事故记录、代码审查以及团队知识。它适用于 Cursor、Claude Code、Amazon Q 以及任何兼容 MCP 的 AI 客户端。当新的 AI 对话会话开始时,Mnemo 会自动加载你的项目上下文。你再也不用重复粘贴架构描述了。
How It Works Technically: When you run mnemo init inside your project, several things happen. 1. AST-Based Codebase Parsing: Mnemo parses your codebase using real language parsers — not regex or grep. C# → Roslyn, Python → ast, TypeScript → TypeScript Compiler API. This allows Mnemo to understand: Method signatures, Class hierarchies, Interface implementations, Dependency relationships. From this, it builds a compact repo map — a structured representation of your codebase shape. Not the full source code. Just the architecture-level understanding required for AI context.
技术原理:当你在项目中运行 mnemo init 时,会发生以下几件事。1. 基于 AST 的代码库解析:Mnemo 使用真正的语言解析器(而非正则表达式或 grep)来解析代码库。C# 使用 Roslyn,Python 使用 ast,TypeScript 使用 TypeScript Compiler API。这使得 Mnemo 能够理解:方法签名、类层次结构、接口实现、依赖关系。基于此,它会构建一张紧凑的仓库地图——即代码库形态的结构化表示。它不是完整的源代码,而是 AI 上下文所需的架构级理解。
-
Architecture Detection: Mnemo scans the codebase for structural signals: Common handler inheritance, IRepository
patterns, Command/query separation, Event-driven conventions, DI registration styles. Using these signals, it classifies your architecture automatically: Clean Architecture, CQRS, Event-Driven, Hexagonal, Repository Pattern, Handler Pattern. This becomes part of the persistent project memory. -
架构检测:Mnemo 会扫描代码库中的结构信号:常见的处理程序继承、IRepository
模式、命令/查询分离、事件驱动约定、依赖注入(DI)注册风格。利用这些信号,它会自动对你的架构进行分类:整洁架构、CQRS、事件驱动、六边形架构、仓库模式、处理程序模式。这些信息将成为持久化项目记忆的一部分。 -
MCP Server Initialization: Mnemo launches a local MCP server process that exposes tools AI assistants can call. At the start of each AI chat session, the assistant calls
mnemo_recall. Mnemo then returns a structured context payload containing: Repo map, Architecture profile, Recent engineering decisions, Error/debug history, Current task context. Everything is stored locally inside:.mnemo/. Currently: JSON files store structured memory, A vector store powers semantic search. No source code leaves your machine. -
MCP 服务器初始化:Mnemo 会启动一个本地 MCP 服务器进程,暴露 AI 助手可以调用的工具。在每次 AI 对话会话开始时,助手会调用
mnemo_recall。随后,Mnemo 会返回一个结构化的上下文负载,包含:仓库地图、架构概况、近期工程决策、错误/调试历史、当前任务上下文。所有内容都存储在本地的.mnemo/文件夹中。目前:JSON 文件存储结构化记忆,向量数据库支持语义搜索。没有任何源代码会离开你的机器。
Why MCP Matters: MCP (Model Context Protocol) is an open protocol from Anthropic that standardizes how AI assistants connect to tools and external context. Think of it like USB for AI tooling. Instead of every AI platform building proprietary integrations: Any MCP server can provide tools, Any MCP-compatible AI client can consume them. Mnemo implements MCP, meaning it works across: Cursor, Claude Code, Amazon Q, Kiro, Other MCP-compatible tools. Mnemo isn’t tied to a single AI assistant. It’s an intelligence layer that upgrades all of them.
为什么 MCP 很重要:MCP(模型上下文协议)是 Anthropic 推出的一个开放协议,旨在标准化 AI 助手连接工具和外部上下文的方式。可以把它想象成 AI 工具的“USB 接口”。与其让每个 AI 平台都构建专有的集成,不如:任何 MCP 服务器都可以提供工具,任何兼容 MCP 的 AI 客户端都可以使用它们。Mnemo 实现了 MCP,这意味着它适用于:Cursor、Claude Code、Amazon Q、Kiro 以及其他兼容 MCP 的工具。Mnemo 不绑定于单一的 AI 助手,它是一个能够升级所有助手的智能层。
What the AI Actually Sees: When the assistant calls mnemo_recall, it receives structured project context like this: ## Project Context Architecture: Clean Architecture + CQRS Patterns: Repository (9 interfaces), Handler pattern (12 handlers), DI container ## Decisions - Use handler pattern for vendor-specific logic - Auth service uses cache-aside with 5min TTL ## Repo Map PaymentService/Handlers/ - StripeHandler - PayPalHandler - SquareHandler AuthService/Services/ - TokenService : ITokenService. With this context loaded, the AI understands: How the codebase is structured, Which patterns are expected, Existing architectural conventions, Historical engineering decisions. So when you ask: “Add a new payment handler”, The generated implementation: Inherits from BasePaymentHandler, Follows existing conventions, Registers correctly in DI, Matches existing architecture. Without Mnemo, most assistants generate generic code that doesn’t fit the system design at all.
AI 实际看到的内容:当助手调用 mnemo_recall 时,它会收到如下结构化的项目上下文:## 项目上下文 架构:整洁架构 + CQRS 模式:仓库(9 个接口)、处理程序模式(12 个处理程序)、DI 容器 ## 决策 - 针对供应商特定逻辑使用处理程序模式 - 认证服务使用 5 分钟 TTL 的旁路缓存 ## 仓库地图 PaymentService/Handlers/ - StripeHandler - PayPalHandler - SquareHandler AuthService/Services/ - TokenService : ITokenService。加载此上下文后,AI 能够理解:代码库的结构、预期的模式、现有的架构约定、历史工程决策。因此,当你要求“添加一个新的支付处理程序”时,生成的实现会:继承自 BasePaymentHandler、遵循现有约定、在 DI 中正确注册、匹配现有架构。如果没有 Mnemo,大多数助手生成的通用代码根本无法适配系统设计。
Installation: Option A: VS Code Extension (Easiest) Install the Mnemo extension from the VS Code Marketplace, Open a project, Click “Initialize Mnemo?”, Done. The extension automatically: Downloads the Mnemo binary, Initializes the repository, Configures MCP. No Python required. Option B: Homebrew (macOS/Linux) brew tap Mnemo-mcp/tap, brew install mnemo. Then: cd your-project, mnemo init. Option C: pip (All Platforms) pip install mnemo. Or from source: git clone https://github.com/Mnemo-mcp/Mnemo.git, cd Mnemo, pip install -e .. Then: cd your-project, mnemo init.
安装方式:选项 A:VS Code 扩展(最简单):从 VS Code 市场安装 Mnemo 扩展,打开项目,点击“Initialize Mnemo?”,完成。该扩展会自动:下载 Mnemo 二进制文件、初始化仓库、配置 MCP。无需 Python 环境。选项 B:Homebrew (macOS/Linux):brew tap Mnemo-mcp/tap,brew install mnemo。然后:cd your-project,mnemo init。选项 C:pip (全平台):pip install mnemo。或从源码安装:git clone https://github.com/Mnemo-mcp/Mnemo.git,cd Mnemo,pip install -e .。然后:cd your-project,mnemo init。
Final Thoughts: Mnemo started as a solution to a frustrating problem: AI assistants forget everything between sessions. For small projects, that’s annoying. For large production systems, it’s a major productivity bottleneck. Mnemo gives AI coding assistants persistent architectural memory, allowing them to operate with real understanding of your codebase instead of stateless guesses. I’d love feedback — especially from teams managing large, distributed systems. What project context do you find yourself re-explaining most often?
结语:Mnemo 的初衷是为了解决一个令人沮丧的问题:AI 助手在会话之间会忘记一切。对于小项目,这只是有点烦人;但对于大型生产系统,这成了严重的生产力瓶颈。Mnemo 为 AI 编程助手提供了持久化的架构记忆,使它们能够真正理解你的代码库,而不是进行无状态的猜测。我非常期待大家的反馈——特别是那些管理大型分布式系统的团队。你最常需要重复解释的项目上下文是什么?