agent-teams
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTable of Contents
目录
Agent Teams Coordination
Agent团队协调
Overview
概述
Claude Code Agent Teams enables multiple Claude CLI processes to collaborate on shared work through a filesystem-based coordination protocol. Each teammate runs as an independent process in a tmux pane, communicating via JSON files guarded by locks. No database, no daemon, no network layer.
claudefcntlThis skill provides the patterns for orchestrating agent teams effectively.
Claude Code Agent Teams 允许多个Claude CLI进程通过基于文件系统的协调协议协作完成共同任务。每个团队成员作为独立的进程运行在tmux窗格中,通过受锁保护的JSON文件进行通信。无需数据库、守护进程或网络层。
claudefcntl本技能提供了有效编排Agent团队的模式。
When To Use
适用场景
- Parallel implementation across multiple files or modules
- Multi-agent code review (one agent reviews, another implements fixes)
- Large refactoring requiring coordinated changes across subsystems
- Tasks with natural parallelism that benefit from concurrent agents
- 跨多个文件或模块的并行实现
- 多Agent代码评审(一个Agent评审,另一个实现修复)
- 需要跨子系统协调变更的大规模重构
- 具有天然并行性、可从并发Agent中获益的任务
When NOT To Use
不适用场景
- Single-file changes or small tasks (overhead exceeds benefit)
- Tasks requiring tight sequential reasoning (agents coordinate loosely)
- When CLI is not available or tmux is not installed
claude
- 单文件变更或小型任务(开销超过收益)
- 需要严格顺序推理的任务(Agent之间是松散协调)
- 无法使用CLI或未安装tmux的场景
claude
Prerequisites
前置条件
bash
undefinedbash
undefinedVerify Claude Code CLI
Verify Claude Code CLI
claude --version
claude --version
Verify tmux (required for split-pane mode)
Verify tmux (required for split-pane mode)
tmux -V
tmux -V
Enable experimental feature (set by spawner automatically)
Enable experimental feature (set by spawner automatically)
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
undefinedexport CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
undefinedProtocol Architecture
协议架构
~/.claude/
teams/<team-name>/
config.json # Team metadata + member roster
inboxes/
<agent-name>.json # Per-agent message queue
.lock # fcntl exclusive lock
tasks/<team-name>/
1.json ... N.json # Auto-incrementing task files
.lock # fcntl exclusive lockDesign principles:
- Filesystem is the database: JSON files, atomic writes via +
tempfileos.replace - fcntl locking: Prevents concurrent read/write corruption on inboxes and tasks
- Numbered tasks: Auto-incrementing IDs with sequential file naming
- Loose coupling: Agents poll their own inbox; no push notifications
~/.claude/
teams/<team-name>/
config.json # Team metadata + member roster
inboxes/
<agent-name>.json # Per-agent message queue
.lock # fcntl exclusive lock
tasks/<team-name>/
1.json ... N.json # Auto-incrementing task files
.lock # fcntl exclusive lock设计原则:
- 文件系统即数据库:JSON文件,通过+
tempfile实现原子写入os.replace - fcntl锁:防止收件箱和任务文件的并发读写损坏
- 编号任务:采用顺序文件命名的自增ID
- 松耦合:Agent轮询自己的收件箱,无需推送通知
Quick Start
快速入门
1. Create a Team
1. 创建团队
bash
undefinedbash
undefinedProgrammatic team setup (via MCP or direct API)
Programmatic team setup (via MCP or direct API)
Team config written to ~/.claude/teams/<team-name>/config.json
Team config written to ~/.claude/teams/<team-name>/config.json
The team config contains:
- `name`, `description`, `created_at` (ms timestamp)
- `lead_agent_id`, `lead_session_id`
- `members[]` — array of LeadMember and TeammateMember objects
团队配置包含:
- `name`、`description`、`created_at`(毫秒时间戳)
- `lead_agent_id`、`lead_session_id`
- `members[]` — 主管成员和团队成员对象的数组2. Spawn Teammates
2. 生成团队成员
Each teammate is a separate CLI process launched with identity flags:
claudebash
claude --agent-id "backend@my-team" \
--agent-name "backend" \
--team-name "my-team" \
--agent-color "#FF6B6B" \
--parent-session-id "$SESSION_ID" \
--agent-type "general-purpose" \
--model sonnetSee for tmux pane management and color assignment.
modules/spawning-patterns.md每个团队成员都是独立的 CLI进程,通过身份标识参数启动:
claudebash
claude --agent-id "backend@my-team" \
--agent-name "backend" \
--team-name "my-team" \
--agent-color "#FF6B6B" \
--parent-session-id "$SESSION_ID" \
--agent-type "general-purpose" \
--model sonnet请参考了解tmux窗格管理和颜色分配规则。
modules/spawning-patterns.md3. Create Tasks with Dependencies
3. 创建带依赖的任务
json
{
"id": "1",
"subject": "Implement API endpoints",
"description": "Create REST endpoints for user management",
"status": "pending",
"owner": null,
"blocks": ["3"],
"blocked_by": [],
"metadata": {}
}See for state machine and dependency management.
modules/task-coordination.mdjson
{
"id": "1",
"subject": "Implement API endpoints",
"description": "Create REST endpoints for user management",
"status": "pending",
"owner": null,
"blocks": ["3"],
"blocked_by": [],
"metadata": {}
}请参考了解状态机和依赖管理规则。
modules/task-coordination.md4. Coordinate via Messages
4. 通过消息协调
json
{
"from": "team-lead",
"text": "API endpoints are ready for integration testing",
"timestamp": "2026-02-07T22:00:00Z",
"read": false,
"summary": "API ready"
}See for message types and inbox operations.
modules/messaging-protocol.mdjson
{
"from": "team-lead",
"text": "API endpoints are ready for integration testing",
"timestamp": "2026-02-07T22:00:00Z",
"read": false,
"summary": "API ready"
}请参考了解消息类型和收件箱操作规则。
modules/messaging-protocol.mdCoordination Workflow
协调工作流
- — Initialize team config and directories
agent-teams:team-created - — Launch agents in tmux panes
agent-teams:teammates-spawned - — Create tasks with dependencies, assign owners
agent-teams:tasks-assigned - — Agents claim tasks, exchange messages, mark completion
agent-teams:coordination-active - — Graceful shutdown with approval protocol
agent-teams:team-shutdown
- — 初始化团队配置和目录
agent-teams:team-created - — 在tmux窗格中启动Agent
agent-teams:teammates-spawned - — 创建带依赖的任务,分配负责人
agent-teams:tasks-assigned - — Agent认领任务、交换消息、标记完成状态
agent-teams:coordination-active - — 遵循审批协议优雅关闭
agent-teams:team-shutdown
Crew Roles
团队角色
Each team member has a that determines their capabilities and task compatibility. Five roles are defined: (default), , , , and . Roles constrain which risk tiers an agent can handle — see for the full capability matrix and role-risk compatibility table.
roleimplementerresearchertesterreviewerarchitectmodules/crew-roles.md每个团队成员都有一个属性,决定其能力和任务适配性。共定义了5种角色:(默认)、、、和。角色会限制Agent可处理的风险等级 — 完整的能力矩阵和角色-风险适配表请参考。
roleimplementerresearchertesterreviewerarchitectmodules/crew-roles.mdHealth Monitoring
健康监控
Team members can be monitored for health via heartbeat messages and claim expiry. The lead polls team health every 60s with a 2-stage stall detection protocol (health_check probe + 30s wait). Stalled agents have their tasks released and are restarted or replaced following the "replace don't wait" doctrine. See for the full protocol and state machine.
modules/health-monitoring.md可通过心跳消息和认领过期机制监控团队成员的健康状态。主管每60秒轮询一次团队健康状态,采用两阶段停滞检测协议(health_check探测 + 30秒等待)。停滞的Agent的任务会被释放,系统会遵循「替换而非等待」的原则重启或替换该Agent。完整协议和状态机请参考。
modules/health-monitoring.mdModule Reference
模块参考
- team-management.md: Team lifecycle, config format, member management
- messaging-protocol.md: Message types, inbox operations, locking patterns
- task-coordination.md: Task CRUD, state machine, dependency cycle detection
- spawning-patterns.md: tmux spawning, CLI flags, pane management
- crew-roles.md: Role taxonomy, capability matrix, role-risk compatibility
- health-monitoring.md: Heartbeat protocol, stall detection, automated recovery
- team-management.md:团队生命周期、配置格式、成员管理
- messaging-protocol.md:消息类型、收件箱操作、锁模式
- task-coordination.md:任务CRUD、状态机、依赖循环检测
- spawning-patterns.md:tmux生成、CLI参数、窗格管理
- crew-roles.md:角色分类、能力矩阵、角色-风险适配
- health-monitoring.md:心跳协议、停滞检测、自动恢复
Integration with Conjure
与Conjure集成
Agent Teams extends the conjure delegation model:
| Conjure Pattern | Agent Teams Equivalent |
|---|---|
| |
| |
| |
| External LLM execution | Teammate agent execution |
Use first to determine if the task benefits from multi-agent coordination vs. single-service delegation.
Skill(conjure:delegation-core)Agent Teams扩展了conjure委托模型:
| Conjure模式 | Agent Teams对应项 |
|---|---|
| |
| |
| |
| 外部LLM执行 | 团队成员Agent执行 |
请先使用判断任务是否适合多Agent协调,还是单服务委托即可。
Skill(conjure:delegation-core)Worktree Isolation Alternative (Claude Code 2.1.49+)
工作树隔离替代方案(Claude Code 2.1.49+)
For parallel agents that modify files, provides a lightweight alternative to filesystem-based coordination. Each agent runs in its own temporary git worktree, eliminating the need for locking or inbox-based conflict avoidance on shared files.
isolation: worktreefcntl- When to prefer worktrees over agent teams messaging: Agents work on overlapping files but don't need mid-execution communication
- When to prefer agent teams messaging: Agents need to coordinate discoveries or adjust plans based on each other's progress
- Combine both: Use agent teams for coordination with per teammate for filesystem safety
isolation: worktree
对于需要修改文件的并行Agent,提供了基于文件系统协调的轻量替代方案。每个Agent运行在自己的临时git工作树中,无需锁或基于收件箱的共享文件冲突规避机制。
isolation: worktreefcntl- 何时优先选择工作树而非Agent团队消息机制:Agent处理重叠文件,但不需要执行中通信
- 何时优先选择Agent团队消息机制:Agent需要协调发现内容或根据彼此的进度调整计划
- 两者结合:使用Agent团队进行协调,同时为每个团队成员配置保证文件系统安全
isolation: worktree
Troubleshooting
故障排查
Common Issues
常见问题
tmux not found
Install via package manager: /
brew install tmuxapt install tmuxStale lock files
If an agent crashes mid-operation, lock files may persist. Remove files manually from or
.lock~/.claude/teams/<team>/inboxes/~/.claude/tasks/<team>/Orphaned tasks
Tasks claimed by a crashed agent stay indefinitely. Use for heartbeat-based stall detection and automatic task release. The health monitoring protocol detects unresponsive agents within 60s + 30s probe window and releases their tasks for reassignment.
in_progressmodules/health-monitoring.mdMessage ordering
Filesystem timestamp resolution varies (HFS+ = 1s granularity). Use numbered filenames or UUID-sorted names to avoid collision on rapid message bursts.
Model errors on Bedrock/Vertex/Foundry (pre-2.1.39)
Teammate agents could use incorrect model identifiers on enterprise providers, causing 400 errors. Upgrade to Claude Code 2.1.39+ for correct model ID qualification across all providers.
Nested session guard (2.1.39+)
If refuses to launch within an existing session, ensure you're using tmux pane splitting (not subshell invocation). The guard is intentional — see for details.
claudemodules/spawning-patterns.mdtmux not found
通过包管理器安装: /
brew install tmuxapt install tmux锁文件残留
如果Agent运行中途崩溃,可能会残留锁文件。可手动删除或目录下的文件
~/.claude/teams/<team>/inboxes/~/.claude/tasks/<team>/.lock孤立任务
崩溃的Agent认领的任务会一直处于状态。可使用中介绍的基于心跳的停滞检测机制自动释放任务。健康监控协议可在60秒 + 30秒探测窗口内检测到无响应的Agent,并释放其任务供重新分配。
in_progressmodules/health-monitoring.md消息排序问题
不同文件系统的时间戳精度不同(HFS+精度为1秒)。可使用编号文件名或UUID排序的文件名避免快速消息突发时的冲突。
Bedrock/Vertex/Foundry上的模型错误(2.1.39之前版本)
团队成员Agent可能在企业级提供商上使用错误的模型标识符,导致400错误。请升级到Claude Code 2.1.39+版本,以支持所有提供商的正确模型ID限定。
嵌套会话防护(2.1.39+)
如果拒绝在现有会话中启动,请确保你使用的是tmux窗格拆分(而非子shell调用)。该防护机制是有意设计的 — 详情请参考。
claudemodules/spawning-patterns.mdExit Criteria
退出标准
- Team created with config and directories
- Teammates spawned and registered in config
- Tasks created with dependency graph (no cycles)
- Agents coordinating via inbox messages
- Graceful shutdown completed
- 已创建团队,包含配置和目录
- 已生成团队成员并在配置中注册
- 已创建任务,依赖图无循环
- Agent通过收件箱消息正常协调
- 优雅关闭完成