简介
Amp 是 Sourcegraph 的 AI 编码 agent,编辑之前先读 整个 仓库。Cursor 和 Claude Code 靠单文件上下文窗口,Amp 查 Sourcegraph 预索引的代码图谱 —— 符号引用、类型层级、依赖关系 —— 给每次编辑做接地。适合 monorepo 重构和任何单上下文窗口装不下的代码库。兼容终端 CLI + VS Code 扩展 + Sourcegraph 网页版。装机时间 5 分钟(Sourcegraph 账号 + API token)。
Amp 跟其他工具的根本区别
多数 AI 编码工具靠"把文件塞进上下文窗口"来近似"看到整个代码库"。Amp 不近似 —— Sourcegraph 本身已经把你的仓库索引好了(符号、引用、类型、历史),Amp 直接查这个索引。
具体说:
- 你说"把
getUser重命名成fetchUser",Amp 用 符号引用,不是文本搜索。注释和字符串里的getUser不会被误改。 - 你问"这个函数在哪被调用",Amp 从图谱返回真实调用点,不是 regex 匹配。
- 你要求重构,Amp 先读类型层级再提改动,尊重接口和覆盖关系。
CLI 用法
# 装
brew install sourcegraph/amp/amp
# 认证(弹浏览器)
amp auth login
# 在当前仓库跑任务
amp "Refactor the User type to add a 'plan' field. Update all call sites."
# 在某个 Sourcegraph 已索引的仓库跑(不用 clone)
amp --repo github.com/sourcegraph/sourcegraph "List all uses of the deprecated AuthService"把 Amp 接到 Claude Code 或 Cursor
Amp 自带 MCP server。加到你的 MCP 配置:
{
"mcpServers": {
"sourcegraph": {
"command": "amp",
"args": ["mcp"],
"env": { "SRC_ACCESS_TOKEN": "your-token" }
}
}
}之后 Claude Code / Cursor / Codex CLI 就能调用 sourcegraph_search / sourcegraph_symbol_references / sourcegraph_blame —— 把你的仓库图谱当成工具用。
什么时候选 Amp 而不是 Cursor / Claude Code
- 你的代码库 >100 万行,任何上下文窗口都装不下
- 你需要尊重真实符号引用的重构,不是 regex
- 你要团队成员答案一致(大家查同一个索引图谱)
FAQ
Q: Amp 免费吗? A: Sourcegraph 有免费档(限索引仓库数)。Pro 套餐和 Amp coding agent 是订阅制。价格见 sourcegraph.com/pricing。
Q: 没 Sourcegraph 账号能用 Amp 吗? A: 不能。Amp 查的是 Sourcegraph 代码图谱,需要 Sourcegraph 先索引你的仓库。单仓库不需要索引时,Cursor / Claude Code 更简单。
Q: 私有仓库能用 Amp 吗? A: 可以。Sourcegraph 自托管和云版本都支持私有仓库。Amp 通过 SRC_ACCESS_TOKEN 鉴权,只能访问你有权限的仓库。