关于 sub-agents
sub-agents 是用于创建和管理独立上下文专用 AI Agent 的参考技能,涵盖配置、内置 Agent、模型选择与串联,并介绍菜单、文件和命令行操作。
主要功能
- 01创建独立上下文的 Agent
- 02配置工具与模型
- 03使用内置 Agent 类型
- 04通过菜单、文件或命令行管理
- 05恢复并串联 Agent
适用场景
- 01设置专职代码审查 Agent
- 02为任务选择模型
- 03限制 Agent 可用工具
- 04串联分析与实现 Agent
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ parcadei/ continuous-claude-v3 --skill sub-agents安装后在 Claude Code 中输入/sub-agents确认已加载。
详细介绍
子 Agent 参考
为特定任务创建上下文隔离的专用 AI Agent。
适用场景
- “如何创建子 Agent?”
- “配置 Agent 工具”
- “有哪些内置 Agent?”
- “Agent 模型选择”
- “Agent 链式调用模式”
快速开始
交互式(推荐)
/agents
打开菜单以创建、编辑和管理 Agent。
手动创建
mkdir -p .claude/agents
cat > .claude/agents/reviewer.md << 'EOF'
---
name: reviewer
description: Code review specialist. Use proactively after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a senior code reviewer focusing on quality and security.
## Review Checklist
- Code clarity and naming
- Error handling
- Security vulnerabilities
- Test coverage
EOF
基于 CLI
claude --agents '{
"reviewer": {
"description": "Code reviewer",
"prompt": "Review for quality and security",
"tools": ["Read", "Bash"],
"model": "sonnet"
}
}'
Agent 文件格式
---
name: agent-name
description: When/why to use this agent
tools: Read, Edit, Bash # Optional, inherits all if omitted
model: sonnet # sonnet, haiku, claude-opus-4-5-20251101, inherit
---
System prompt content here...
配置字段
| 字段 | 必填 | 选项 |
|---|---|---|
name | 是 | 小写字母、连字符 |
description | 是 | 使用场景 |
tools | 否 | 工具列表(省略时继承所有工具) |
model | 否 | sonnet、haiku、claude-opus-4-5-20251101、inherit |
内置 Agent
| Agent | 模型 | 工具 | 用途 |
|---|---|---|---|
| 通用 | Sonnet | 所有 | 复杂的多步骤任务 |
| 规划 | Sonnet | 只读 | 规划模式下的研究 |
| 探索 | Haiku | 只读 | 快速搜索代码库 |
模型选择
| 模型 | 速度 | 最适合 |
|---|---|---|
| Haiku | 最快 | 搜索、快速查询 |
| Sonnet | 快 | 大多数任务(默认) |
| Opus | 较慢 | 复杂推理 |
工具组合
# Code Reviewer (read-only)
tools: Read, Grep, Glob, Bash
# Debugger
tools: Read, Edit, Bash, Grep, Glob
# Implementer
tools: Read, Write, Edit, Bash, Glob
Agent 示例
代码审查员
---
name: code-reviewer
description: Reviews code for quality and security. Use after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
---
Review code for:
- Security vulnerabilities
- Code quality issues
- Missing error handling
- Test coverage gaps
Output findings by priority: Critical > Warning > Suggestion
调试器
---
name: debugger
description: Debug errors and test failures.
tools: Read, Edit, Bash, Grep, Glob
model: inherit
---
Debugging process:
1. Capture error details
2. Identify failure location
3. Form hypotheses
4. Test and verify
5. Implement fix
文件位置
| 类型 | 位置 | 优先级 |
|---|---|---|
| 项目 | .claude/agents/ | 最高 |
| 用户 | ~/.claude/agents/ | 较低 |
高级模式
可恢复的 Agent
[Agent returns agentId: "abc123"]
# Later: resume with context
claude -r "abc123" "Continue analysis"
Agent 链式调用
Use code-analyzer to find issues,
then use optimizer to fix them
最佳实践
- 职责单一 - 每个 Agent 只负责一个明确的用途
- 限制工具 - 只授予所需工具
- 描述清晰 - 以行动为导向,并包含“proactively”
- 版本控制 - 将
.claude/agents/纳入 git 版本控制
评论
支持 Markdown