AI代码记忆 是 AI Skill Hub 本期精选MCP工具之一。综合评分 7.5 分,整体质量较高。我们推荐使用将其纳入你的 AI 工具库,帮助提升工作效率。
AI代码记忆 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
AI代码记忆 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
# 方式一:通过 Claude Code CLI 一键安装
claude skill install https://github.com/masondelan/selvedge
# 方式二:手动配置 claude_desktop_config.json
{
"mcpServers": {
"ai----": {
"command": "npx",
"args": ["-y", "selvedge"]
}
}
}
# 配置文件位置
# macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# Windows: %APPDATA%/Claude/claude_desktop_config.json
# 安装后在 Claude 对话中直接使用 # 示例: 用户: 请帮我用 AI代码记忆 执行以下任务... Claude: [自动调用 AI代码记忆 MCP 工具处理请求] # 查看可用工具列表 # 在 Claude 中输入:"列出所有可用的 MCP 工具"
// claude_desktop_config.json 配置示例
{
"mcpServers": {
"ai____": {
"command": "npx",
"args": ["-y", "selvedge"],
"env": {
// "API_KEY": "your-api-key-here"
}
}
}
}
// 保存后重启 Claude Desktop 生效
<p align="center"> <img src="docs/wordmark.svg" alt="selvedge" width="480"> </p>
<p align="center"> <a href="https://selvedge.sh"><strong>selvedge.sh</strong></a> · <a href="https://pypi.org/project/selvedge/"><strong>PyPI</strong></a> · <a href="https://github.com/masondelan/selvedge"><strong>GitHub</strong></a> </p>
<p align="center"> <a href="https://github.com/masondelan/selvedge/actions/workflows/test.yml"><img src="https://github.com/masondelan/selvedge/actions/workflows/test.yml/badge.svg" alt="Tests"></a> <a href="https://pypi.org/project/selvedge/"><img src="https://img.shields.io/pypi/v/selvedge?cacheSeconds=3600" alt="PyPI"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a> </p>
Long-term memory for AI-coded codebases. A git blame for AI agents — but for the why, not just which line which model touched. Captured live, by the agent, as the change happens.
Selvedge is a local MCP server. AI coding agents (Claude Code, Cursor, Copilot) call it as they work to log structured change events with reasoning. Your data stays in a SQLite file under .selvedge/ next to your code.
---
Six months ago, your AI agent added a column called user_tier_v2. You don't know why. git blame points to a commit from claude-code with a generated message that says "Update schema." The session that made the change is long gone — and so is the prompt that produced it.
With Selvedge, you run this instead:
$ selvedge blame user_tier_v2
user_tier_v2
Changed 2025-10-14 09:31:02
Agent claude-code
Commit 3e7a991
Reasoning User asked to add a grandfathering flag for legacy free-tier
users during the pricing migration. Stores the original tier
so we can backfill discounts without touching billing history.
That reasoning was captured by the agent in the moment — written into Selvedge from the same context that produced the change. Not inferred from the diff afterward by a second LLM. Not a hand-typed commit message.
---
---
Two themes in one release as a one-time exception to the single-theme cadence: stay-current (background PyPI version check) and retention basics (selvedge prune for the tool_calls table). Drop-in upgrade for anyone on 0.3.5.
The recovery-basics release. v0.3.1 made the runtime safe; v0.3.2 made problems visible; v0.3.5 ships the minimum viable "what happens when something has gone wrong" surface. Drop-in upgrade for anyone on 0.3.4.
selvedge verify — DB-correctness gate with two exit tiers. Walks the store and reports each check as PASS / WARN / FAIL. Must-fail conditions (SQLite corruption, schema mismatch against the declared MIGRATIONS, empty entity_path, unknown change_type in the store, unparseable timestamps, malformed tool_calls rows) exit non-zero. Should-warn conditions (singleton changeset_id groups, events past the 60-minute backfill window with no git_commit) print warnings but exit 0 by default. Pass --strict to escalate warnings to failures — the tiering means selvedge verify can drop into CI on day one without || true. --json for machine output.
selvedge backup — online SQLite snapshot via VACUUM INTO. Default destination .selvedge/backups/selvedge-YYYYMMDD-HHMMSS.db, kept out of git because selvedge init now appends .selvedge/backups/ to the project .gitignore (and the first selvedge backup run on an existing repo appends it the same way — idempotent). Hardcoded keep_last=7 for this release; the setting becomes backup_keep_last in .selvedge/config.toml when that file lands in v0.3.10. --output <path> overrides the default and is excluded from rotation so ad-hoc destinations aren't swept up. Two backups in the same second don't collide.
Doctor — Last backup row. INFO when the newest backup is ≤7 days old, WARN when older, FAIL when no backups exist and the events table has ≥10,000 rows (the threshold where no-backups becomes a real data-loss exposure rather than a CI/scratch DB).
Doctor — Schema version now FAILs on downgrade. When schema_migrations contains a version not declared in the current MIGRATIONS tuple, the row fails rather than silently passing — surfaces "this DB was last opened by a newer Selvedge" before any write attempts schema work it doesn't understand.
See CHANGELOG.md for the full list including the 24 new tests across test_verify.py, test_backup.py, and the test_doctor.py extension.
---
pip install selvedge
cd your-project
selvedge setup
That's it. selvedge setup is an interactive wizard: it detects which AI tools you have (Claude Code, Cursor, Copilot), writes the MCP entry into each one's config, drops the canonical agent-instructions block into your project's prompt file (CLAUDE.md / .cursorrules / copilot-instructions.md), runs selvedge init, and installs the post-commit hook. Every modified file gets a .bak written next to it before any change reaches disk. Re-running is a no-op.
For CI bootstrap or devcontainer.json postCreateCommand:
selvedge setup --non-interactive --yes
| Method | Format | Example |
|---|---|---|
| Env var | SELVEDGE_DB=/path/to/db | Per-session override |
| Project init | selvedge init | Creates .selvedge/selvedge.db in CWD |
| Global fallback | ~/.selvedge/selvedge.db | Used if no project DB found |
---
selvedge init [--path PATH] Initialize in project
selvedge status Recent activity summary
selvedge diff ENTITY [--limit N] Change history for entity
selvedge blame ENTITY Most recent change + context
selvedge history [--since SINCE] Browse all history
[--entity ENTITY]
[--project PROJECT]
[--changeset CS]
[--summarize]
[--limit N]
selvedge changeset [CHANGESET_ID] Show events in a changeset
[--list] or list all changesets
[--project NAME]
[--since SINCE]
selvedge search QUERY [--limit N] Full-text search
selvedge stats [--since SINCE] Tool call coverage report (per-tool, per-agent)
selvedge doctor [--json] Health check: DB path, schema, hook, MCP wiring
selvedge install-hook [--path PATH] Install git post-commit hook
[--window MIN] (default 60 minutes)
selvedge backfill-commit --hash HASH Backfill git_commit on recent events
[--window MIN] (default 60 minutes)
selvedge import PATH Import migration files (SQL / Alembic)
[--format auto|sql|alembic]
[--project NAME]
[--dry-run]
selvedge export [--format json|csv] Export history to JSON or CSV
[--since SINCE]
[--entity ENTITY]
[--output FILE]
selvedge log ENTITY CHANGE_TYPE Manually log a change
[--diff TEXT] CHANGE_TYPE: add, remove, modify,
[--reasoning TEXT] rename, retype, create, delete,
[--agent NAME] index_add, index_remove, migrate
[--commit HASH]
[--project NAME]
[--changeset CS]
All read commands support --json for machine-readable output.
Relative time in --since: - 15m → last 15 minutes (m = minutes) - 24h → last 24 hours - 7d → last 7 days - 5mo → last 5 months (mo or mon = months) - 1y → last year
Unparseable inputs (e.g. --since yesterday) exit with a clear error rather than silently returning empty results. ISO 8601 timestamps are also accepted and normalized to UTC.
---
python scripts/coverage_check.py --since 30d ```
The coverage script compares your git log against Selvedge events and shows which commits have associated change events. Low coverage usually means the system prompt needs strengthening — see docs/fallbacks.md for guidance.
---
There's a fast-growing "git blame for AI agents" category. Here's where Selvedge fits — and where it deliberately doesn't.
| Reasoning source | Granularity | Mechanism | Grouping | Storage | |
|---|---|---|---|---|---|
| **Selvedge** | **Captured live**, by the agent in the same context that produced the change | **Entity** — DB column, table, env var, dep, API route, function | **MCP server** — agent calls it as work happens | **Changesets** — named feature/task slugs across many entities | SQLite, zero deps |
| AgentDiff | **Inferred post-hoc** by Claude Haiku from the diff at session end | Line | Git pre/post-commit hook | None | JSONL on disk |
| Origin | Captured at commit time | Line | Git hook | None | Local |
| Git AI | Attribution metadata | Line | Git hook + Agent Trace alliance | None | Git notes |
| BlamePrompt | Prompt-only | Line | Git hook | None | Local |
Why "captured live" matters. AgentDiff and Origin generate reasoning after the change is made, by feeding the diff back to a second LLM call. Selvedge's reasoning is the agent's own intent, written from the same context window that produced the change — no inference, no hallucinated explanations, and an empty reasoning field is itself a useful signal (the agent didn't have one).
Why "entity-level" matters. Most tools attribute lines. Selvedge attributes things you actually search for: users.email, env/STRIPE_SECRET_KEY, api/v1/checkout, deps/stripe. The first question after git blame is usually "what's the history of this column", not "what's the history of lines 40–48 of users.py".
Why "changesets" matter. A Stripe billing rollout touches the users table, two new env vars, three new API routes, one dependency, and four functions across the codebase. Tag every event with changeset:add-stripe-billing and you can pull the entire scope back later — even if the original PR was broken into eight smaller ones over a month.
Selvedge ↔ Agent Trace. Agent Trace (Cursor + Cognition AI, RFC Jan 2026, backed by Cloudflare, Vercel, Google Jules, Amp, OpenCode, and git-ai) is an emerging open standard for AI code attribution traces. Selvedge isn't a competitor to it — it's a compatible producer. The design for selvedge export --format agent-trace is at docs/agent-trace-interop.md. Agent Trace is the wire format. Selvedge is the live capture + query layer that emits it.
---
If you're a Claude Code user and want to install Selvedge through the official plugin marketplace flow, run these inside Claude Code after pip install selvedge:
/plugin marketplace add masondelan/selvedge
/plugin install selvedge@selvedge
The plugin system wires the MCP server into Claude Code, but it does not install the Python package for you — `pip install selvedge first, otherwise the selvedge-server` command won't exist on your PATH and the plugin can't start. For the full setup (post-commit hook, project CLAUDE.md instructions block, etc.), selvedge setup is still the recommended path; the plugin marketplace install is just the lightweight Claude-Code-only entry point.
Verify the wiring — open a second terminal in the same project:
selvedge watch
Make any change in your AI tool — add a column, rename a function, add an env var. selvedge watch should print the new event within a second of the agent calling log_change. If nothing arrives, run selvedge doctor for a single-command health check that tells you which step is silently broken.
Query your history:
selvedge status # recent activity + missing-commit count
selvedge diff users # all changes to the users table
selvedge diff users.email # changes to a specific column
selvedge blame payments.amount # what changed last and why
selvedge history --since 30d # last 30 days of changes
selvedge history --since 15m # last 15 minutes ('m' = minutes)
selvedge changeset add-stripe-billing # all events for a feature/task
selvedge search "stripe" # full-text search
selvedge stats # log_change coverage report (per-agent)
selvedge import migrations/ # backfill from migration files
selvedge export --format csv # dump history to CSV
<details> <summary><b>Manual install</b> — if you'd rather wire it up yourself</summary>
If you don't want to run the wizard, the four manual steps it automates:
1. Initialize in your project
cd your-project
selvedge init
2. Add to your Claude Code config
~/.claude/config.json:
{
"mcpServers": {
"selvedge": {
"command": "selvedge-server"
}
}
}
For Cursor: ~/.cursor/mcp.json. For Copilot: .github/copilot-instructions.md (different format — see selvedge prompt --help).
3. Tell your agent to use it
selvedge prompt --install CLAUDE.md
This installs the canonical agent-instructions block, sentinel-bracketed (` / `) so future --install calls update the bracketed region without disturbing anything else in the file. Or pipe it:
selvedge prompt | tee -a CLAUDE.md
4. Install the post-commit hook
selvedge install-hook
That's the same four steps the wizard runs.
</details>
---
一个有趣的AI代码记忆工具
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
经综合评估,AI代码记忆 在MCP工具赛道中表现稳健,质量良好。如果你已有明确的使用需求,可以直接上手体验;如果还在评估阶段,建议对比同类工具后再做决策。
| 原始名称 | selvedge |
| 原始描述 | 开源MCP工具:Long-term memory for AI-coded codebases. A git blame for AI agents — but for the。⭐8 · Python |
| Topics | ai-agent代码追溯代码记忆 |
| GitHub | https://github.com/masondelan/selvedge |
| License | MIT |
| 语言 | Python |
收录时间:2026-05-26 · 更新时间:2026-05-30 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端