snapedit
Snapshot-based file editing for AI agents. Enables safe file edits by sending only new content against immutable, content-addressed snapshots with 3-way merging and ambiguity protection.
README
snapedit
Snapshot-based file editing for AI agents — send only the NEW content, never the old block.
snapedit lets an editing agent (Claude Code, OpenCode, or any MCP client)
edit files by sending only the new content — never the old text. Files are
captured as immutable, content-addressed snapshots; edits reference the
snapshot's 1-based line numbers, so lines shifted by prior edits elsewhere
never silently misapply.
Agent snapedit Filesystem
│ read_snapshot(path) │
├────────────────────────────────►│ sha256(bytes) → blob_id
│◄── blob_id + numbered page ────┤
│ │ …(agent thinks)…
│ apply_snapshot_patch(blob, │
│ from, to, NEW_CONTENT) ──────►│ base=snapshot · ours=live
│ │ 3-way merge OR splice
│◄── ok:true / conflict / err ────┤
│ │ atomic write + lock
Why
Direct rewrite tools force the agent to transmit the old text to locate a
change; when a file changes between reads, misalignment silently corrupts
files. snapedit replaces that with:
- Immutable snapshots —
blob_id = sha256(bytes). The agent carries only the id; content is never re-sent. - 3-way merge on apply — base = snapshot, ours = live file. Earlier edits (even insertions above the hunk) are preserved; the patch lands exactly where the snapshot said it should.
- Explicit conflicts — if the live file changed inside the hunk with different content, no write happens; a structured conflict is returned with previews of both sides.
- Safety over guesswork — ambiguous patches (hunk text duplicated in the live file) are refused with zero writes, never silently applied to the wrong occurrence.
- No shell transport — all bodies travel over stdio MCP (JSON-RPC lines). Large files are paged, never truncated by a shell.
Features
| Feature | Details |
|---|---|
| Content-addressed store | ~/.snapedit/blobs, sha256 verified on read, recency index |
| Cross-process safety | advisory locks, EEXIST-tolerant writes, stale-lock recovery |
| Concurrency | parallel edits: disjoint ranges both land; same range → clean conflict |
| Ambiguity safety | duplicated hunk text ⇒ refused, file proven byte-identical |
| Store GC | snapedit store prune [--days N] [--dry-run] (blobs never garbage-collected automatically) |
| Zero dependencies | plain Node.js ≥ 18, ESM |
Install
git clone https://github.com/rianprei/snapedit.git
cd snapedit
npm test # 55 tests, no deps required
npm link # optional: expose `snapedit` on PATH
Quick start (CLI)
# snapshot + numbered page (default page 0, 300 lines)
snapedit read path/to/file.txt
# apply NEW content to snapshot lines 2..4 (1-based, inclusive)
snapedit apply path/to/file.txt <blob_id> 2 4 --content $'wrote new lines\n'
# where does the hunk map in the live file today?
snapedit locate path/to/file.txt <blob_id> 2 4
# run the MCP server over stdio
snapedit mcp
Claude Code configuration
Add an MCP server entry (Claude Code ~/.claude.json, or OpenCode's "type": "local" MCP):
{
"mcpServers": {
"snapedit": {
"command": "/abs/path/to/snapedit/bin/snapedit",
"args": ["mcp"]
}
}
}
Agent edit protocol (keep this short)
read_snapshot(page containing region) — rememberblob_id.apply_snapshot_patch(path, blob_id, from, to, new_content).ok:true→ done.mode:"conflict"→ re-read_snapshot, retry on the new snapshot.kind:"snapshot_missing"→ re-read_snapshot.
- Never send the old text; never concatenate whole-file bodies yourself.
new_content is the exact replacement for snapshot lines [from..to]
(1-based, inclusive). Multi-line edits work as a single new_content; the
merge replays the hunk in snapshot coordinates, so earlier shifts don't break
it.
Documentation
- Protocol — full JSON-RPC tool contracts, results, errors
- Architecture — modules, data flow, concurrency model
- Safety & invariants — ambiguity gate, conflict rules, corruption defenses, GC, locking
- Changelog
- Contributing
Security
See docs/SAFETY.md for the full property list. Highlights:
- Refuses ambiguous applies deterministically (
match_count != 1 → write == false, proven byte-identical by sha256 in tests). - Path-like
blob_ids rejected (no filesystem traversal via the store). - MCP input validation: malformed JSON-RPC →
-32600, invalid tool args →bad_arg, never a crash of the server. - Atomic write: temp file in same dir +
rename→ readers never observe partial content.
License
MIT — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。