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