S1哥 今日赠品 · 2026-11-02
配套教程:待补
来源:Anthropic 官方文档《Create custom subagents》前半部分。英文提示词和文件内容是官方示例原文,带“模板”的是 S1哥 按官方思路整理,把 <> 里换成你自己的。
一、官方 Quickstart 提示词(直接贴给 Claude Code)
Create a personal code-improver subagent in ~/.claude/agents/ that scans files and suggests improvements for readability, performance, and best practices. It should explain each issue, show the current code, and provide an improved version. Make it read-only and have it use Sonnet.
模板:Create a <personal 或 project> <名字> subagent in <~/.claude/agents/ 或 .claude/agents/> that <它要做什么>. Make it read-only and have it use <sonnet 或 haiku>.
二、官方示例文件(~/.claude/agents/code-improver.md)
---
name: code-improver
description: Scans files and suggests improvements for readability, performance, and best practices. Use after writing or modifying code.
tools: Read, Grep, Glob
model: sonnet
---
You are a code improvement specialist. For each issue you find, explain
the problem, show the current code, and provide an improved version.
三、试用
Use the code-improver agent to suggest improvements in this project
成功标志:记录里出现 code-improver(Suggest code improvements) 这样的一行。
四、作用域速查(优先级从高到低,同名取高的)
1 托管设置:整个组织
2 --agents 命令行参数:只在当前会话,不存盘
3 .claude/agents/:当前项目,建议提交进版本控制
4 ~/.claude/agents/:你所有的项目
5 插件的 agents 目录:插件启用的地方,优先级最低
五、官方自带子代理
Explore:只读,搜索和分析代码;调用时分 quick、medium、very thorough 三档;默认不带 CLAUDE.md 和 git 状态
Plan:计划模式下收集上下文;只读
General-purpose:全部工具,复杂多步操作
想让 Explore 更便宜:自建同名 Explore 子代理并写 model: haiku
六、命令行临时子代理(官方示例,只在这次会话有效)
claude --agents '{
"code-reviewer": {
"description": "Expert code reviewer. Use proactively after code changes.",
"prompt": "You are a senior code reviewer. Focus on code quality, security, and best practices.",
"tools": ["Read", "Grep", "Glob", "Bash"],
"model": "sonnet"
}
}'
七、避坑清单
1. 子代理也发自己的请求,算进同一份用量额度
2. 自建子代理的描述加起来超过 15,000 token,启动会警告:把 description 写短,细节放进系统提示词
3. ~/.claude/agents/ 如果在会话开始前不存在,新建后要重启 Claude Code
4. 同一棵树下 name 要唯一,否则只加载一个
5. 插件子代理不支持 hooks、mcpServers、permissionMode,要用就把文件复制到 .claude/agents/
6. 先用自带的 Explore 和 Plan,在同一类活上反复写同样提示词时,再建自己的