@fro.bot/systematic 2.33.3 → 3.0.1

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