@every-env/compound-plugin 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/.claude/commands/triage-prs.md +193 -0
  2. package/.claude-plugin/marketplace.json +4 -4
  3. package/.github/workflows/ci.yml +25 -0
  4. package/README.md +25 -4
  5. package/docs/index.html +14 -14
  6. package/docs/pages/changelog.html +1 -1
  7. package/docs/pages/getting-started.html +1 -1
  8. package/docs/plans/2026-02-08-feat-pr-triage-and-merge-plan.md +128 -0
  9. package/package.json +1 -1
  10. package/plans/grow-your-own-garden-plugin-architecture.md +1 -1
  11. package/plugins/compound-engineering/.claude-plugin/plugin.json +3 -3
  12. package/plugins/compound-engineering/CHANGELOG.md +32 -0
  13. package/plugins/compound-engineering/CLAUDE.md +3 -4
  14. package/plugins/compound-engineering/README.md +20 -7
  15. package/plugins/compound-engineering/agents/research/best-practices-researcher.md +14 -3
  16. package/plugins/compound-engineering/agents/research/framework-docs-researcher.md +11 -3
  17. package/plugins/compound-engineering/agents/research/git-history-analyzer.md +2 -0
  18. package/plugins/compound-engineering/agents/research/learnings-researcher.md +243 -0
  19. package/plugins/compound-engineering/agents/research/repo-research-analyst.md +5 -4
  20. package/plugins/compound-engineering/agents/review/code-simplicity-reviewer.md +1 -0
  21. package/plugins/compound-engineering/agents/review/pattern-recognition-specialist.md +1 -1
  22. package/plugins/compound-engineering/agents/review/schema-drift-detector.md +139 -0
  23. package/plugins/compound-engineering/commands/deepen-plan.md +5 -5
  24. package/plugins/compound-engineering/commands/report-bug.md +3 -3
  25. package/plugins/compound-engineering/commands/resolve_todo_parallel.md +2 -0
  26. package/plugins/compound-engineering/commands/slfg.md +31 -0
  27. package/plugins/compound-engineering/commands/technical_review.md +7 -0
  28. package/plugins/compound-engineering/commands/workflows/brainstorm.md +124 -0
  29. package/plugins/compound-engineering/commands/workflows/compound.md +64 -27
  30. package/plugins/compound-engineering/commands/workflows/plan.md +127 -42
  31. package/plugins/compound-engineering/commands/workflows/review.md +12 -0
  32. package/plugins/compound-engineering/commands/workflows/work.md +72 -2
  33. package/plugins/compound-engineering/skills/brainstorming/SKILL.md +190 -0
  34. package/plugins/compound-engineering/skills/compound-docs/SKILL.md +9 -9
  35. package/plugins/compound-engineering/skills/compound-docs/assets/critical-pattern-template.md +1 -1
  36. package/plugins/compound-engineering/skills/compound-docs/assets/resolution-template.md +3 -3
  37. package/plugins/compound-engineering/skills/compound-docs/references/yaml-schema.md +1 -1
  38. package/plugins/compound-engineering/skills/create-agent-skills/SKILL.md +168 -192
  39. package/plugins/compound-engineering/skills/create-agent-skills/references/official-spec.md +74 -125
  40. package/plugins/compound-engineering/skills/create-agent-skills/references/skill-structure.md +109 -329
  41. package/plugins/compound-engineering/skills/document-review/SKILL.md +87 -0
  42. package/plugins/compound-engineering/skills/git-worktree/scripts/worktree-manager.sh +2 -10
  43. package/plugins/compound-engineering/skills/orchestrating-swarms/SKILL.md +1717 -0
  44. package/plugins/compound-engineering/skills/resolve-pr-parallel/SKILL.md +89 -0
  45. package/plugins/compound-engineering/skills/resolve-pr-parallel/scripts/get-pr-comments +68 -0
  46. package/plugins/compound-engineering/skills/resolve-pr-parallel/scripts/resolve-pr-thread +23 -0
  47. package/src/commands/install.ts +3 -1
  48. package/src/commands/sync.ts +84 -0
  49. package/src/converters/claude-to-codex.ts +59 -2
  50. package/src/converters/claude-to-opencode.ts +7 -5
  51. package/src/index.ts +2 -0
  52. package/src/parsers/claude-home.ts +65 -0
  53. package/src/sync/codex.ts +92 -0
  54. package/src/sync/opencode.ts +75 -0
  55. package/src/targets/codex.ts +7 -2
  56. package/src/targets/opencode.ts +11 -2
  57. package/src/types/claude.ts +1 -1
  58. package/src/utils/files.ts +13 -0
  59. package/src/utils/symlink.ts +43 -0
  60. package/tests/cli.test.ts +7 -5
  61. package/tests/codex-converter.test.ts +83 -0
  62. package/tests/codex-writer.test.ts +32 -0
  63. package/tests/opencode-writer.test.ts +57 -0
  64. package/plugins/compound-engineering/commands/plan_review.md +0 -7
  65. package/plugins/compound-engineering/commands/resolve_pr_parallel.md +0 -49
