amp-code — Delegate Coding Tasks to Sourcegraph Amp
Use this skill to hand off coding work to Amp, an autonomous coding agent.
Amp can read, write, refactor, and test code across an entire codebase without supervision.
When to delegate to Amp
Delegate when the task involves:
- - Multi-file changes — refactoring, moving modules, updating APIs
- New features — implementing something that requires creating/editing several files
- Bug fixes — especially when the root cause requires investigation and code changes
- Test writing — generating test suites, adding coverage
- Anything > ~5 min of coding — if you'd need multiple edit calls, let Amp do it
Do NOT delegate:
- - Simple single-line edits (just use
edit) - Purely diagnostic/read-only questions (just use
exec/read) - Tasks where you need fine-grained control over each file change
Modes
| Mode | Description | Use when |
|---|
| INLINECODE3 | Fast, lightweight model | Small/clear tasks, quick fixes |
| INLINECODE4 |
Balanced model (default) | Most tasks |
|
deep | Powerful model, slower, higher cost | Complex architecture, hard bugs |
How to run a task
Simple one-shot (recommended)
CODEBLOCK0
The -x flag (execute mode) makes amp non-interactive: it runs the task and exits,
printing only the agent's final message to stdout.
Using the wrapper script
CODEBLOCK1
The script handles: cd to project dir, thread creation (for auditability), execute mode,
and clean output. It prints the thread ID and final agent response.
Key flags
| Flag | Effect |
|---|
| INLINECODE8 | No confirmation prompts — agent acts autonomously |
| INLINECODE9 |
Suppress sound/system notifications |
|
--no-ide | Don't connect to IDE (safe for headless runs) |
|
-x "message" | Execute mode: non-interactive, prints final output |
|
-m rush/smart/deep | Select agent mode (model + system prompt) |
|
-l "label" | Tag the thread with a label (repeatable) |
Working directory matters
Amp reads the codebase from the current directory. Always cd to the project root first,
or pass --dir to the wrapper script. Without the right cwd, Amp won't see the right files.
Checking results
After a run, the wrapper script outputs:
- 1. The thread ID — use this to inspect or continue the conversation
- The final agent message — summary of what was done
To see the full thread as markdown (all messages, tool calls, etc.):
CODEBLOCK2
To continue a thread (e.g., to follow up or fix something):
CODEBLOCK3
To list recent threads:
amp threads list
Example invocations
One-shot fix
CODEBLOCK5
Feature implementation (via wrapper)
CODEBLOCK6
Deep refactor
CODEBLOCK7
Quick test generation
bash {baseDir}/scripts/amp-task.sh \
--task "Write Jest unit tests for all functions in src/utils/formatting.js" \
--dir /path/to/your/project \
--mode rush
Notes
- - Amp commits are tagged with
Amp-Thread: trailer in git. Use this to find amp-authored commits. - The
--dangerously-allow-all flag bypasses all tool permission checks. Only use on trusted projects. - Amp may make mistakes. Review the diff after large changes: INLINECODE18
- For very long tasks, amp may time out. Break into smaller sub-tasks if needed.
- Thread IDs are UUIDs. Save them if you want to audit or continue work later.
amp-code — 将编码任务委托给 Sourcegraph Amp
使用此技能将编码工作交给自主编码代理 Amp 处理。
Amp 能够无需监督地读取、编写、重构和测试整个代码库中的代码。
何时委托给 Amp
当任务涉及以下内容时进行委托:
- - 多文件更改 — 重构、移动模块、更新 API
- 新功能 — 实现需要创建/编辑多个文件的功能
- Bug 修复 — 特别是当根本原因需要调查和代码更改时
- 编写测试 — 生成测试套件、增加覆盖率
- 任何超过约 5 分钟的编码工作 — 如果需要多次编辑调用,让 Amp 来处理
不要委托:
- - 简单的单行编辑(直接使用 edit)
- 纯诊断/只读问题(直接使用 exec/read)
- 需要对每个文件更改进行精细控制的任务
模式
| 模式 | 描述 | 使用场景 |
|---|
| rush | 快速、轻量级模型 | 小型/明确的任务、快速修复 |
| smart |
平衡模型(默认) | 大多数任务 |
| deep | 强大模型,较慢,成本较高 | 复杂架构、棘手 Bug |
如何运行任务
简单一次性执行(推荐)
bash
cd /path/to/project && \
amp \
--dangerously-allow-all \
--no-notifications \
--no-ide \
-m smart \
-x 在此处填写任务描述
-x 标志(执行模式)使 amp 以非交互方式运行:执行任务后退出,
仅将代理的最终消息输出到标准输出。
使用包装脚本
bash
bash {baseDir}/scripts/amp-task.sh \
--task 为 /invoices 端点添加分页功能 \
--dir /path/to/your/project \
--mode smart
该脚本处理:切换到项目目录、创建线程(用于可审计性)、执行模式
以及干净输出。它会输出线程 ID 和最终的代理响应。
关键标志
| 标志 | 效果 |
|---|
| --dangerously-allow-all | 无确认提示 — 代理自主行动 |
| --no-notifications |
抑制声音/系统通知 |
| --no-ide | 不连接 IDE(安全用于无头运行) |
| -x 消息 | 执行模式:非交互式,输出最终结果 |
| -m rush/smart/deep | 选择代理模式(模型 + 系统提示) |
| -l 标签 | 为线程添加标签(可重复) |
工作目录很重要
Amp 从当前目录读取代码库。务必先 cd 到项目根目录,
或向包装脚本传递 --dir 参数。如果工作目录不正确,Amp 将无法找到正确的文件。
检查结果
运行后,包装脚本会输出:
- 1. 线程 ID — 使用此 ID 查看或继续对话
- 最终代理消息 — 已完成工作的摘要
要查看完整线程的 Markdown 格式(所有消息、工具调用等):
bash
amp threads markdown <线程ID>
要继续线程(例如,跟进或修复某些内容):
bash
cd /path/to/project && \
echo 现在也为分页逻辑添加测试 | \
amp threads continue <线程ID> \
--dangerously-allow-all --no-notifications --no-ide -x
要列出最近的线程:
bash
amp threads list
调用示例
一次性修复
bash
cd /path/to/your/project && \
amp --dangerously-allow-all --no-notifications --no-ide -x \
修复 src/api/invoices.js 第 42 行的 TypeError — amount 有时为 null
功能实现(通过包装脚本)
bash
bash {baseDir}/scripts/amp-task.sh \
--task 为发票列表页面实现 CSV 导出功能 — 在 UI 中添加按钮和 /api/invoices/export 端点 \
--dir /path/to/your/project \
--mode smart
深度重构
bash
bash {baseDir}/scripts/amp-task.sh \
--task 将所有数据库调用从原始 SQL 迁移到 Knex 查询构建器。保持现有行为,添加注释。 \
--dir /path/to/your/project \
--mode deep
快速测试生成
bash
bash {baseDir}/scripts/amp-task.sh \
--task 为 src/utils/formatting.js 中的所有函数编写 Jest 单元测试 \
--dir /path/to/your/project \
--mode rush
注意事项
- - Amp 的提交会在 git 中用 Amp-Thread: 尾部标记。使用此标记查找 amp 编写的提交。
- --dangerously-allow-all 标志会绕过所有工具权限检查。仅在受信任的项目上使用。
- Amp 可能会出错。在大型更改后检查差异:git diff HEAD~1
- 对于非常长的任务,amp 可能会超时。如有必要,将其分解为较小的子任务。
- 线程 ID 是 UUID。保存它们以便日后审计或继续工作。