关于 repomemory
repomemory 是面向代码库中 AI 编码 Agent 的持久化可搜索知识库。它组织事实、决策、回归问题、偏好和自动捕获的会话,并支持多种编码工具。
主要功能
- 01关键词与语义混合搜索
- 02结构化项目及全局上下文
- 03自动保存会话摘要
- 04上下文路由与风险评估
- 05为多种编码工具配置
适用场景
- 01在编码会话开始时帮助 Agent 熟悉项目
- 02查找代码库过往决策
- 03记录修复以避免重复回归问题
- 04在不同代码库间沿用编码偏好
MCP 相关
MCP 服务提供七种用于搜索、读取、写入、列出、定向了解、评估风险和删除上下文的工具。配置命令可为 Claude Code、Cursor 等支持的客户端设置该服务。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
repomemory
你的代码库永不遗忘。
AI Agent 每次会话都会失去上下文。repomemory 解决了这个问题——只需一条命令,即可创建一个持久、可搜索的知识库,任何 AI 工具都能读取、搜索和写入其中。
npx repomemory go
问题
每次你使用 Claude Code、Cursor、Copilot 或其他 AI 编码 Agent 打开项目时:
- 它都会从头重新发现你的架构
- 它会提出之前已经讨论并否决过的更改
- 它会重新引入已经修复的错误
你的 CLAUDE.md / .cursorrules 有帮助,但内容是静态的,而且会过时。
解决方案
.context/
├── index.md ← Quick orientation (loaded every session)
├── facts/ ← Architecture, database, deployment
├── decisions/ ← "We chose Drizzle over Prisma because..."
├── regressions/ ← "This broke before. Here's what happened."
├── preferences/ ← Your coding style — follows you across all repos
├── sessions/ ← Auto-captured AI session summaries
└── changelog/ ← Monthly git history syncs
事实告诉 Agent 各项内容如何运作。决策避免重复讨论。回归问题避免错误再次出现。偏好教会 Agent 你的编码方式。
快速开始
使用 API 密钥(Claude Code、终端工作流)
npx repomemory go
只需一条命令:设置全局配置文件、创建 .context/、配置 Claude Code 和 Cursor、运行 AI 分析,并输出 CLAUDE.md 指令。
使用 Cursor(无需 API 密钥)
npx repomemory setup cursor
此操作会安装 Cursor 所需的一切:
~/.cursor/mcp.json中的 MCP 服务(在每个项目中自动启动 repomemory).cursor/rules/repomemory.mdc中的 规则(教会 Cursor 的 AI 使用上下文).cursor/commands/中的 6 个命令(在 Cursor 聊天中用/运行)
然后,在 Cursor 聊天中输入:
/repomemory-analyze
Cursor 自带的 AI 会扫描你的代码库,并通过 MCP 工具填充 .context/。无需外部 API 密钥——由你的 Cursor 订阅提供支持。
可用的 Cursor 命令:
| 命令 | 功能 |
|---|---|
/repomemory-analyze | 全面分析代码库——填充事实、决策和索引 |
/repomemory-orient | 在会话开始时快速了解项目 |
/repomemory-search | 搜索知识库 |
/repomemory-record | 记录事实、决策或回归问题 |
/repomemory-session | 保存会话摘要 |
/repomemory-status | 显示上下文覆盖情况 |
引导式向导
npx repomemory wizard
向导会引导你选择提供商、集成工具并执行首次分析。如果未检测到 API 密钥,则会提供 “None — I use Cursor”(无,我使用 Cursor) 选项,完全跳过外部分析。
非交互模式(适用于 CI)
npx repomemory go --yes --provider anthropic --embedding-provider gemini --max-files 80
使用 --yes / --defaults / --no-prompt 时不会显示提示。
MCP 服务——拥有真实记忆的 Agent
MCP 服务才是真正强大的功能。通过 repomemory setup claude 配置后,它会随 Claude Code 自动启动,并为 Agent 提供 7 个工具:
| 工具 | 功能 |
|---|---|
context_search | 在代码库和全局上下文中进行关键词与语义混合搜索 |
context_auto_orient | 一次调用即可了解项目:索引、偏好、近期会话 |
context_write | 写入条目,并智能路由其作用范围(偏好 → 全局) |
context_read | 读取完整内容,优先从代码库读取,必要时回退到全局内容 |
context_list | 浏览条目,并查看 [repo] / [global] 来源标签 |
context_risk | 评估修改风险——热点、隐性耦合、关键人物风险 |
context_delete | 移除过时知识 |
Agent: "Let me orient myself in this project..."
→ context_auto_orient()
→ Returns: project overview, preferences, recent sessions, recent changes
Agent: "Let me search for context about the auth flow..."
→ context_search("authentication flow")
→ Auto-routes to facts/ category, returns compact results
Agent: "I found a race condition. Let me record this."
→ context_write(category="regressions", filename="token-refresh-race", content="...")
→ Persisted. Detects if it supersedes an existing entry.
会话会在关闭时自动捕获。无需任何配置——repomemory setup claude 会处理一切。
支持的工具
| 工具 | 集成方式 | 是否需要 API 密钥? |
|---|---|---|
| Claude Code | MCP 服务(自动启动)+ 提交后钩子 | 是(用于分析) |
| Cursor | MCP 服务 + 规则 + 6 个斜杠命令 | 否 — 使用 Cursor 内置 AI |
| GitHub Copilot | copilot-instructions.md | 是(用于分析) |
| Windsurf | .windsurfrules | 是(用于分析) |
| Cline | .clinerules | 是(用于分析) |
| Aider | .aider.conf.yml | 是(用于分析) |
| Continue | .continue/rules/ | 是(用于分析) |
**Cursor 用户:**您不需要任何 API 密钥。运行
npx repomemory setup cursor,然后在 Cursor 聊天中使用/repomemory-analyze。Cursor 的 AI 会使用 MCP 工具进行分析 — 无论 Cursor 正在使用哪个模型(甚至可以在任务中途切换模型)。
支持的提供商
| 提供商 | 模型 | 环境变量 |
|---|---|---|
anthropic | claude-sonnet-4-6, claude-opus-4-6 | ANTHROPIC_API_KEY |
openai | gpt-4o, o3-mini | OPENAI_API_KEY |
gemini | gemini-2.0-flash, gemini-2.5-pro | GEMINI_API_KEY / GOOGLE_API_KEY |
grok | grok-3, grok-3-mini | GROK_API_KEY / XAI_API_KEY |
嵌入(可选,用于语义搜索):Gemini text-embedding-004(免费,默认)或 OpenAI text-embedding-3-small。根据可用的 API 密钥自动检测。
所有命令
repomemory go # One-command setup (add --yes for non-interactive)
repomemory wizard # Interactive guided setup
repomemory analyze # AI-powered repo analysis
repomemory analyze --merge # Update without overwriting edits
repomemory analyze --dry-run # Preview without API call
repomemory search <query> # Search knowledge base from terminal
repomemory status # Coverage and freshness report
repomemory doctor # Diagnostics and health check
repomemory dashboard # Local web UI (localhost:3333)
repomemory risk # Hotspots, coupling, ownership analysis
repomemory risk -f src/auth.ts # Targeted risk assessment for specific files
repomemory sync # Sync git history to changelog
repomemory setup <tool> # Configure Claude/Cursor/Copilot/etc
repomemory hook install # Auto-sync changelog on commits
repomemory global list # Manage global developer context
repomemory global export # Export global context as JSON
配置
仓库根目录中的 .repomemory.json(所有字段均为可选):
{
"provider": "anthropic",
"model": "claude-sonnet-4-6",
"embeddingProvider": "gemini",
"hybridAlpha": 0.5,
"maxFilesForAnalysis": 80,
"enableGlobalContext": true
}
自定义 ignorePatterns 和 keyFilePatterns 为累加式 — 它们会扩展内置默认值,而非替换默认值。
为什么不只用 CLAUDE.md?
| CLAUDE.md | repomemory | |
|---|---|---|
| 维护 | 手动 | AI 生成 + Agent 维护 |
| 搜索 | 加载所有内容 | 关键词与语义混合搜索 |
| 跨工具 | 仅限 Claude Code | 支持 7 种工具 |
| 团队知识 | 由一个人编写 | 每次 AI 会话都会贡献内容 |
| 决策 | 与指令混杂 | 结构化、可搜索 |
| 回归问题 | 不跟踪 | 防止重复出现的错误 |
| 会话 | 不跟踪 | 关闭时自动捕获 |
| 新鲜度 | 未知 | 过时检测 + 自动清除 |
repomemory 不会取代 CLAUDE.md — 而是与之互补。CLAUDE.md 用于存放指令和规则。.context/ 则用于存放随时间不断积累的知识。
参与贡献
请参阅 CONTRIBUTING.md,了解开发环境设置、测试和贡献指南。
许可证
MIT
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。