@@ -0,0 +1,1717 @@
1
+ ---
2
+ name: orchestrating-swarms
3
+ description: This skill should be used when orchestrating multi-agent swarms using Claude Code's TeammateTool and Task system. It applies when coordinating multiple agents, running parallel code reviews, creating pipeline workflows with dependencies, building self-organizing task queues, or any task benefiting from divide-and-conquer patterns.
4
+ ---
5
+
6
+ # Claude Code Swarm Orchestration
7
+
8
+ Master multi-agent orchestration using Claude Code's TeammateTool and Task system.
9
+
10
+ ---
11
+
12
+ ## Primitives
13
+
14
+ | Primitive | What It Is | File Location |
15
+ |-----------|-----------|---------------|
16
+ | **Agent** | A Claude instance that can use tools. You are an agent. Subagents are agents you spawn. | N/A (process) |
17
+ | **Team** | A named group of agents working together. One leader, multiple teammates. | `~/.claude/teams/{name}/config.json` |
18
+ | **Teammate** | An agent that joined a team. Has a name, color, inbox. Spawned via Task with `team_name` + `name`. | Listed in team config |
19
+ | **Leader** | The agent that created the team. Receives teammate messages, approves plans/shutdowns. | First member in config |
20
+ | **Task** | A work item with subject, description, status, owner, and dependencies. | `~/.claude/tasks/{team}/N.json` |
21
+ | **Inbox** | JSON file where an agent receives messages from teammates. | `~/.claude/teams/{name}/inboxes/{agent}.json` |
22
+ | **Message** | A JSON object sent between agents. Can be text or structured (shutdown_request, idle_notification, etc). | Stored in inbox files |
23
+ | **Backend** | How teammates run. Auto-detected: `in-process` (same Node.js, invisible), `tmux` (separate panes, visible), `iterm2` (split panes in iTerm2). See [Spawn Backends](#spawn-backends). | Auto-detected based on environment |
24
+
25
+ ### How They Connect
26
+
27
+ ```mermaid
28
+ flowchart TB
29
+ subgraph TEAM[TEAM]
30
+ Leader[Leader - you]
31
+ T1[Teammate 1]
32
+ T2[Teammate 2]
33
+
34
+ Leader <-->|messages via inbox| T1
35
+ Leader <-->|messages via inbox| T2
36
+ T1 <-.->|can message| T2
37
+ end
38
+
39
+ subgraph TASKS[TASK LIST]
40
+ Task1["#1 completed: Research<br/>owner: teammate1"]
41
+ Task2["#2 in_progress: Implement<br/>owner: teammate2"]
42
+ Task3["#3 pending: Test<br/>blocked by #2"]
43
+ end
44
+
45
+ T1 --> Task1
46
+ T2 --> Task2
47
+ Task2 -.->|unblocks| Task3
48
+ ```
49
+
50
+ ### Lifecycle
51
+
52
+ ```mermaid
53
+ flowchart LR
54
+ A[1. Create Team] --> B[2. Create Tasks]
55
+ B --> C[3. Spawn Teammates]
56
+ C --> D[4. Work]
57
+ D --> E[5. Coordinate]
58
+ E --> F[6. Shutdown]
59
+ F --> G[7. Cleanup]
60
+ ```
61
+
62
+ ### Message Flow
63
+
64
+ ```mermaid
65
+ sequenceDiagram
66
+ participant L as Leader
67
+ participant T1 as Teammate 1
68
+ participant T2 as Teammate 2
69
+ participant Tasks as Task List
70
+
71
+ L->>Tasks: TaskCreate (3 tasks)
72
+ L->>T1: spawn with prompt
73
+ L->>T2: spawn with prompt
74
+
75
+ T1->>Tasks: claim task #1
76
+ T2->>Tasks: claim task #2
77
+
78
+ T1->>Tasks: complete #1
79
+ T1->>L: send findings (inbox)
80
+
81
+ Note over Tasks: #3 auto-unblocks
82
+
83
+ T2->>Tasks: complete #2
84
+ T2->>L: send findings (inbox)
85
+
86
+ L->>T1: requestShutdown
87
+ T1->>L: approveShutdown
88
+ L->>T2: requestShutdown
89
+ T2->>L: approveShutdown
90
+
91
+ L->>L: cleanup
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Table of Contents
97
+
98
+ 1. [Core Architecture](#core-architecture)
99
+ 2. [Two Ways to Spawn Agents](#two-ways-to-spawn-agents)
100
+ 3. [Built-in Agent Types](#built-in-agent-types)
101
+ 4. [Plugin Agent Types](#plugin-agent-types)
102
+ 5. [TeammateTool Operations](#teammatetool-operations)
103
+ 6. [Task System Integration](#task-system-integration)
104
+ 7. [Message Formats](#message-formats)
105
+ 8. [Orchestration Patterns](#orchestration-patterns)
106
+ 9. [Environment Variables](#environment-variables)
107
+ 10. [Spawn Backends](#spawn-backends)
108
+ 11. [Error Handling](#error-handling)
109
+ 12. [Complete Workflows](#complete-workflows)
110
+
111
+ ---
112
+
113
+ ## Core Architecture
114
+
115
+ ### How Swarms Work
116
+
117
+ A swarm consists of:
118
+ - **Leader** (you) - Creates team, spawns workers, coordinates work
119
+ - **Teammates** (spawned agents) - Execute tasks, report back
120
+ - **Task List** - Shared work queue with dependencies
121
+ - **Inboxes** - JSON files for inter-agent messaging
122
+
123
+ ### File Structure
124
+
125
+ ```
126
+ ~/.claude/teams/{team-name}/
127
+ ├── config.json # Team metadata and member list
128
+ └── inboxes/
129
+ ├── team-lead.json # Leader's inbox
130
+ ├── worker-1.json # Worker 1's inbox
131
+ └── worker-2.json # Worker 2's inbox
132
+
133
+ ~/.claude/tasks/{team-name}/
134
+ ├── 1.json # Task #1
135
+ ├── 2.json # Task #2
136
+ └── 3.json # Task #3
137
+ ```
138
+
139
+ ### Team Config Structure
140
+
141
+ ```json
142
+ {
143
+ "name": "my-project",
144
+ "description": "Working on feature X",
145
+ "leadAgentId": "team-lead@my-project",
146
+ "createdAt": 1706000000000,
147
+ "members": [
148
+ {
149
+ "agentId": "team-lead@my-project",
150
+ "name": "team-lead",
151
+ "agentType": "team-lead",
152
+ "color": "#4A90D9",
153
+ "joinedAt": 1706000000000,
154
+ "backendType": "in-process"
155
+ },
156
+ {
157
+ "agentId": "worker-1@my-project",
158
+ "name": "worker-1",
159
+ "agentType": "Explore",
160
+ "model": "haiku",
161
+ "prompt": "Analyze the codebase structure...",
162
+ "color": "#D94A4A",
163
+ "planModeRequired": false,
164
+ "joinedAt": 1706000001000,
165
+ "tmuxPaneId": "in-process",
166
+ "cwd": "/Users/me/project",
167
+ "backendType": "in-process"
168
+ }
169
+ ]
170
+ }
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Two Ways to Spawn Agents
176
+
177
+ ### Method 1: Task Tool (Subagents)
178
+
179
+ Use Task for **short-lived, focused work** that returns a result:
180
+
181
+ ```javascript
182
+ Task({
183
+ subagent_type: "Explore",
184
+ description: "Find auth files",
185
+ prompt: "Find all authentication-related files in this codebase",
186
+ model: "haiku" // Optional: haiku, sonnet, opus
187
+ })
188
+ ```
189
+
190
+ **Characteristics:**
191
+ - Runs synchronously (blocks until complete) or async with `run_in_background: true`
192
+ - Returns result directly to you
193
+ - No team membership required
194
+ - Best for: searches, analysis, focused research
195
+
196
+ ### Method 2: Task Tool + team_name + name (Teammates)
197
+
198
+ Use Task with `team_name` and `name` to **spawn persistent teammates**:
199
+
200
+ ```javascript
201
+ // First create a team
202
+ Teammate({ operation: "spawnTeam", team_name: "my-project" })
203
+
204
+ // Then spawn a teammate into that team
205
+ Task({
206
+ team_name: "my-project", // Required: which team to join
207
+ name: "security-reviewer", // Required: teammate's name
208
+ subagent_type: "security-sentinel",
209
+ prompt: "Review all authentication code for vulnerabilities. Send findings to team-lead via Teammate write.",
210
+ run_in_background: true // Teammates usually run in background
211
+ })
212
+ ```
213
+
214
+ **Characteristics:**
215
+ - Joins team, appears in `config.json`
216
+ - Communicates via inbox messages
217
+ - Can claim tasks from shared task list
218
+ - Persists until shutdown
219
+ - Best for: parallel work, ongoing collaboration, pipeline stages
220
+
221
+ ### Key Difference
222
+
223
+ | Aspect | Task (subagent) | Task + team_name + name (teammate) |
224
+ |--------|-----------------|-----------------------------------|
225
+ | Lifespan | Until task complete | Until shutdown requested |
226
+ | Communication | Return value | Inbox messages |
227
+ | Task access | None | Shared task list |
228
+ | Team membership | No | Yes |
229
+ | Coordination | One-off | Ongoing |
230
+
231
+ ---
232
+
233
+ ## Built-in Agent Types
234
+
235
+ These are always available without plugins:
236
+
237
+ ### Bash
238
+ ```javascript
239
+ Task({
240
+ subagent_type: "Bash",
241
+ description: "Run git commands",
242
+ prompt: "Check git status and show recent commits"
243
+ })
244
+ ```
245
+ - **Tools:** Bash only
246
+ - **Model:** Inherits from parent
247
+ - **Best for:** Git operations, command execution, system tasks
248
+
249
+ ### Explore
250
+ ```javascript
251
+ Task({
252
+ subagent_type: "Explore",
253
+ description: "Find API endpoints",
254
+ prompt: "Find all API endpoints in this codebase. Be very thorough.",
255
+ model: "haiku" // Fast and cheap
256
+ })
257
+ ```
258
+ - **Tools:** All read-only tools (no Edit, Write, NotebookEdit, Task)
259
+ - **Model:** Haiku (optimized for speed)
260
+ - **Best for:** Codebase exploration, file searches, code understanding
261
+ - **Thoroughness levels:** "quick", "medium", "very thorough"
262
+
263
+ ### Plan
264
+ ```javascript
265
+ Task({
266
+ subagent_type: "Plan",
267
+ description: "Design auth system",
268
+ prompt: "Create an implementation plan for adding OAuth2 authentication"
269
+ })
270
+ ```
271
+ - **Tools:** All read-only tools
272
+ - **Model:** Inherits from parent
273
+ - **Best for:** Architecture planning, implementation strategies
274
+
275
+ ### general-purpose
276
+ ```javascript
277
+ Task({
278
+ subagent_type: "general-purpose",
279
+ description: "Research and implement",
280
+ prompt: "Research React Query best practices and implement caching for the user API"
281
+ })
282
+ ```
283
+ - **Tools:** All tools (*)
284
+ - **Model:** Inherits from parent
285
+ - **Best for:** Multi-step tasks, research + action combinations
286
+
287
+ ### claude-code-guide
288
+ ```javascript
289
+ Task({
290
+ subagent_type: "claude-code-guide",
291
+ description: "Help with Claude Code",
292
+ prompt: "How do I configure MCP servers?"
293
+ })
294
+ ```
295
+ - **Tools:** Read-only + WebFetch + WebSearch
296
+ - **Best for:** Questions about Claude Code, Agent SDK, Anthropic API
297
+
298
+ ### statusline-setup
299
+ ```javascript
300
+ Task({
301
+ subagent_type: "statusline-setup",
302
+ description: "Configure status line",
303
+ prompt: "Set up a status line showing git branch and node version"
304
+ })
305
+ ```
306
+ - **Tools:** Read, Edit only
307
+ - **Model:** Sonnet
308
+ - **Best for:** Configuring Claude Code status line
309
+
310
+ ---
311
+
312
+ ## Plugin Agent Types
313
+
314
+ From the `compound-engineering` plugin (examples):
315
+
316
+ ### Review Agents
317
+ ```javascript
318
+ // Security review
319
+ Task({
320
+ subagent_type: "compound-engineering:review:security-sentinel",
321
+ description: "Security audit",
322
+ prompt: "Audit this PR for security vulnerabilities"
323
+ })
324
+
325
+ // Performance review
326
+ Task({
327
+ subagent_type: "compound-engineering:review:performance-oracle",
328
+ description: "Performance check",
329
+ prompt: "Analyze this code for performance bottlenecks"
330
+ })
331
+
332
+ // Rails code review
333
+ Task({
334
+ subagent_type: "compound-engineering:review:kieran-rails-reviewer",
335
+ description: "Rails review",
336
+ prompt: "Review this Rails code for best practices"
337
+ })
338
+
339
+ // Architecture review
340
+ Task({
341
+ subagent_type: "compound-engineering:review:architecture-strategist",
342
+ description: "Architecture review",
343
+ prompt: "Review the system architecture of the authentication module"
344
+ })
345
+
346
+ // Code simplicity
347
+ Task({
348
+ subagent_type: "compound-engineering:review:code-simplicity-reviewer",
349
+ description: "Simplicity check",
350
+ prompt: "Check if this implementation can be simplified"
351
+ })
352
+ ```
353
+
354
+ **All review agents from compound-engineering:**
355
+ - `agent-native-reviewer` - Ensures features work for agents too
356
+ - `architecture-strategist` - Architectural compliance
357
+ - `code-simplicity-reviewer` - YAGNI and minimalism
358
+ - `data-integrity-guardian` - Database and data safety
359
+ - `data-migration-expert` - Migration validation
360
+ - `deployment-verification-agent` - Pre-deploy checklists
361
+ - `dhh-rails-reviewer` - DHH/37signals Rails style
362
+ - `julik-frontend-races-reviewer` - JavaScript race conditions
363
+ - `kieran-python-reviewer` - Python best practices
364
+ - `kieran-rails-reviewer` - Rails best practices
365
+ - `kieran-typescript-reviewer` - TypeScript best practices
366
+ - `pattern-recognition-specialist` - Design patterns and anti-patterns
367
+ - `performance-oracle` - Performance analysis
368
+ - `security-sentinel` - Security vulnerabilities
369
+
370
+ ### Research Agents
371
+ ```javascript
372
+ // Best practices research
373
+ Task({
374
+ subagent_type: "compound-engineering:research:best-practices-researcher",
375
+ description: "Research auth best practices",
376
+ prompt: "Research current best practices for JWT authentication in Rails 2024-2026"
377
+ })
378
+
379
+ // Framework documentation
380
+ Task({
381
+ subagent_type: "compound-engineering:research:framework-docs-researcher",
382
+ description: "Research Active Storage",
383
+ prompt: "Gather comprehensive documentation about Active Storage file uploads"
384
+ })
385
+
386
+ // Git history analysis
387
+ Task({
388
+ subagent_type: "compound-engineering:research:git-history-analyzer",
389
+ description: "Analyze auth history",
390
+ prompt: "Analyze the git history of the authentication module to understand its evolution"
391
+ })
392
+ ```
393
+
394
+ **All research agents:**
395
+ - `best-practices-researcher` - External best practices
396
+ - `framework-docs-researcher` - Framework documentation
397
+ - `git-history-analyzer` - Code archaeology
398
+ - `learnings-researcher` - Search docs/solutions/
399
+ - `repo-research-analyst` - Repository patterns
400
+
401
+ ### Design Agents
402
+ ```javascript
403
+ Task({
404
+ subagent_type: "compound-engineering:design:figma-design-sync",
405
+ description: "Sync with Figma",
406
+ prompt: "Compare implementation with Figma design at [URL]"
407
+ })
408
+ ```
409
+
410
+ ### Workflow Agents
411
+ ```javascript
412
+ Task({
413
+ subagent_type: "compound-engineering:workflow:bug-reproduction-validator",
414
+ description: "Validate bug",
415
+ prompt: "Reproduce and validate this reported bug: [description]"
416
+ })
417
+ ```
418
+
419
+ ---
420
+
421
+ ## TeammateTool Operations
422
+
423
+ ### 1. spawnTeam - Create a Team
424
+
425
+ ```javascript
426
+ Teammate({
427
+ operation: "spawnTeam",
428
+ team_name: "feature-auth",
429
+ description: "Implementing OAuth2 authentication"
430
+ })
431
+ ```
432
+
433
+ **Creates:**
434
+ - `~/.claude/teams/feature-auth/config.json`
435
+ - `~/.claude/tasks/feature-auth/` directory
436
+ - You become the team leader
437
+
438
+ ### 2. discoverTeams - List Available Teams
439
+
440
+ ```javascript
441
+ Teammate({ operation: "discoverTeams" })
442
+ ```
443
+
444
+ **Returns:** List of teams you can join (not already a member of)
445
+
446
+ ### 3. requestJoin - Request to Join Team
447
+
448
+ ```javascript
449
+ Teammate({
450
+ operation: "requestJoin",
451
+ team_name: "feature-auth",
452
+ proposed_name: "helper",
453
+ capabilities: "I can help with code review and testing"
454
+ })
455
+ ```
456
+
457
+ ### 4. approveJoin - Accept Join Request (Leader Only)
458
+
459
+ When you receive a `join_request` message:
460
+ ```json
461
+ {"type": "join_request", "proposedName": "helper", "requestId": "join-123", ...}
462
+ ```
463
+
464
+ Approve it:
465
+ ```javascript
466
+ Teammate({
467
+ operation: "approveJoin",
468
+ target_agent_id: "helper",
469
+ request_id: "join-123"
470
+ })
471
+ ```
472
+
473
+ ### 5. rejectJoin - Decline Join Request (Leader Only)
474
+
475
+ ```javascript
476
+ Teammate({
477
+ operation: "rejectJoin",
478
+ target_agent_id: "helper",
479
+ request_id: "join-123",
480
+ reason: "Team is at capacity"
481
+ })
482
+ ```
483
+
484
+ ### 6. write - Message One Teammate
485
+
486
+ ```javascript
487
+ Teammate({
488
+ operation: "write",
489
+ target_agent_id: "security-reviewer",
490
+ value: "Please prioritize the authentication module. The deadline is tomorrow."
491
+ })
492
+ ```
493
+
494
+ **Important for teammates:** Your text output is NOT visible to the team. You MUST use `write` to communicate.
495
+
496
+ ### 7. broadcast - Message ALL Teammates
497
+
498
+ ```javascript
499
+ Teammate({
500
+ operation: "broadcast",
501
+ name: "team-lead", // Your name
502
+ value: "Status check: Please report your progress"
503
+ })
504
+ ```
505
+
506
+ **WARNING:** Broadcasting is expensive - sends N separate messages for N teammates. Prefer `write` to specific teammates.
507
+
508
+ **When to broadcast:**
509
+ - Critical issues requiring immediate attention
510
+ - Major announcements affecting everyone
511
+
512
+ **When NOT to broadcast:**
513
+ - Responding to one teammate
514
+ - Normal back-and-forth
515
+ - Information relevant to only some teammates
516
+
517
+ ### 8. requestShutdown - Ask Teammate to Exit (Leader Only)
518
+
519
+ ```javascript
520
+ Teammate({
521
+ operation: "requestShutdown",
522
+ target_agent_id: "security-reviewer",
523
+ reason: "All tasks complete, wrapping up"
524
+ })
525
+ ```
526
+
527
+ ### 9. approveShutdown - Accept Shutdown (Teammate Only)
528
+
529
+ When you receive a `shutdown_request` message:
530
+ ```json
531
+ {"type": "shutdown_request", "requestId": "shutdown-123", "from": "team-lead", "reason": "Done"}
532
+ ```
533
+
534
+ **MUST** call:
535
+ ```javascript
536
+ Teammate({
537
+ operation: "approveShutdown",
538
+ request_id: "shutdown-123"
539
+ })
540
+ ```
541
+
542
+ This sends confirmation and terminates your process.
543
+
544
+ ### 10. rejectShutdown - Decline Shutdown (Teammate Only)
545
+
546
+ ```javascript
547
+ Teammate({
548
+ operation: "rejectShutdown",
549
+ request_id: "shutdown-123",
550
+ reason: "Still working on task #3, need 5 more minutes"
551
+ })
552
+ ```
553
+
554
+ ### 11. approvePlan - Approve Teammate's Plan (Leader Only)
555
+
556
+ When teammate with `plan_mode_required` sends a plan:
557
+ ```json
558
+ {"type": "plan_approval_request", "from": "architect", "requestId": "plan-456", ...}
559
+ ```
560
+
561
+ Approve:
562
+ ```javascript
563
+ Teammate({
564
+ operation: "approvePlan",
565
+ target_agent_id: "architect",
566
+ request_id: "plan-456"
567
+ })
568
+ ```
569
+
570
+ ### 12. rejectPlan - Reject Plan with Feedback (Leader Only)
571
+
572
+ ```javascript
573
+ Teammate({
574
+ operation: "rejectPlan",
575
+ target_agent_id: "architect",
576
+ request_id: "plan-456",
577
+ feedback: "Please add error handling for the API calls and consider rate limiting"
578
+ })
579
+ ```
580
+
581
+ ### 13. cleanup - Remove Team Resources
582
+
583
+ ```javascript
584
+ Teammate({ operation: "cleanup" })
585
+ ```
586
+
587
+ **Removes:**
588
+ - `~/.claude/teams/{team-name}/` directory
589
+ - `~/.claude/tasks/{team-name}/` directory
590
+
591
+ **IMPORTANT:** Will fail if teammates are still active. Use `requestShutdown` first.
592
+
593
+ ---
594
+
595
+ ## Task System Integration
596
+
597
+ ### TaskCreate - Create Work Items
598
+
599
+ ```javascript
600
+ TaskCreate({
601
+ subject: "Review authentication module",
602
+ description: "Review all files in app/services/auth/ for security vulnerabilities",
603
+ activeForm: "Reviewing auth module..." // Shown in spinner when in_progress
604
+ })
605
+ ```
606
+
607
+ ### TaskList - See All Tasks
608
+
609
+ ```javascript
610
+ TaskList()
611
+ ```
612
+
613
+ Returns:
614
+ ```
615
+ #1 [completed] Analyze codebase structure
616
+ #2 [in_progress] Review authentication module (owner: security-reviewer)
617
+ #3 [pending] Generate summary report [blocked by #2]
618
+ ```
619
+
620
+ ### TaskGet - Get Task Details
621
+
622
+ ```javascript
623
+ TaskGet({ taskId: "2" })
624
+ ```
625
+
626
+ Returns full task with description, status, blockedBy, etc.
627
+
628
+ ### TaskUpdate - Update Task Status
629
+
630
+ ```javascript
631
+ // Claim a task
632
+ TaskUpdate({ taskId: "2", owner: "security-reviewer" })
633
+
634
+ // Start working
635
+ TaskUpdate({ taskId: "2", status: "in_progress" })
636
+
637
+ // Mark complete
638
+ TaskUpdate({ taskId: "2", status: "completed" })
639
+
640
+ // Set up dependencies
641
+ TaskUpdate({ taskId: "3", addBlockedBy: ["1", "2"] })
642
+ ```
643
+
644
+ ### Task Dependencies
645
+
646
+ When a blocking task is completed, blocked tasks are automatically unblocked:
647
+
648
+ ```javascript
649
+ // Create pipeline
650
+ TaskCreate({ subject: "Step 1: Research" }) // #1
651
+ TaskCreate({ subject: "Step 2: Implement" }) // #2
652
+ TaskCreate({ subject: "Step 3: Test" }) // #3
653
+ TaskCreate({ subject: "Step 4: Deploy" }) // #4
654
+
655
+ // Set up dependencies
656
+ TaskUpdate({ taskId: "2", addBlockedBy: ["1"] }) // #2 waits for #1
657
+ TaskUpdate({ taskId: "3", addBlockedBy: ["2"] }) // #3 waits for #2
658
+ TaskUpdate({ taskId: "4", addBlockedBy: ["3"] }) // #4 waits for #3
659
+
660
+ // When #1 completes, #2 auto-unblocks
661
+ // When #2 completes, #3 auto-unblocks
662
+ // etc.
663
+ ```
664
+
665
+ ### Task File Structure
666
+
667
+ `~/.claude/tasks/{team-name}/1.json`:
668
+ ```json
669
+ {
670
+ "id": "1",
671
+ "subject": "Review authentication module",
672
+ "description": "Review all files in app/services/auth/...",
673
+ "status": "in_progress",
674
+ "owner": "security-reviewer",
675
+ "activeForm": "Reviewing auth module...",
676
+ "blockedBy": [],
677
+ "blocks": ["3"],
678
+ "createdAt": 1706000000000,
679
+ "updatedAt": 1706000001000
680
+ }
681
+ ```
682
+
683
+ ---
684
+
685
+ ## Message Formats
686
+
687
+ ### Regular Message
688
+
689
+ ```json
690
+ {
691
+ "from": "team-lead",
692
+ "text": "Please prioritize the auth module",
693
+ "timestamp": "2026-01-25T23:38:32.588Z",
694
+ "read": false
695
+ }
696
+ ```
697
+
698
+ ### Structured Messages (JSON in text field)
699
+
700
+ #### Shutdown Request
701
+ ```json
702
+ {
703
+ "type": "shutdown_request",
704
+ "requestId": "shutdown-abc123@worker-1",
705
+ "from": "team-lead",
706
+ "reason": "All tasks complete",
707
+ "timestamp": "2026-01-25T23:38:32.588Z"
708
+ }
709
+ ```
710
+
711
+ #### Shutdown Approved
712
+ ```json
713
+ {
714
+ "type": "shutdown_approved",
715
+ "requestId": "shutdown-abc123@worker-1",
716
+ "from": "worker-1",
717
+ "paneId": "%5",
718
+ "backendType": "in-process",
719
+ "timestamp": "2026-01-25T23:39:00.000Z"
720
+ }
721
+ ```
722
+
723
+ #### Idle Notification (auto-sent when teammate stops)
724
+ ```json
725
+ {
726
+ "type": "idle_notification",
727
+ "from": "worker-1",
728
+ "timestamp": "2026-01-25T23:40:00.000Z",
729
+ "completedTaskId": "2",
730
+ "completedStatus": "completed"
731
+ }
732
+ ```
733
+
734
+ #### Task Completed
735
+ ```json
736
+ {
737
+ "type": "task_completed",
738
+ "from": "worker-1",
739
+ "taskId": "2",
740
+ "taskSubject": "Review authentication module",
741
+ "timestamp": "2026-01-25T23:40:00.000Z"
742
+ }
743
+ ```
744
+
745
+ #### Plan Approval Request
746
+ ```json
747
+ {
748
+ "type": "plan_approval_request",
749
+ "from": "architect",
750
+ "requestId": "plan-xyz789",
751
+ "planContent": "# Implementation Plan\n\n1. ...",
752
+ "timestamp": "2026-01-25T23:41:00.000Z"
753
+ }
754
+ ```
755
+
756
+ #### Join Request
757
+ ```json
758
+ {
759
+ "type": "join_request",
760
+ "proposedName": "helper",
761
+ "requestId": "join-abc123",
762
+ "capabilities": "Code review and testing",
763
+ "timestamp": "2026-01-25T23:42:00.000Z"
764
+ }
765
+ ```
766
+
767
+ #### Permission Request (for sandbox/tool permissions)
768
+ ```json
769
+ {
770
+ "type": "permission_request",
771
+ "requestId": "perm-123",
772
+ "workerId": "worker-1@my-project",
773
+ "workerName": "worker-1",
774
+ "workerColor": "#4A90D9",
775
+ "toolName": "Bash",
776
+ "toolUseId": "toolu_abc123",
777
+ "description": "Run npm install",
778
+ "input": {"command": "npm install"},
779
+ "permissionSuggestions": ["Bash(npm *)"],
780
+ "createdAt": 1706000000000
781
+ }
782
+ ```
783
+
784
+ ---
785
+
786
+ ## Orchestration Patterns
787
+
788
+ ### Pattern 1: Parallel Specialists (Leader Pattern)
789
+
790
+ Multiple specialists review code simultaneously:
791
+
792
+ ```javascript
793
+ // 1. Create team
794
+ Teammate({ operation: "spawnTeam", team_name: "code-review" })
795
+
796
+ // 2. Spawn specialists in parallel (single message, multiple Task calls)
797
+ Task({
798
+ team_name: "code-review",
799
+ name: "security",
800
+ subagent_type: "compound-engineering:review:security-sentinel",
801
+ prompt: "Review the PR for security vulnerabilities. Focus on: SQL injection, XSS, auth bypass. Send findings to team-lead.",
802
+ run_in_background: true
803
+ })
804
+
805
+ Task({
806
+ team_name: "code-review",
807
+ name: "performance",
808
+ subagent_type: "compound-engineering:review:performance-oracle",
809
+ prompt: "Review the PR for performance issues. Focus on: N+1 queries, memory leaks, slow algorithms. Send findings to team-lead.",
810
+ run_in_background: true
811
+ })
812
+
813
+ Task({
814
+ team_name: "code-review",
815
+ name: "simplicity",
816
+ subagent_type: "compound-engineering:review:code-simplicity-reviewer",
817
+ prompt: "Review the PR for unnecessary complexity. Focus on: over-engineering, premature abstraction, YAGNI violations. Send findings to team-lead.",
818
+ run_in_background: true
819
+ })
820
+
821
+ // 3. Wait for results (check inbox)
822
+ // cat ~/.claude/teams/code-review/inboxes/team-lead.json
823
+
824
+ // 4. Synthesize findings and cleanup
825
+ Teammate({ operation: "requestShutdown", target_agent_id: "security" })
826
+ Teammate({ operation: "requestShutdown", target_agent_id: "performance" })
827
+ Teammate({ operation: "requestShutdown", target_agent_id: "simplicity" })
828
+ // Wait for approvals...
829
+ Teammate({ operation: "cleanup" })
830
+ ```
831
+
832
+ ### Pattern 2: Pipeline (Sequential Dependencies)
833
+
834
+ Each stage depends on the previous:
835
+
836
+ ```javascript
837
+ // 1. Create team and task pipeline
838
+ Teammate({ operation: "spawnTeam", team_name: "feature-pipeline" })
839
+
840
+ TaskCreate({ subject: "Research", description: "Research best practices for the feature", activeForm: "Researching..." })
841
+ TaskCreate({ subject: "Plan", description: "Create implementation plan based on research", activeForm: "Planning..." })
842
+ TaskCreate({ subject: "Implement", description: "Implement the feature according to plan", activeForm: "Implementing..." })
843
+ TaskCreate({ subject: "Test", description: "Write and run tests for the implementation", activeForm: "Testing..." })
844
+ TaskCreate({ subject: "Review", description: "Final code review before merge", activeForm: "Reviewing..." })
845
+
846
+ // Set up sequential dependencies
847
+ TaskUpdate({ taskId: "2", addBlockedBy: ["1"] })
848
+ TaskUpdate({ taskId: "3", addBlockedBy: ["2"] })
849
+ TaskUpdate({ taskId: "4", addBlockedBy: ["3"] })
850
+ TaskUpdate({ taskId: "5", addBlockedBy: ["4"] })
851
+
852
+ // 2. Spawn workers that claim and complete tasks
853
+ Task({
854
+ team_name: "feature-pipeline",
855
+ name: "researcher",
856
+ subagent_type: "compound-engineering:research:best-practices-researcher",
857
+ prompt: "Claim task #1, research best practices, complete it, send findings to team-lead. Then check for more work.",
858
+ run_in_background: true
859
+ })
860
+
861
+ Task({
862
+ team_name: "feature-pipeline",
863
+ name: "implementer",
864
+ subagent_type: "general-purpose",
865
+ prompt: "Poll TaskList every 30 seconds. When task #3 unblocks, claim it and implement. Then complete and notify team-lead.",
866
+ run_in_background: true
867
+ })
868
+
869
+ // Tasks auto-unblock as dependencies complete
870
+ ```
871
+
872
+ ### Pattern 3: Swarm (Self-Organizing)
873
+
874
+ Workers grab available tasks from a pool:
875
+
876
+ ```javascript
877
+ // 1. Create team and task pool
878
+ Teammate({ operation: "spawnTeam", team_name: "file-review-swarm" })
879
+
880
+ // Create many independent tasks (no dependencies)
881
+ for (const file of ["auth.rb", "user.rb", "api_controller.rb", "payment.rb"]) {
882
+ TaskCreate({
883
+ subject: `Review ${file}`,
884
+ description: `Review ${file} for security and code quality issues`,
885
+ activeForm: `Reviewing ${file}...`
886
+ })
887
+ }
888
+
889
+ // 2. Spawn worker swarm
890
+ Task({
891
+ team_name: "file-review-swarm",
892
+ name: "worker-1",
893
+ subagent_type: "general-purpose",
894
+ prompt: `
895
+ You are a swarm worker. Your job:
896
+ 1. Call TaskList to see available tasks
897
+ 2. Find a task with status 'pending' and no owner
898
+ 3. Claim it with TaskUpdate (set owner to your name)
899
+ 4. Do the work
900
+ 5. Mark it completed with TaskUpdate
901
+ 6. Send findings to team-lead via Teammate write
902
+ 7. Repeat until no tasks remain
903
+ `,
904
+ run_in_background: true
905
+ })
906
+
907
+ Task({
908
+ team_name: "file-review-swarm",
909
+ name: "worker-2",
910
+ subagent_type: "general-purpose",
911
+ prompt: `[Same prompt as worker-1]`,
912
+ run_in_background: true
913
+ })
914
+
915
+ Task({
916
+ team_name: "file-review-swarm",
917
+ name: "worker-3",
918
+ subagent_type: "general-purpose",
919
+ prompt: `[Same prompt as worker-1]`,
920
+ run_in_background: true
921
+ })
922
+
923
+ // Workers race to claim tasks, naturally load-balance
924
+ ```
925
+
926
+ ### Pattern 4: Research + Implementation
927
+
928
+ Research first, then implement:
929
+
930
+ ```javascript
931
+ // 1. Research phase (synchronous, returns results)
932
+ const research = await Task({
933
+ subagent_type: "compound-engineering:research:best-practices-researcher",
934
+ description: "Research caching patterns",
935
+ prompt: "Research best practices for implementing caching in Rails APIs. Include: cache invalidation strategies, Redis vs Memcached, cache key design."
936
+ })
937
+
938
+ // 2. Use research to guide implementation
939
+ Task({
940
+ subagent_type: "general-purpose",
941
+ description: "Implement caching",
942
+ prompt: `
943
+ Implement API caching based on this research:
944
+
945
+ ${research.content}
946
+
947
+ Focus on the user_controller.rb endpoints.
948
+ `
949
+ })
950
+ ```
951
+
952
+ ### Pattern 5: Plan Approval Workflow
953
+
954
+ Require plan approval before implementation:
955
+
956
+ ```javascript
957
+ // 1. Create team
958
+ Teammate({ operation: "spawnTeam", team_name: "careful-work" })
959
+
960
+ // 2. Spawn architect with plan_mode_required
961
+ Task({
962
+ team_name: "careful-work",
963
+ name: "architect",
964
+ subagent_type: "Plan",
965
+ prompt: "Design an implementation plan for adding OAuth2 authentication",
966
+ mode: "plan", // Requires plan approval
967
+ run_in_background: true
968
+ })
969
+
970
+ // 3. Wait for plan approval request
971
+ // You'll receive: {"type": "plan_approval_request", "from": "architect", "requestId": "plan-xxx", ...}
972
+
973
+ // 4. Review and approve/reject
974
+ Teammate({
975
+ operation: "approvePlan",
976
+ target_agent_id: "architect",
977
+ request_id: "plan-xxx"
978
+ })
979
+ // OR
980
+ Teammate({
981
+ operation: "rejectPlan",
982
+ target_agent_id: "architect",
983
+ request_id: "plan-xxx",
984
+ feedback: "Please add rate limiting considerations"
985
+ })
986
+ ```
987
+
988
+ ### Pattern 6: Coordinated Multi-File Refactoring
989
+
990
+ ```javascript
991
+ // 1. Create team for coordinated refactoring
992
+ Teammate({ operation: "spawnTeam", team_name: "refactor-auth" })
993
+
994
+ // 2. Create tasks with clear file boundaries
995
+ TaskCreate({
996
+ subject: "Refactor User model",
997
+ description: "Extract authentication methods to AuthenticatableUser concern",
998
+ activeForm: "Refactoring User model..."
999
+ })
1000
+
1001
+ TaskCreate({
1002
+ subject: "Refactor Session controller",
1003
+ description: "Update to use new AuthenticatableUser concern",
1004
+ activeForm: "Refactoring Sessions..."
1005
+ })
1006
+
1007
+ TaskCreate({
1008
+ subject: "Update specs",
1009
+ description: "Update all authentication specs for new structure",
1010
+ activeForm: "Updating specs..."
1011
+ })
1012
+
1013
+ // Dependencies: specs depend on both refactors completing
1014
+ TaskUpdate({ taskId: "3", addBlockedBy: ["1", "2"] })
1015
+
1016
+ // 3. Spawn workers for each task
1017
+ Task({
1018
+ team_name: "refactor-auth",
1019
+ name: "model-worker",
1020
+ subagent_type: "general-purpose",
1021
+ prompt: "Claim task #1, refactor the User model, complete when done",
1022
+ run_in_background: true
1023
+ })
1024
+
1025
+ Task({
1026
+ team_name: "refactor-auth",
1027
+ name: "controller-worker",
1028
+ subagent_type: "general-purpose",
1029
+ prompt: "Claim task #2, refactor the Session controller, complete when done",
1030
+ run_in_background: true
1031
+ })
1032
+
1033
+ Task({
1034
+ team_name: "refactor-auth",
1035
+ name: "spec-worker",
1036
+ subagent_type: "general-purpose",
1037
+ prompt: "Wait for task #3 to unblock (when #1 and #2 complete), then update specs",
1038
+ run_in_background: true
1039
+ })
1040
+ ```
1041
+
1042
+ ---
1043
+
1044
+ ## Environment Variables
1045
+
1046
+ Spawned teammates automatically receive these:
1047
+
1048
+ ```bash
1049
+ CLAUDE_CODE_TEAM_NAME="my-project"
1050
+ CLAUDE_CODE_AGENT_ID="worker-1@my-project"
1051
+ CLAUDE_CODE_AGENT_NAME="worker-1"
1052
+ CLAUDE_CODE_AGENT_TYPE="Explore"
1053
+ CLAUDE_CODE_AGENT_COLOR="#4A90D9"
1054
+ CLAUDE_CODE_PLAN_MODE_REQUIRED="false"
1055
+ CLAUDE_CODE_PARENT_SESSION_ID="session-xyz"
1056
+ ```
1057
+
1058
+ **Using in prompts:**
1059
+ ```javascript
1060
+ Task({
1061
+ team_name: "my-project",
1062
+ name: "worker",
1063
+ subagent_type: "general-purpose",
1064
+ prompt: "Your name is $CLAUDE_CODE_AGENT_NAME. Use it when sending messages to team-lead."
1065
+ })
1066
+ ```
1067
+
1068
+ ---
1069
+
1070
+ ## Spawn Backends
1071
+
1072
+ A **backend** determines how teammate Claude instances actually run. Claude Code supports three backends, and **auto-detects** the best one based on your environment.
1073
+
1074
+ ### Backend Comparison
1075
+
1076
+ | Backend | How It Works | Visibility | Persistence | Speed |
1077
+ |---------|-------------|------------|-------------|-------|
1078
+ | **in-process** | Same Node.js process as leader | Hidden (background) | Dies with leader | Fastest |
1079
+ | **tmux** | Separate terminal in tmux session | Visible in tmux | Survives leader exit | Medium |
1080
+ | **iterm2** | Split panes in iTerm2 window | Visible side-by-side | Dies with window | Medium |
1081
+
1082
+ ### Auto-Detection Logic
1083
+
1084
+ Claude Code automatically selects a backend using this decision tree:
1085
+
1086
+ ```mermaid
1087
+ flowchart TD
1088
+ A[Start] --> B{Running inside tmux?}
1089
+ B -->|Yes| C[Use tmux backend]
1090
+ B -->|No| D{Running in iTerm2?}
1091
+ D -->|No| E{tmux available?}
1092
+ E -->|Yes| F[Use tmux - external session]
1093
+ E -->|No| G[Use in-process]
1094
+ D -->|Yes| H{it2 CLI installed?}
1095
+ H -->|Yes| I[Use iterm2 backend]
1096
+ H -->|No| J{tmux available?}
1097
+ J -->|Yes| K[Use tmux - prompt to install it2]
1098
+ J -->|No| L[Error: Install tmux or it2]
1099
+ ```
1100
+
1101
+ **Detection checks:**
1102
+ 1. `$TMUX` environment variable → inside tmux
1103
+ 2. `$TERM_PROGRAM === "iTerm.app"` or `$ITERM_SESSION_ID` → in iTerm2
1104
+ 3. `which tmux` → tmux available
1105
+ 4. `which it2` → it2 CLI installed
1106
+
1107
+ ### in-process (Default for non-tmux)
1108
+
1109
+ Teammates run as async tasks within the same Node.js process.
1110
+
1111
+ **How it works:**
1112
+ - No new process spawned
1113
+ - Teammates share the same Node.js event loop
1114
+ - Communication via in-memory queues (fast)
1115
+ - You don't see teammate output directly
1116
+
1117
+ **When it's used:**
1118
+ - Not running inside tmux session
1119
+ - Non-interactive mode (CI, scripts)
1120
+ - Explicitly set via `CLAUDE_CODE_SPAWN_BACKEND=in-process`
1121
+
1122
+ **Characteristics:**
1123
+ ```
1124
+ ┌─────────────────────────────────────────┐
1125
+ │ Node.js Process │
1126
+ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
1127
+ │ │ Leader │ │Worker 1 │ │Worker 2 │ │
1128
+ │ │ (main) │ │ (async) │ │ (async) │ │
1129
+ │ └─────────┘ └─────────┘ └─────────┘ │
1130
+ └─────────────────────────────────────────┘
1131
+ ```
1132
+
1133
+ **Pros:**
1134
+ - Fastest startup (no process spawn)
1135
+ - Lowest overhead
1136
+ - Works everywhere
1137
+
1138
+ **Cons:**
1139
+ - Can't see teammate output in real-time
1140
+ - All die if leader dies
1141
+ - Harder to debug
1142
+
1143
+ ```javascript
1144
+ // in-process is automatic when not in tmux
1145
+ Task({
1146
+ team_name: "my-project",
1147
+ name: "worker",
1148
+ subagent_type: "general-purpose",
1149
+ prompt: "...",
1150
+ run_in_background: true
1151
+ })
1152
+
1153
+ // Force in-process explicitly
1154
+ // export CLAUDE_CODE_SPAWN_BACKEND=in-process
1155
+ ```
1156
+
1157
+ ### tmux
1158
+
1159
+ Teammates run as separate Claude instances in tmux panes/windows.
1160
+
1161
+ **How it works:**
1162
+ - Each teammate gets its own tmux pane
1163
+ - Separate process per teammate
1164
+ - You can switch panes to see teammate output
1165
+ - Communication via inbox files
1166
+
1167
+ **When it's used:**
1168
+ - Running inside a tmux session (`$TMUX` is set)
1169
+ - tmux available and not in iTerm2
1170
+ - Explicitly set via `CLAUDE_CODE_SPAWN_BACKEND=tmux`
1171
+
1172
+ **Layout modes:**
1173
+
1174
+ 1. **Inside tmux (native):** Splits your current window
1175
+ ```
1176
+ ┌─────────────────┬─────────────────┐
1177
+ │ │ Worker 1 │
1178
+ │ Leader ├─────────────────┤
1179
+ │ (your pane) │ Worker 2 │
1180
+ │ ├─────────────────┤
1181
+ │ │ Worker 3 │
1182
+ └─────────────────┴─────────────────┘
1183
+ ```
1184
+
1185
+ 2. **Outside tmux (external session):** Creates a new tmux session called `claude-swarm`
1186
+ ```bash
1187
+ # Your terminal stays as-is
1188
+ # Workers run in separate tmux session
1189
+
1190
+ # View workers:
1191
+ tmux attach -t claude-swarm
1192
+ ```
1193
+
1194
+ **Pros:**
1195
+ - See teammate output in real-time
1196
+ - Teammates survive leader exit
1197
+ - Can attach/detach sessions
1198
+ - Works in CI/headless environments
1199
+
1200
+ **Cons:**
1201
+ - Slower startup (process spawn)
1202
+ - Requires tmux installed
1203
+ - More resource usage
1204
+
1205
+ ```bash
1206
+ # Start tmux session first
1207
+ tmux new-session -s claude
1208
+
1209
+ # Or force tmux backend
1210
+ export CLAUDE_CODE_SPAWN_BACKEND=tmux
1211
+ ```
1212
+
1213
+ **Useful tmux commands:**
1214
+ ```bash
1215
+ # List all panes in current window
1216
+ tmux list-panes
1217
+
1218
+ # Switch to pane by number
1219
+ tmux select-pane -t 1
1220
+
1221
+ # Kill a specific pane
1222
+ tmux kill-pane -t %5
1223
+
1224
+ # View swarm session (if external)
1225
+ tmux attach -t claude-swarm
1226
+
1227
+ # Rebalance pane layout
1228
+ tmux select-layout tiled
1229
+ ```
1230
+
1231
+ ### iterm2 (macOS only)
1232
+
1233
+ Teammates run as split panes within your iTerm2 window.
1234
+
1235
+ **How it works:**
1236
+ - Uses iTerm2's Python API via `it2` CLI
1237
+ - Splits your current window into panes
1238
+ - Each teammate visible side-by-side
1239
+ - Communication via inbox files
1240
+
1241
+ **When it's used:**
1242
+ - Running in iTerm2 (`$TERM_PROGRAM === "iTerm.app"`)
1243
+ - `it2` CLI is installed and working
1244
+ - Python API enabled in iTerm2 preferences
1245
+
1246
+ **Layout:**
1247
+ ```
1248
+ ┌─────────────────┬─────────────────┐
1249
+ │ │ Worker 1 │
1250
+ │ Leader ├─────────────────┤
1251
+ │ (your pane) │ Worker 2 │
1252
+ │ ├─────────────────┤
1253
+ │ │ Worker 3 │
1254
+ └─────────────────┴─────────────────┘
1255
+ ```
1256
+
1257
+ **Pros:**
1258
+ - Visual debugging - see all teammates
1259
+ - Native macOS experience
1260
+ - No tmux needed
1261
+ - Automatic pane management
1262
+
1263
+ **Cons:**
1264
+ - macOS + iTerm2 only
1265
+ - Requires setup (it2 CLI + Python API)
1266
+ - Panes die with window
1267
+
1268
+ **Setup:**
1269
+ ```bash
1270
+ # 1. Install it2 CLI
1271
+ uv tool install it2
1272
+ # OR
1273
+ pipx install it2
1274
+ # OR
1275
+ pip install --user it2
1276
+
1277
+ # 2. Enable Python API in iTerm2
1278
+ # iTerm2 → Settings → General → Magic → Enable Python API
1279
+
1280
+ # 3. Restart iTerm2
1281
+
1282
+ # 4. Verify
1283
+ it2 --version
1284
+ it2 session list
1285
+ ```
1286
+
1287
+ **If setup fails:**
1288
+ Claude Code will prompt you to set up it2 when you first spawn a teammate. You can choose to:
1289
+ 1. Install it2 now (guided setup)
1290
+ 2. Use tmux instead
1291
+ 3. Cancel
1292
+
1293
+ ### Forcing a Backend
1294
+
1295
+ ```bash
1296
+ # Force in-process (fastest, no visibility)
1297
+ export CLAUDE_CODE_SPAWN_BACKEND=in-process
1298
+
1299
+ # Force tmux (visible panes, persistent)
1300
+ export CLAUDE_CODE_SPAWN_BACKEND=tmux
1301
+
1302
+ # Auto-detect (default)
1303
+ unset CLAUDE_CODE_SPAWN_BACKEND
1304
+ ```
1305
+
1306
+ ### Backend in Team Config
1307
+
1308
+ The backend type is recorded per-teammate in `config.json`:
1309
+
1310
+ ```json
1311
+ {
1312
+ "members": [
1313
+ {
1314
+ "name": "worker-1",
1315
+ "backendType": "in-process",
1316
+ "tmuxPaneId": "in-process"
1317
+ },
1318
+ {
1319
+ "name": "worker-2",
1320
+ "backendType": "tmux",
1321
+ "tmuxPaneId": "%5"
1322
+ }
1323
+ ]
1324
+ }
1325
+ ```
1326
+
1327
+ ### Troubleshooting Backends
1328
+
1329
+ | Issue | Cause | Solution |
1330
+ |-------|-------|----------|
1331
+ | "No pane backend available" | Neither tmux nor iTerm2 available | Install tmux: `brew install tmux` |
1332
+ | "it2 CLI not installed" | In iTerm2 but missing it2 | Run `uv tool install it2` |
1333
+ | "Python API not enabled" | it2 can't communicate with iTerm2 | Enable in iTerm2 Settings → General → Magic |
1334
+ | Workers not visible | Using in-process backend | Start inside tmux or iTerm2 |
1335
+ | Workers dying unexpectedly | Outside tmux, leader exited | Use tmux for persistence |
1336
+
1337
+ ### Checking Current Backend
1338
+
1339
+ ```bash
1340
+ # See what backend was detected
1341
+ cat ~/.claude/teams/{team}/config.json | jq '.members[].backendType'
1342
+
1343
+ # Check if inside tmux
1344
+ echo $TMUX
1345
+
1346
+ # Check if in iTerm2
1347
+ echo $TERM_PROGRAM
1348
+
1349
+ # Check tmux availability
1350
+ which tmux
1351
+
1352
+ # Check it2 availability
1353
+ which it2
1354
+ ```
1355
+
1356
+ ---
1357
+
1358
+ ## Error Handling
1359
+
1360
+ ### Common Errors
1361
+
1362
+ | Error | Cause | Solution |
1363
+ |-------|-------|----------|
1364
+ | "Cannot cleanup with active members" | Teammates still running | `requestShutdown` all teammates first, wait for approval |
1365
+ | "Already leading a team" | Team already exists | `cleanup` first, or use different team name |
1366
+ | "Agent not found" | Wrong teammate name | Check `config.json` for actual names |
1367
+ | "Team does not exist" | No team created | Call `spawnTeam` first |
1368
+ | "team_name is required" | Missing team context | Provide `team_name` parameter |
1369
+ | "Agent type not found" | Invalid subagent_type | Check available agents with proper prefix |
1370
+
1371
+ ### Graceful Shutdown Sequence
1372
+
1373
+ **Always follow this sequence:**
1374
+
1375
+ ```javascript
1376
+ // 1. Request shutdown for all teammates
1377
+ Teammate({ operation: "requestShutdown", target_agent_id: "worker-1" })
1378
+ Teammate({ operation: "requestShutdown", target_agent_id: "worker-2" })
1379
+
1380
+ // 2. Wait for shutdown approvals
1381
+ // Check for {"type": "shutdown_approved", ...} messages
1382
+
1383
+ // 3. Verify no active members
1384
+ // Read ~/.claude/teams/{team}/config.json
1385
+
1386
+ // 4. Only then cleanup
1387
+ Teammate({ operation: "cleanup" })
1388
+ ```
1389
+
1390
+ ### Handling Crashed Teammates
1391
+
1392
+ Teammates have a 5-minute heartbeat timeout. If a teammate crashes:
1393
+
1394
+ 1. They'll be automatically marked as inactive after timeout
1395
+ 2. Their tasks remain in the task list
1396
+ 3. Another teammate can claim their tasks
1397
+ 4. Cleanup will work after timeout expires
1398
+
1399
+ ### Debugging
1400
+
1401
+ ```bash
1402
+ # Check team config
1403
+ cat ~/.claude/teams/{team}/config.json | jq '.members[] | {name, agentType, backendType}'
1404
+
1405
+ # Check teammate inboxes
1406
+ cat ~/.claude/teams/{team}/inboxes/{agent}.json | jq '.'
1407
+
1408
+ # List all teams
1409
+ ls ~/.claude/teams/
1410
+
1411
+ # Check task states
1412
+ cat ~/.claude/tasks/{team}/*.json | jq '{id, subject, status, owner, blockedBy}'
1413
+
1414
+ # Watch for new messages
1415
+ tail -f ~/.claude/teams/{team}/inboxes/team-lead.json
1416
+ ```
1417
+
1418
+ ---
1419
+
1420
+ ## Complete Workflows
1421
+
1422
+ ### Workflow 1: Full Code Review with Parallel Specialists
1423
+
1424
+ ```javascript
1425
+ // === STEP 1: Setup ===
1426
+ Teammate({ operation: "spawnTeam", team_name: "pr-review-123", description: "Reviewing PR #123" })
1427
+
1428
+ // === STEP 2: Spawn reviewers in parallel ===
1429
+ // (Send all these in a single message for parallel execution)
1430
+ Task({
1431
+ team_name: "pr-review-123",
1432
+ name: "security",
1433
+ subagent_type: "compound-engineering:review:security-sentinel",
1434
+ prompt: `Review PR #123 for security vulnerabilities.
1435
+
1436
+ Focus on:
1437
+ - SQL injection
1438
+ - XSS vulnerabilities
1439
+ - Authentication/authorization bypass
1440
+ - Sensitive data exposure
1441
+
1442
+ When done, send your findings to team-lead using:
1443
+ Teammate({ operation: "write", target_agent_id: "team-lead", value: "Your findings here" })`,
1444
+ run_in_background: true
1445
+ })
1446
+
1447
+ Task({
1448
+ team_name: "pr-review-123",
1449
+ name: "perf",
1450
+ subagent_type: "compound-engineering:review:performance-oracle",
1451
+ prompt: `Review PR #123 for performance issues.
1452
+
1453
+ Focus on:
1454
+ - N+1 queries
1455
+ - Missing indexes
1456
+ - Memory leaks
1457
+ - Inefficient algorithms
1458
+
1459
+ Send findings to team-lead when done.`,
1460
+ run_in_background: true
1461
+ })
1462
+
1463
+ Task({
1464
+ team_name: "pr-review-123",
1465
+ name: "arch",
1466
+ subagent_type: "compound-engineering:review:architecture-strategist",
1467
+ prompt: `Review PR #123 for architectural concerns.
1468
+
1469
+ Focus on:
1470
+ - Design pattern adherence
1471
+ - SOLID principles
1472
+ - Separation of concerns
1473
+ - Testability
1474
+
1475
+ Send findings to team-lead when done.`,
1476
+ run_in_background: true
1477
+ })
1478
+
1479
+ // === STEP 3: Monitor and collect results ===
1480
+ // Poll inbox or wait for idle notifications
1481
+ // cat ~/.claude/teams/pr-review-123/inboxes/team-lead.json
1482
+
1483
+ // === STEP 4: Synthesize findings ===
1484
+ // Combine all reviewer findings into a cohesive report
1485
+
1486
+ // === STEP 5: Cleanup ===
1487
+ Teammate({ operation: "requestShutdown", target_agent_id: "security" })
1488
+ Teammate({ operation: "requestShutdown", target_agent_id: "perf" })
1489
+ Teammate({ operation: "requestShutdown", target_agent_id: "arch" })
1490
+ // Wait for approvals...
1491
+ Teammate({ operation: "cleanup" })
1492
+ ```
1493
+
1494
+ ### Workflow 2: Research → Plan → Implement → Test Pipeline
1495
+
1496
+ ```javascript
1497
+ // === SETUP ===
1498
+ Teammate({ operation: "spawnTeam", team_name: "feature-oauth" })
1499
+
1500
+ // === CREATE PIPELINE ===
1501
+ TaskCreate({ subject: "Research OAuth providers", description: "Research OAuth2 best practices and compare providers (Google, GitHub, Auth0)", activeForm: "Researching OAuth..." })
1502
+ TaskCreate({ subject: "Create implementation plan", description: "Design OAuth implementation based on research findings", activeForm: "Planning..." })
1503
+ TaskCreate({ subject: "Implement OAuth", description: "Implement OAuth2 authentication according to plan", activeForm: "Implementing OAuth..." })
1504
+ TaskCreate({ subject: "Write tests", description: "Write comprehensive tests for OAuth implementation", activeForm: "Writing tests..." })
1505
+ TaskCreate({ subject: "Final review", description: "Review complete implementation for security and quality", activeForm: "Final review..." })
1506
+
1507
+ // Set dependencies
1508
+ TaskUpdate({ taskId: "2", addBlockedBy: ["1"] })
1509
+ TaskUpdate({ taskId: "3", addBlockedBy: ["2"] })
1510
+ TaskUpdate({ taskId: "4", addBlockedBy: ["3"] })
1511
+ TaskUpdate({ taskId: "5", addBlockedBy: ["4"] })
1512
+
1513
+ // === SPAWN SPECIALIZED WORKERS ===
1514
+ Task({
1515
+ team_name: "feature-oauth",
1516
+ name: "researcher",
1517
+ subagent_type: "compound-engineering:research:best-practices-researcher",
1518
+ prompt: "Claim task #1. Research OAuth2 best practices, compare providers, document findings. Mark task complete and send summary to team-lead.",
1519
+ run_in_background: true
1520
+ })
1521
+
1522
+ Task({
1523
+ team_name: "feature-oauth",
1524
+ name: "planner",
1525
+ subagent_type: "Plan",
1526
+ prompt: "Wait for task #2 to unblock. Read research from task #1. Create detailed implementation plan. Mark complete and send plan to team-lead.",
1527
+ run_in_background: true
1528
+ })
1529
+
1530
+ Task({
1531
+ team_name: "feature-oauth",
1532
+ name: "implementer",
1533
+ subagent_type: "general-purpose",
1534
+ prompt: "Wait for task #3 to unblock. Read plan from task #2. Implement OAuth2 authentication. Mark complete when done.",
1535
+ run_in_background: true
1536
+ })
1537
+
1538
+ Task({
1539
+ team_name: "feature-oauth",
1540
+ name: "tester",
1541
+ subagent_type: "general-purpose",
1542
+ prompt: "Wait for task #4 to unblock. Write comprehensive tests for the OAuth implementation. Run tests. Mark complete with results.",
1543
+ run_in_background: true
1544
+ })
1545
+
1546
+ Task({
1547
+ team_name: "feature-oauth",
1548
+ name: "reviewer",
1549
+ subagent_type: "compound-engineering:review:security-sentinel",
1550
+ prompt: "Wait for task #5 to unblock. Review the complete OAuth implementation for security. Send final assessment to team-lead.",
1551
+ run_in_background: true
1552
+ })
1553
+
1554
+ // Pipeline auto-progresses as each stage completes
1555
+ ```
1556
+
1557
+ ### Workflow 3: Self-Organizing Code Review Swarm
1558
+
1559
+ ```javascript
1560
+ // === SETUP ===
1561
+ Teammate({ operation: "spawnTeam", team_name: "codebase-review" })
1562
+
1563
+ // === CREATE TASK POOL (all independent, no dependencies) ===
1564
+ const filesToReview = [
1565
+ "app/models/user.rb",
1566
+ "app/models/payment.rb",
1567
+ "app/controllers/api/v1/users_controller.rb",
1568
+ "app/controllers/api/v1/payments_controller.rb",
1569
+ "app/services/payment_processor.rb",
1570
+ "app/services/notification_service.rb",
1571
+ "lib/encryption_helper.rb"
1572
+ ]
1573
+
1574
+ for (const file of filesToReview) {
1575
+ TaskCreate({
1576
+ subject: `Review ${file}`,
1577
+ description: `Review ${file} for security vulnerabilities, code quality, and performance issues`,
1578
+ activeForm: `Reviewing ${file}...`
1579
+ })
1580
+ }
1581
+
1582
+ // === SPAWN WORKER SWARM ===
1583
+ const swarmPrompt = `
1584
+ You are a swarm worker. Your job is to continuously process available tasks.
1585
+
1586
+ LOOP:
1587
+ 1. Call TaskList() to see available tasks
1588
+ 2. Find a task that is:
1589
+ - status: 'pending'
1590
+ - no owner
1591
+ - not blocked
1592
+ 3. If found:
1593
+ - Claim it: TaskUpdate({ taskId: "X", owner: "YOUR_NAME" })
1594
+ - Start it: TaskUpdate({ taskId: "X", status: "in_progress" })
1595
+ - Do the review work
1596
+ - Complete it: TaskUpdate({ taskId: "X", status: "completed" })
1597
+ - Send findings to team-lead via Teammate write
1598
+ - Go back to step 1
1599
+ 4. If no tasks available:
1600
+ - Send idle notification to team-lead
1601
+ - Wait 30 seconds
1602
+ - Try again (up to 3 times)
1603
+ - If still no tasks, exit
1604
+
1605
+ Replace YOUR_NAME with your actual agent name from $CLAUDE_CODE_AGENT_NAME.
1606
+ `
1607
+
1608
+ // Spawn 3 workers
1609
+ Task({ team_name: "codebase-review", name: "worker-1", subagent_type: "general-purpose", prompt: swarmPrompt, run_in_background: true })
1610
+ Task({ team_name: "codebase-review", name: "worker-2", subagent_type: "general-purpose", prompt: swarmPrompt, run_in_background: true })
1611
+ Task({ team_name: "codebase-review", name: "worker-3", subagent_type: "general-purpose", prompt: swarmPrompt, run_in_background: true })
1612
+
1613
+ // Workers self-organize: race to claim tasks, naturally load-balance
1614
+ // Monitor progress with TaskList() or by reading inbox
1615
+ ```
1616
+
1617
+ ---
1618
+
1619
+ ## Best Practices
1620
+
1621
+ ### 1. Always Cleanup
1622
+ Don't leave orphaned teams. Always call `cleanup` when done.
1623
+
1624
+ ### 2. Use Meaningful Names
1625
+ ```javascript
1626
+ // Good
1627
+ name: "security-reviewer"
1628
+ name: "oauth-implementer"
1629
+ name: "test-writer"
1630
+
1631
+ // Bad
1632
+ name: "worker-1"
1633
+ name: "agent-2"
1634
+ ```
1635
+
1636
+ ### 3. Write Clear Prompts
1637
+ Tell workers exactly what to do:
1638
+ ```javascript
1639
+ // Good
1640
+ prompt: `
1641
+ 1. Review app/models/user.rb for N+1 queries
1642
+ 2. Check all ActiveRecord associations have proper includes
1643
+ 3. Document any issues found
1644
+ 4. Send findings to team-lead via Teammate write
1645
+ `
1646
+
1647
+ // Bad
1648
+ prompt: "Review the code"
1649
+ ```
1650
+
1651
+ ### 4. Use Task Dependencies
1652
+ Let the system manage unblocking:
1653
+ ```javascript
1654
+ // Good: Auto-unblocking
1655
+ TaskUpdate({ taskId: "2", addBlockedBy: ["1"] })
1656
+
1657
+ // Bad: Manual polling
1658
+ "Wait until task #1 is done, check every 30 seconds..."
1659
+ ```
1660
+
1661
+ ### 5. Check Inboxes for Results
1662
+ Workers send results to your inbox. Check it:
1663
+ ```bash
1664
+ cat ~/.claude/teams/{team}/inboxes/team-lead.json | jq '.'
1665
+ ```
1666
+
1667
+ ### 6. Handle Worker Failures
1668
+ - Workers have 5-minute heartbeat timeout
1669
+ - Tasks of crashed workers can be reclaimed
1670
+ - Build retry logic into worker prompts
1671
+
1672
+ ### 7. Prefer write Over broadcast
1673
+ `broadcast` sends N messages for N teammates. Use `write` for targeted communication.
1674
+
1675
+ ### 8. Match Agent Type to Task
1676
+ - **Explore** for searching/reading
1677
+ - **Plan** for architecture design
1678
+ - **general-purpose** for implementation
1679
+ - **Specialized reviewers** for specific review types
1680
+
1681
+ ---
1682
+
1683
+ ## Quick Reference
1684
+
1685
+ ### Spawn Subagent (No Team)
1686
+ ```javascript
1687
+ Task({ subagent_type: "Explore", description: "Find files", prompt: "..." })
1688
+ ```
1689
+
1690
+ ### Spawn Teammate (With Team)
1691
+ ```javascript
1692
+ Teammate({ operation: "spawnTeam", team_name: "my-team" })
1693
+ Task({ team_name: "my-team", name: "worker", subagent_type: "general-purpose", prompt: "...", run_in_background: true })
1694
+ ```
1695
+
1696
+ ### Message Teammate
1697
+ ```javascript
1698
+ Teammate({ operation: "write", target_agent_id: "worker-1", value: "..." })
1699
+ ```
1700
+
1701
+ ### Create Task Pipeline
1702
+ ```javascript
1703
+ TaskCreate({ subject: "Step 1", description: "..." })
1704
+ TaskCreate({ subject: "Step 2", description: "..." })
1705
+ TaskUpdate({ taskId: "2", addBlockedBy: ["1"] })
1706
+ ```
1707
+
1708
+ ### Shutdown Team
1709
+ ```javascript
1710
+ Teammate({ operation: "requestShutdown", target_agent_id: "worker-1" })
1711
+ // Wait for approval...
1712
+ Teammate({ operation: "cleanup" })
1713
+ ```
1714
+
1715
+ ---
1716
+
1717
+ *Based on Claude Code v2.1.19 - Tested and verified 2026-01-25*