Agenter Coder
Instead of writing code tool-by-tool (filling your context window with file
contents), delegate to a purpose-built coding agent that runs in its own
process. It has its own tools, validates its output with AST parsing, and
comes back with structured results. Your context stays clean.
Why this instead of coding directly
- - Your context window stays clean. The sub-agent does all the file
reading, editing, and bash execution in its own process. You only see
the final result.
- - Automatic validation and retry. Every iteration runs AST syntax checks
(and optional Bandit security scans). If code has errors, the agent retries
automatically — no manual back-and-forth.
- - Hard budget enforcement. Set a dollar limit, token limit, or time limit.
The agent stops when it hits the cap — no surprise bills.
- - Backend portability. Same interface whether you're using Claude, GPT, or
open-source models. Switch with one flag.
When to use
Use this skill when the user asks to:
- - Write, create, or generate code for a project
- Modify, refactor, or update existing code
- Fix bugs in a codebase
- Create entire applications or components
- Generate tests for existing code
Do NOT use for: reading files, explaining code, or answering questions. Use
your own tools for those — they don't need a sub-agent.
How to run
CODEBLOCK0
Parameters
| Flag | Required | Default | Description |
|---|
| INLINECODE0 | Yes | — | The coding task. Be specific about what to build. |
| INLINECODE1 |
Yes | — | Working directory. Use the current workspace or a subdirectory. |
|
--backend | No |
anthropic-sdk | Runtime:
anthropic-sdk,
claude-code,
codex, or
openhands. |
|
--model | No | auto | Model override (e.g.,
claude-sonnet-4-20250514,
gpt-5.4). |
|
--max-cost-usd | No | unlimited | Maximum spend in USD. |
|
--max-tokens | No | unlimited | Maximum total tokens (input + output). |
|
--max-time-seconds | No | unlimited | Maximum wall clock time. |
|
--max-iterations | No |
5 | Max validation/retry iterations. |
|
--allowed-write-paths | No | all in cwd | Glob patterns for allowed writes (e.g.,
"*.py" "*.ts"). |
|
--sandbox /
--no-sandbox | No |
--sandbox | Sandboxed execution (recommended). |
|
--stream | No | off | Emit NDJSON progress events for real-time updates. |
Cost awareness
Set budget limits based on task complexity. Always tell the user the estimated cost.
| Task type | Suggested INLINECODE22 | Suggested INLINECODE23 |
|---|
| Simple script / single file | 0.50 | 3 |
| Small app / multiple files |
2.00 | 5 |
| Complex refactoring / full project | 5.00 | 7 |
Backend selection
Default to anthropic-sdk unless the user asks for a specific backend. Check
{SKILL_DIR}/references/backends.md if the user asks about backend differences.
- - anthropic-sdk — Default. Claude Sonnet/Opus. Works with
ANTHROPIC_API_KEY or AWS Bedrock. - claude-code — Claude Code CLI runtime. Native OS-level sandbox, battle-tested file tools.
- codex — OpenAI's gpt-5.4/gpt-5.4-mini. Requires
OPENAI_API_KEY. - openhands — Any model via litellm (including local). Must use
--no-sandbox.
Reading the output
The script outputs JSON to stdout:
CODEBLOCK1
Status values
| Status | Meaning | What to do |
|---|
| INLINECODE29 | Task succeeded, files written to disk. | Report summary and files to user. |
| INLINECODE30 |
Task succeeded but used more resources than configured. | Report success + warn about cost. |
|
budget_exceeded | Stopped because budget ran out before completion. | Tell user, ask if they want to retry with higher budget. |
|
refused | The model refused the request (safety/policy). | Report refusal reason to user. |
|
failed | Unrecoverable error. | Report error, suggest checking logs. |
After running
- 1. Check the
status field. - If
completed: the files are already written to disk in --cwd. Use read to
inspect them if the user wants to review.
- 3. Report the summary, cost, and files modified to the user.
- If
failed or budget_exceeded: report the issue and ask how to proceed.
Agenter Coder
与其逐个工具地编写代码(用文件内容填满你的上下文窗口),不如将任务委托给一个在独立进程中运行的专业编码代理。它拥有自己的工具,通过AST解析验证输出,并返回结构化结果。你的上下文保持干净。
为什么使用它而不是直接编码
- - 你的上下文窗口保持干净。 子代理在其自己的进程中进行所有文件读取、编辑和bash执行。你只看到最终结果。
- 自动验证和重试。 每次迭代都会运行AST语法检查(以及可选的Bandit安全扫描)。如果代码有错误,代理会自动重试——无需手动来回操作。
- 硬性预算限制。 设置美元限额、令牌限额或时间限额。代理在达到上限时停止——不会有意外的账单。
- 后端可移植性。 无论你使用Claude、GPT还是开源模型,接口相同。只需一个标志即可切换。
何时使用
当用户要求以下内容时使用此技能:
- - 为项目编写、创建或生成代码
- 修改、重构或更新现有代码
- 修复代码库中的错误
- 创建完整的应用程序或组件
- 为现有代码生成测试
不要用于:读取文件、解释代码或回答问题。使用你自己的工具来处理这些——它们不需要子代理。
如何运行
bash
python3 {SKILLDIR}/scripts/agentercli.py \
--prompt <编码任务> \
--cwd <工作目录> \
--backend anthropic-sdk \
--max-cost-usd 2.0 \
--max-iterations 5 \
--sandbox
参数
| 标志 | 必需 | 默认值 | 描述 |
|---|
| --prompt | 是 | — | 编码任务。具体说明要构建什么。 |
| --cwd |
是 | — | 工作目录。使用当前工作区或子目录。 |
| --backend | 否 | anthropic-sdk | 运行时:anthropic-sdk、claude-code、codex或openhands。 |
| --model | 否 | 自动 | 模型覆盖(例如claude-sonnet-4-20250514、gpt-5.4)。 |
| --max-cost-usd | 否 | 无限制 | 最大花费(美元)。 |
| --max-tokens | 否 | 无限制 | 最大总令牌数(输入+输出)。 |
| --max-time-seconds | 否 | 无限制 | 最大挂钟时间。 |
| --max-iterations | 否 | 5 | 最大验证/重试迭代次数。 |
| --allowed-write-paths | 否 | cwd中的所有 | 允许写入的全局模式(例如
.py .ts)。 |
| --sandbox / --no-sandbox | 否 | --sandbox | 沙盒执行(推荐)。 |
| --stream | 否 | 关闭 | 发出NDJSON进度事件以实现实时更新。 |
成本意识
根据任务复杂度设置预算限制。始终告知用户预估成本。
| 任务类型 | 建议的 --max-cost-usd | 建议的 --max-iterations |
|---|
| 简单脚本/单个文件 | 0.50 | 3 |
| 小型应用/多个文件 |
2.00 | 5 |
| 复杂重构/完整项目 | 5.00 | 7 |
后端选择
默认使用anthropic-sdk,除非用户要求特定后端。如果用户询问后端差异,请查看{SKILL_DIR}/references/backends.md。
- - anthropic-sdk — 默认。Claude Sonnet/Opus。适用于ANTHROPICAPIKEY或AWS Bedrock。
- claude-code — Claude Code CLI运行时。原生操作系统级沙盒,经过实战检验的文件工具。
- codex — OpenAI的gpt-5.4/gpt-5.4-mini。需要OPENAIAPIKEY。
- openhands — 通过litellm支持任何模型(包括本地模型)。必须使用--no-sandbox。
读取输出
脚本输出JSON到标准输出:
json
{
status: completed,
summary: 使用FastAPI应用和test_main.py创建了main.py,
filesmodified: [main.py, testmain.py],
files: {main.py: ..., test_main.py: ...},
iterations: 2,
total_tokens: 15000,
totalcostusd: 0.045,
totaldurationseconds: 12.3
}
状态值
| 状态 | 含义 | 操作 |
|---|
| completed | 任务成功,文件已写入磁盘。 | 向用户报告摘要和文件。 |
| completedwithlimit_exceeded |
任务成功但使用了超过配置的资源。 | 报告成功并警告成本。 |
| budget_exceeded | 因预算耗尽而停止,未完成。 | 告知用户,询问是否想以更高预算重试。 |
| refused | 模型拒绝请求(安全/策略)。 | 向用户报告拒绝原因。 |
| failed | 不可恢复的错误。 | 报告错误,建议检查日志。 |
运行后
- 1. 检查status字段。
- 如果为completed:文件已写入--cwd指定的磁盘位置。如果用户想审查,使用read检查它们。
- 向用户报告摘要、成本和修改的文件。
- 如果为failed或budget_exceeded:报告问题并询问如何继续。