Loading...
Loading...
Compare original and translation side by side
Experimental: Agent teams require theflag and may change between Claude Code versions.--enable-teams
实验性功能:Agent 团队需要使用参数,且在不同 Claude Code 版本之间可能发生变动。--enable-teams
| Use agent teams when... | Use subagents instead when... |
|---|---|
| Multiple agents need to work in parallel | Tasks are sequential and interdependent |
| Ongoing communication between agents is needed | One focused task produces one result |
| Background tasks need progress reporting | Agent output feeds directly into next step |
| Complex workflows benefit from task coordination | Simple, bounded, isolated execution |
| Independent changes to the same codebase (with worktrees) | Context sharing is fine and efficient |
| 当出现以下情况时使用Agent团队 | 当出现以下情况时改用子Agent |
|---|---|
| 多个Agent需要并行工作 | 任务为顺序执行且相互依赖 |
| 需要Agent之间持续通信 | 单个聚焦任务仅产出一个结果 |
| 后台任务需要上报进度 | Agent输出直接作为下一步的输入 |
| 复杂工作流需要任务协调 | 执行简单、有边界、相互隔离的任务 |
| 对同一代码库进行独立变更(使用worktree) | 上下文共享高效且无问题 |
Lead Agent (orchestrator)
├── TeamCreate — creates team + shared task list
├── Task tool — spawns teammate agents
├── SendMessage — communicates with teammates
├── TaskUpdate — assigns tasks to teammates
└── Teammates (run in parallel)
├── Read team config from ~/.claude/teams/<name>/config.json
├── TaskList/TaskUpdate — claim and complete tasks
└── SendMessage — report back to leadLead Agent (orchestrator)
├── TeamCreate — creates team + shared task list
├── Task tool — spawns teammate agents
├── SendMessage — communicates with teammates
├── TaskUpdate — assigns tasks to teammates
└── Teammates (run in parallel)
├── Read team config from ~/.claude/teams/<name>/config.json
├── TaskList/TaskUpdate — claim and complete tasks
└── SendMessage — report back to lead| Tool | Purpose |
|---|---|
| Create team and shared task list directory |
| Clean up team when all work is complete |
| Send DMs, broadcasts, shutdown requests, plan approvals |
| Get output from a background agent |
| Stop a running background agent |
| 工具 | 用途 |
|---|---|
| 创建团队和共享任务列表目录 |
| 所有工作完成后清理团队资源 |
| 发送私信、广播、关闭请求、方案审批 |
| 获取后台Agent的输出 |
| 停止运行中的后台Agent |
TeamCreate({
team_name: "my-project",
description: "Working on feature X"
})~/.claude/teams/<team-name>/~/.claude/tasks/<team-name>/TeamCreate({
team_name: "my-project",
description: "Working on feature X"
})~/.claude/teams/<team-name>/~/.claude/tasks/<team-name>/TaskCreate({
team_name: "my-project",
title: "Implement security review",
description: "Audit auth module for vulnerabilities",
status: "pending"
})TaskCreate({
team_name: "my-project",
title: "Implement security review",
description: "Audit auth module for vulnerabilities",
status: "pending"
})Agent tool with:
subagent_type: "agents-plugin:security-audit"
team_name: "my-project"
name: "security-reviewer"
prompt: "Join team my-project and work on security review task..."Agent tool with:
subagent_type: "agents-plugin:security-audit"
team_name: "my-project"
name: "security-reviewer"
prompt: "Join team my-project and work on security review task..."TaskUpdate({
team_name: "my-project",
task_id: "task-1",
owner: "security-reviewer",
status: "in_progress"
})TaskUpdate({
team_name: "my-project",
task_id: "task-1",
owner: "security-reviewer",
status: "in_progress"
})| State | Meaning |
|---|---|
| Not yet started |
| Assigned and active (one at a time per teammate) |
| Finished successfully |
| Waiting on another task |
| 状态 | 含义 |
|---|---|
| 尚未启动 |
| 已分配且正在处理(每个成员同一时间仅处理一个任务) |
| 已成功完成 |
| 等待其他任务完成 |
TaskListTaskList({ team_name: "my-project" })
→ Returns all tasks with status, owner, and blocked-by infoTaskUpdate({ team_name: "my-project", task_id: "N", owner: "my-name" })TaskListTaskList({ team_name: "my-project" })
→ Returns all tasks with status, owner, and blocked-by infoTaskUpdate({ team_name: "my-project", task_id: "N", owner: "my-name" })| Type | Use When |
|---|---|
| Direct message to a specific teammate |
| Critical team-wide announcement (use sparingly — expensive) |
| Ask a teammate to gracefully exit |
| Approve or reject a shutdown request |
| Approve or reject a teammate's plan |
| 类型 | 使用场景 |
|---|---|
| 给特定成员发送私信 |
| 重要的全团队公告(谨慎使用——成本较高) |
| 请求成员优雅退出 |
| 同意或拒绝关闭请求 |
| 同意或拒绝成员的方案 |
SendMessage({
type: "message",
recipient: "security-reviewer", // Use NAME, not agent ID
content: "Please also check the payment module",
summary: "Adding payment module to scope"
})SendMessage({
type: "message",
recipient: "security-reviewer", // Use NAME, not agent ID
content: "Please also check the payment module",
summary: "Adding payment module to scope"
})SendMessage({
type: "broadcast",
content: "Stop all work — critical blocker found in auth module",
summary: "Critical blocker: halt work"
})SendMessage({
type: "broadcast",
content: "Stop all work — critical blocker found in auth module",
summary: "Critical blocker: halt work"
})Read ~/.claude/teams/<team-name>/config.json
→ members array with name, agentId, agentTyperecipientRead ~/.claude/teams/<team-name>/config.json
→ members array with name, agentId, agentTyperecipientin_progressTaskUpdateSendMessageSendMessagein_progressTaskUpdateSendMessageSendMessageSendMessage({
type: "shutdown_request",
recipient: "security-reviewer",
content: "All tasks complete, wrapping up"
})SendMessage({
type: "shutdown_request",
recipient: "security-reviewer",
content: "All tasks complete, wrapping up"
})SendMessage({
type: "shutdown_response",
request_id: "<id from shutdown_request JSON>",
approve: true
})SendMessage({
type: "shutdown_response",
request_id: "<id from shutdown_request JSON>",
approve: true
})TeamDelete()
→ Removes ~/.claude/teams/<name>/ and ~/.claude/tasks/<name>/TeamDelete()
→ Removes ~/.claude/teams/<name>/ and ~/.claude/tasks/<name>/TeamCreate: "code-review"
Tasks: security-audit, performance-review, correctness-check
Teammates: security-agent, performance-agent, correctness-agent (all parallel)
Lead: collects results, synthesizes findingsTeamCreate: "code-review"
Tasks: security-audit, performance-review, correctness-check
Teammates: security-agent, performance-agent, correctness-agent (all parallel)
Lead: collects results, synthesizes findingsTeamCreate: "feature-impl"
Tasks: backend-api, frontend-ui, tests
Teammates: each spawned with isolation: "worktree"
Lead: delegates git push (sub-agents must not push independently in sandbox)TeamCreate: "feature-impl"
Tasks: backend-api, frontend-ui, tests
Teammates: each spawned with isolation: "worktree"
Lead: delegates git push (sub-agents must not push independently in sandbox)blocked_byblocked_by| Role | Behavior | When to Use |
|---|---|---|
| Lead | Orchestrates, assigns tasks, receives results | Always — coordinates the team |
| Teammate | Parallel execution with messaging | Ongoing collaboration, progress reporting |
| Subagent | Focused, isolated, returns single result | Simple bounded tasks, no coordination needed |
| 角色 | 行为 | 使用场景 |
|---|---|---|
| 负责人(Lead) | 编排流程、分配任务、接收结果 | 始终需要——负责协调团队 |
| 团队成员(Teammate) | 并行执行任务,支持消息通信 | 持续协作、进度上报场景 |
| 子Agent(Subagent) | 聚焦、隔离执行,返回单个结果 | 简单有边界的任务,无需协调 |
CLAUDE_CODE_REMOTE=truegit pushCLAUDE_CODE_REMOTE=truegit push| Context | Approach |
|---|---|
| Quick parallel review | Spawn 2–4 teammates, broadcast task assignments |
| Large codebase split | Assign directory subsets as separate tasks |
| Long-running work | Background teammates, poll via TaskList |
| Minimize API cost | Prefer |
| Fast shutdown | Send shutdown_request to each teammate, then TeamDelete |
| 场景 | 方案 |
|---|---|
| 快速并行评审 | 生成2-4个成员,广播任务分配 |
| 大型代码库拆分 | 将不同目录子集分配为独立任务 |
| 长期运行工作 | 后台运行成员,通过TaskList轮询状态 |
| 最小化API成本 | 优先使用 |
| 快速关闭 | 向每个成员发送shutdown_request,然后执行TeamDelete |
TeamCreateTaskCreateteam_namenameTaskUpdateSendMessageSendMessage shutdown_requestTeamDeleteTeamCreateTaskCreateteam_namenameTaskUpdateSendMessageshutdown_requestTeamDelete| Path | Contents |
|---|---|
| Team members (name, agentId, agentType) |
| Shared task list directory |
| 路径 | 内容 |
|---|---|
| 团队成员信息(name、agentId、agentType) |
| 共享任务列表目录 |
| Mistake | Correct Approach |
|---|---|
| Using agentId as recipient | Use |
| Sending broadcast for every update | Use |
| Polling for messages | Messages delivered automatically — just wait |
| Sending JSON status messages | Use |
| Sub-agent pushes to remote | Delegate push to lead orchestrator |
| TeamDelete before shutdown | Shutdown all teammates first |
| 错误 | 正确做法 |
|---|---|
| 使用agentId作为收件人 | 使用config.json中的 |
| 每次更新都发送广播 | 单收件人通信使用 |
| 轮询获取消息 | 消息会自动投递——只需等待 |
| 发送JSON状态消息 | 状态更新使用 |
| 子Agent推送到远程仓库 | 将推送操作交给负责人编排器执行 |
| 关闭前执行TeamDelete | 先关闭所有成员 |
.claude/rules/agent-development.md.claude/rules/agentic-permissions.md.claude/rules/sandbox-guidance.md.claude/rules/agent-development.md.claude/rules/agentic-permissions.md.claude/rules/sandbox-guidance.md