claude_swarm 1.0.6 → 1.0.8

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +27 -0
  4. data/README.md +336 -1037
  5. data/docs/V1_TO_V2_MIGRATION_GUIDE.md +1120 -0
  6. data/docs/v1/README.md +1197 -0
  7. data/docs/v2/CHANGELOG.swarm_cli.md +22 -0
  8. data/docs/v2/CHANGELOG.swarm_memory.md +20 -0
  9. data/docs/v2/CHANGELOG.swarm_sdk.md +287 -10
  10. data/docs/v2/README.md +32 -6
  11. data/docs/v2/guides/complete-tutorial.md +133 -37
  12. data/docs/v2/guides/composable-swarms.md +1178 -0
  13. data/docs/v2/guides/getting-started.md +42 -1
  14. data/docs/v2/guides/snapshots.md +1498 -0
  15. data/docs/v2/reference/architecture-flow.md +5 -3
  16. data/docs/v2/reference/event_payload_structures.md +249 -12
  17. data/docs/v2/reference/execution-flow.md +1 -1
  18. data/docs/v2/reference/ruby-dsl.md +368 -22
  19. data/docs/v2/reference/yaml.md +314 -63
  20. data/examples/snapshot_demo.rb +119 -0
  21. data/examples/v2/dsl/01_basic.rb +0 -2
  22. data/examples/v2/dsl/02_core_parameters.rb +0 -2
  23. data/examples/v2/dsl/03_capabilities.rb +0 -2
  24. data/examples/v2/dsl/04_llm_parameters.rb +0 -2
  25. data/examples/v2/dsl/05_advanced_flags.rb +0 -3
  26. data/examples/v2/dsl/06_permissions.rb +0 -4
  27. data/examples/v2/dsl/07_mcp_server.rb +0 -2
  28. data/examples/v2/dsl/08_swarm_hooks.rb +0 -2
  29. data/examples/v2/dsl/09_agent_hooks.rb +0 -2
  30. data/examples/v2/dsl/10_all_agents_hooks.rb +0 -3
  31. data/examples/v2/dsl/11_delegation.rb +0 -2
  32. data/examples/v2/dsl/12_complete_integration.rb +2 -6
  33. data/examples/v2/node_context_demo.rb +1 -1
  34. data/examples/v2/node_workflow.rb +2 -4
  35. data/examples/v2/plan_and_execute.rb +157 -0
  36. data/lib/claude_swarm/cli.rb +0 -18
  37. data/lib/claude_swarm/configuration.rb +28 -18
  38. data/lib/claude_swarm/openai/chat_completion.rb +2 -11
  39. data/lib/claude_swarm/openai/responses.rb +2 -11
  40. data/lib/claude_swarm/version.rb +1 -1
  41. data/lib/swarm_cli/formatters/human_formatter.rb +103 -0
  42. data/lib/swarm_cli/interactive_repl.rb +9 -3
  43. data/lib/swarm_cli/version.rb +1 -1
  44. data/lib/swarm_memory/core/storage_read_tracker.rb +51 -14
  45. data/lib/swarm_memory/integration/cli_registration.rb +3 -2
  46. data/lib/swarm_memory/integration/sdk_plugin.rb +11 -5
  47. data/lib/swarm_memory/tools/memory_edit.rb +2 -2
  48. data/lib/swarm_memory/tools/memory_multi_edit.rb +2 -2
  49. data/lib/swarm_memory/tools/memory_read.rb +3 -3
  50. data/lib/swarm_memory/version.rb +1 -1
  51. data/lib/swarm_memory.rb +5 -0
  52. data/lib/swarm_sdk/agent/builder.rb +33 -0
  53. data/lib/swarm_sdk/agent/chat/context_tracker.rb +33 -0
  54. data/lib/swarm_sdk/agent/chat/hook_integration.rb +49 -3
  55. data/lib/swarm_sdk/agent/chat/system_reminder_injector.rb +11 -27
  56. data/lib/swarm_sdk/agent/chat.rb +200 -51
  57. data/lib/swarm_sdk/agent/context.rb +6 -2
  58. data/lib/swarm_sdk/agent/context_manager.rb +6 -0
  59. data/lib/swarm_sdk/agent/definition.rb +14 -2
  60. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +180 -0
  61. data/lib/swarm_sdk/configuration.rb +387 -94
  62. data/lib/swarm_sdk/events_to_messages.rb +181 -0
  63. data/lib/swarm_sdk/log_collector.rb +31 -5
  64. data/lib/swarm_sdk/log_stream.rb +37 -8
  65. data/lib/swarm_sdk/model_aliases.json +4 -1
  66. data/lib/swarm_sdk/node/agent_config.rb +33 -8
  67. data/lib/swarm_sdk/node/builder.rb +39 -18
  68. data/lib/swarm_sdk/node_orchestrator.rb +293 -26
  69. data/lib/swarm_sdk/proc_helpers.rb +53 -0
  70. data/lib/swarm_sdk/providers/openai_with_responses.rb +22 -15
  71. data/lib/swarm_sdk/restore_result.rb +65 -0
  72. data/lib/swarm_sdk/snapshot.rb +156 -0
  73. data/lib/swarm_sdk/snapshot_from_events.rb +386 -0
  74. data/lib/swarm_sdk/state_restorer.rb +491 -0
  75. data/lib/swarm_sdk/state_snapshot.rb +369 -0
  76. data/lib/swarm_sdk/swarm/agent_initializer.rb +360 -55
  77. data/lib/swarm_sdk/swarm/all_agents_builder.rb +28 -1
  78. data/lib/swarm_sdk/swarm/builder.rb +208 -12
  79. data/lib/swarm_sdk/swarm/swarm_registry_builder.rb +67 -0
  80. data/lib/swarm_sdk/swarm/tool_configurator.rb +46 -11
  81. data/lib/swarm_sdk/swarm.rb +338 -42
  82. data/lib/swarm_sdk/swarm_loader.rb +145 -0
  83. data/lib/swarm_sdk/swarm_registry.rb +136 -0
  84. data/lib/swarm_sdk/tools/delegate.rb +92 -7
  85. data/lib/swarm_sdk/tools/read.rb +17 -5
  86. data/lib/swarm_sdk/tools/stores/read_tracker.rb +47 -12
  87. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +45 -0
  88. data/lib/swarm_sdk/utils.rb +18 -0
  89. data/lib/swarm_sdk/validation_result.rb +33 -0
  90. data/lib/swarm_sdk/version.rb +1 -1
  91. data/lib/swarm_sdk.rb +40 -8
  92. data/swarm_cli.gemspec +1 -1
  93. data/swarm_memory.gemspec +2 -2
  94. data/swarm_sdk.gemspec +2 -2
  95. metadata +21 -13
  96. data/examples/learning-assistant/assistant.md +0 -7
  97. data/examples/learning-assistant/example-memories/concept-example.md +0 -90
  98. data/examples/learning-assistant/example-memories/experience-example.md +0 -66
  99. data/examples/learning-assistant/example-memories/fact-example.md +0 -76
  100. data/examples/learning-assistant/example-memories/memory-index.md +0 -78
  101. data/examples/learning-assistant/example-memories/skill-example.md +0 -168
  102. data/examples/learning-assistant/learning_assistant.rb +0 -34
  103. data/examples/learning-assistant/learning_assistant.yml +0 -20
  104. data/lib/swarm_sdk/mcp.rb +0 -16
  105. data/llm.v2.txt +0 -13407
  106. /data/docs/v2/guides/{MEMORY_DEFRAG_GUIDE.md → memory-defrag-guide.md} +0 -0
  107. /data/{llms.txt → llms.claude-swarm.txt} +0 -0
data/docs/v1/README.md ADDED
@@ -0,0 +1,1197 @@
1
+ # Claude Swarm (v1)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/claude_swarm.svg?cache_bust1=1.0.1)](https://badge.fury.io/rb/claude_swarm)
4
+ [![CI](https://github.com/parruda/claude-swarm/actions/workflows/ci.yml/badge.svg)](https://github.com/parruda/claude-swarm/actions/workflows/ci.yml)
5
+ [![Mentioned in Awesome Claude Code](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/hesreallyhim/awesome-claude-code)
6
+
7
+
8
+ > **Note**: This is the documentation for Claude Swarm v1, which uses a multi-process architecture with Claude Code instances. For new projects, we recommend using [SwarmSDK v2](../v2/README.md) which offers a single-process architecture, better performance, and more features.
9
+
10
+ Claude Swarm orchestrates multiple Claude Code instances as a collaborative AI development team. It enables running AI agents with specialized roles, tools, and directory contexts, communicating via MCP (Model Context Protocol) in a tree-like hierarchy. Define your swarm topology in simple YAML and let Claude instances delegate tasks through connected instances. Perfect for complex projects requiring specialized AI agents for frontend, backend, testing, DevOps, or research tasks.
11
+
12
+ ---
13
+
14
+ ## Table of Contents
15
+
16
+ - [Installation](#installation)
17
+ - [Prerequisites](#prerequisites)
18
+ - [Usage](#usage)
19
+ - [Quick Start](#quick-start)
20
+ - [Configuration Format](#configuration-format)
21
+ - [MCP Server Types](#mcp-server-types)
22
+ - [Tools](#tools)
23
+ - [Examples](#examples)
24
+ - [Command Line Options](#command-line-options)
25
+ - [Session Monitoring](#session-monitoring)
26
+ - [Session Management and Restoration](#session-management-and-restoration-experimental)
27
+ - [How It Works](#how-it-works)
28
+ - [Troubleshooting](#troubleshooting)
29
+ - [Architecture](#architecture)
30
+ - [Development](#development)
31
+ - [Contributing](#contributing)
32
+ - [License](#license)
33
+
34
+ ## Installation
35
+
36
+ Install [Claude CLI](https://docs.anthropic.com/en/docs/claude-code/overview) if you haven't already:
37
+
38
+ ```bash
39
+ npm install -g @anthropic-ai/claude-code
40
+ ```
41
+
42
+ Install this gem by executing:
43
+
44
+ ```bash
45
+ gem install claude_swarm
46
+ ```
47
+
48
+ Or add it to your Gemfile:
49
+
50
+ ```ruby
51
+ gem 'claude_swarm', "~> 1.0"
52
+ ```
53
+
54
+ Then run:
55
+
56
+ ```bash
57
+ bundle install
58
+ ```
59
+
60
+ ## Prerequisites
61
+
62
+ - Ruby 3.2.0 or higher
63
+ - Claude CLI installed and configured
64
+ - Any MCP servers you plan to use (optional)
65
+
66
+ ## Usage
67
+
68
+ ### Quick Start
69
+
70
+ 1. Run `claude-swarm init` to create a basic template, or use `claude-swarm generate` for an interactive configuration experience with Claude's help. You can also manually create a `claude-swarm.yml` file in your project:
71
+
72
+ ```yaml
73
+ version: 1
74
+ swarm:
75
+ name: "My Dev Team"
76
+ main: lead
77
+ instances:
78
+ lead:
79
+ description: "Team lead coordinating development efforts"
80
+ directory: .
81
+ model: opus
82
+ connections: [frontend, backend]
83
+ vibe: true # Allow all tools for this instance
84
+ frontend:
85
+ description: "Frontend specialist handling UI and user experience"
86
+ directory: ./frontend
87
+ model: opus
88
+ allowed_tools: # Tools aren't required if you run it with `--vibe`
89
+ - Edit
90
+ - Write
91
+ - Bash
92
+ backend:
93
+ description: "Backend developer managing APIs and data layer"
94
+ directory: ./backend
95
+ model: opus
96
+ allowed_tools:
97
+ - Edit
98
+ - Write
99
+ - Bash
100
+ ```
101
+
102
+ 2. Start the swarm:
103
+
104
+ ```bash
105
+ claude-swarm
106
+ ```
107
+
108
+ or if you are feeling the vibes...
109
+
110
+ ```bash
111
+ claude-swarm --vibe # That will allow ALL tools for all instances! Be Careful!
112
+ ```
113
+
114
+ This will:
115
+
116
+ - Launch the main instance (lead) with connections to other instances
117
+ - The lead instance can communicate with the other instances via MCP
118
+ - All session files are stored in `~/.claude-swarm/sessions/{project}/{timestamp}/` (customizable via `CLAUDE_SWARM_HOME`)
119
+
120
+ #### Multi-Level Swarm Example
121
+
122
+ Here's a more complex example showing specialized teams working on different parts of a project:
123
+
124
+ ```yaml
125
+ version: 1
126
+ swarm:
127
+ name: "Multi-Service Development Team"
128
+ main: architect
129
+ instances:
130
+ architect:
131
+ description: "System architect coordinating between service teams"
132
+ directory: .
133
+ model: opus
134
+ connections: [frontend_lead, backend_lead, mobile_lead, devops]
135
+ prompt: "You are the system architect coordinating between different service teams"
136
+ allowed_tools: [Read, Edit, WebSearch]
137
+
138
+ frontend_lead:
139
+ description: "Frontend team lead overseeing React development"
140
+ directory: ./web-frontend
141
+ model: opus
142
+ connections: [react_dev, css_expert]
143
+ prompt: "You lead the web frontend team working with React"
144
+ allowed_tools: [Read, Edit, Bash]
145
+
146
+ react_dev:
147
+ description: "React developer specializing in components and state management"
148
+ directory: ./web-frontend/src
149
+ model: opus
150
+ prompt: "You specialize in React components and state management"
151
+ allowed_tools: [Edit, Write, Bash]
152
+
153
+ css_expert:
154
+ description: "CSS specialist handling styling and responsive design"
155
+ directory: ./web-frontend/styles
156
+ model: opus
157
+ prompt: "You handle all CSS and styling concerns"
158
+ allowed_tools: [Edit, Write, Read]
159
+
160
+ backend_lead:
161
+ description: "Backend team lead managing API development"
162
+ directory: ./api-server
163
+ model: opus
164
+ connections: [api_dev, database_expert]
165
+ prompt: "You lead the API backend team"
166
+ allowed_tools: [Read, Edit, Bash]
167
+
168
+ api_dev:
169
+ description: "API developer building REST endpoints"
170
+ directory: ./api-server/src
171
+ model: opus
172
+ prompt: "You develop REST API endpoints"
173
+ allowed_tools: [Edit, Write, Bash]
174
+
175
+ database_expert:
176
+ description: "Database specialist managing schemas and migrations"
177
+ directory: ./api-server/db
178
+ model: opus
179
+ prompt: "You handle database schema and migrations"
180
+ allowed_tools: [Edit, Write, Bash]
181
+
182
+ mobile_lead:
183
+ description: "Mobile team lead coordinating cross-platform development"
184
+ directory: ./mobile-app
185
+ model: opus
186
+ connections: [ios_dev, android_dev]
187
+ prompt: "You coordinate mobile development across platforms"
188
+ allowed_tools: [Read, Edit]
189
+
190
+ ios_dev:
191
+ description: "iOS developer building native Apple applications"
192
+ directory: ./mobile-app/ios
193
+ model: opus
194
+ prompt: "You develop the iOS application"
195
+ allowed_tools: [Edit, Write, Bash]
196
+
197
+ android_dev:
198
+ description: "Android developer creating native Android apps"
199
+ directory: ./mobile-app/android
200
+ model: opus
201
+ prompt: "You develop the Android application"
202
+ allowed_tools: [Edit, Write, Bash]
203
+
204
+ devops:
205
+ description: "DevOps engineer managing CI/CD and infrastructure"
206
+ directory: ./infrastructure
207
+ model: opus
208
+ prompt: "You handle CI/CD and infrastructure"
209
+ allowed_tools: [Read, Edit, Bash]
210
+ ```
211
+
212
+ In this setup:
213
+
214
+ - The architect (main instance) can delegate tasks to team leads
215
+ - Each team lead can work with their specialized developers
216
+ - Each instance is independent - connections create separate MCP server instances
217
+ - Teams work in isolated directories with role-appropriate tools
218
+ - Connected instances are accessible via MCP tools like `mcp__frontend_lead__task`, `mcp__backend_lead__task`, etc.
219
+
220
+ ### Configuration Format
221
+
222
+ #### Top Level
223
+
224
+ ```yaml
225
+ version: 1 # Required, currently only version 1 is supported
226
+ swarm:
227
+ name: "Swarm Name" # Display name for your swarm
228
+ main: instance_key # Which instance to launch as the main interface
229
+ before: # Optional: commands to run before launching the swarm
230
+ - "echo 'Setting up environment...'"
231
+ - "npm install"
232
+ - "docker-compose up -d"
233
+ after: # Optional: commands to run after exiting the swarm
234
+ - "echo 'Cleaning up environment...'"
235
+ - "docker-compose down"
236
+ instances:
237
+ # Instance definitions...
238
+ ```
239
+
240
+ #### YAML Aliases
241
+
242
+ Claude Swarm supports [YAML aliases](https://yaml.org/spec/1.2.2/#71-alias-nodes) to reduce duplication in your configuration. This is particularly useful for sharing common values like prompts, tool lists, or MCP configurations across multiple instances:
243
+
244
+ ```yaml
245
+ version: 1
246
+ swarm:
247
+ name: "Development Team"
248
+ main: lead
249
+ instances:
250
+ lead:
251
+ description: "Lead developer"
252
+ prompt: &shared_prompt "You are an expert developer following best practices"
253
+ allowed_tools: &standard_tools
254
+ - Read
255
+ - Edit
256
+ - Bash
257
+ - WebSearch
258
+ mcps: &common_mcps
259
+ - name: github
260
+ type: stdio
261
+ command: gh
262
+ args: ["mcp"]
263
+
264
+ frontend:
265
+ description: "Frontend developer"
266
+ prompt: *shared_prompt # Reuses the same prompt
267
+ allowed_tools: *standard_tools # Reuses the same tool list
268
+ mcps: *common_mcps # Reuses the same MCP servers
269
+ directory: ./frontend
270
+
271
+ backend:
272
+ description: "Backend developer"
273
+ prompt: *shared_prompt # Reuses the same prompt
274
+ allowed_tools: *standard_tools # Reuses the same tool list
275
+ mcps: *common_mcps # Reuses the same MCP servers
276
+ directory: ./backend
277
+ ```
278
+
279
+ In this example:
280
+
281
+ - `&shared_prompt` defines an anchor for the prompt string
282
+ - `&standard_tools` defines an anchor for the tool array
283
+ - `&common_mcps` defines an anchor for the MCP configuration
284
+ - `*shared_prompt`, `*standard_tools`, and `*common_mcps` reference those anchors
285
+
286
+ This helps maintain consistency across instances and makes configuration updates easier.
287
+
288
+ #### Environment Variable Interpolation
289
+
290
+ Claude Swarm supports environment variable interpolation in all configuration values using the `${ENV_VAR_NAME}` syntax:
291
+
292
+ ```yaml
293
+ version: 1
294
+ swarm:
295
+ name: "${APP_NAME} Development Team"
296
+ main: lead
297
+ instances:
298
+ lead:
299
+ description: "Lead developer for ${APP_NAME}"
300
+ directory: "${PROJECT_ROOT}"
301
+ model: "${CLAUDE_MODEL}"
302
+ prompt: "You are developing ${APP_NAME} version ${APP_VERSION}"
303
+ allowed_tools: ["${TOOL_1}", "${TOOL_2}", "Bash"]
304
+ mcps:
305
+ - name: github
306
+ type: stdio
307
+ command: "${MCP_GITHUB_PATH}"
308
+ env:
309
+ GITHUB_TOKEN: "${GITHUB_TOKEN}"
310
+ ```
311
+
312
+ Features:
313
+
314
+ - Variables are interpolated recursively in strings, arrays, and nested structures
315
+ - Multiple variables can be used in the same string
316
+ - Partial string interpolation is supported (e.g., `"prefix-${VAR}-suffix"`)
317
+ - If a referenced environment variable is not set, Claude Swarm will exit with a clear error message
318
+ - Non-matching patterns like `$VAR` or `{VAR}` are preserved as-is
319
+
320
+ ##### Default Values
321
+
322
+ Environment variables can have default values using the `${VAR_NAME:=default_value}` syntax:
323
+
324
+ ```yaml
325
+ version: 1
326
+ swarm:
327
+ name: "Dev Team"
328
+ main: lead
329
+ instances:
330
+ lead:
331
+ description: "Lead developer"
332
+ directory: "${PROJECT_DIR:=.}"
333
+ model: "${CLAUDE_MODEL:=sonnet}"
334
+ mcps:
335
+ - name: api-server
336
+ type: sse
337
+ url: "${API_URL:=http://localhost:8080}"
338
+ worktree: "${BRANCH_NAME:=feature-branch}"
339
+ ```
340
+
341
+ - Default values are used when the environment variable is not set
342
+ - Any string can be used as a default value, including spaces and special characters
343
+ - Empty defaults are supported: `${VAR:=}` results in an empty string if VAR is not set
344
+ - Works in all configuration values: strings, arrays, and nested structures
345
+
346
+ #### Instance Configuration
347
+
348
+ Each instance must have:
349
+
350
+ - **description** (required): Brief description of the agent's role (used in task tool descriptions)
351
+
352
+ Each instance can have:
353
+
354
+ - **directory**: Working directory for this instance (can use ~ for home). Can be a string for a single directory or an array of strings for multiple directories
355
+ - **model**: Claude model to use (opus, sonnet)
356
+ - **connections**: Array of other instances this one can communicate with
357
+ - **allowed_tools**: Array of tools this instance can use (backward compatible with `tools`)
358
+ - **disallowed_tools**: Array of tools to explicitly deny (takes precedence over allowed_tools)
359
+ - **mcps**: Array of additional MCP servers to connect
360
+ - **prompt**: Custom system prompt to append to the instance
361
+ - **vibe**: Enable vibe mode (--dangerously-skip-permissions) for this instance (default: false)
362
+ - **worktree**: Configure Git worktree usage for this instance (true/false/string)
363
+ - **provider**: AI provider to use - "claude" (default) or "openai"
364
+ - **hooks**: Configure Claude Code hooks for this instance (see Hooks Configuration section below)
365
+
366
+ #### OpenAI Provider Configuration
367
+
368
+ When using `provider: openai`, the following additional fields are available:
369
+
370
+ - **temperature**: Temperature for GPT models only (0.0-2.0). Not supported for O-series reasoning models (o1, o1-preview, o1-mini, o3, etc.)
371
+ - **api_version**: API version to use - "chat_completion" (default) or "responses"
372
+ - **openai_token_env**: Environment variable name for OpenAI API key (default: "OPENAI_API_KEY")
373
+ - **base_url**: Custom base URL for OpenAI API (optional)
374
+ - **reasoning_effort**: Reasoning effort for O-series models only - "low", "medium", or "high"
375
+
376
+ **Important Notes:**
377
+
378
+ - O-series models (o1, o1-preview, o1-mini, o3, etc.) use deterministic reasoning and do not support the `temperature` parameter
379
+ - The `reasoning_effort` parameter is only supported by O-series models
380
+ - GPT models support `temperature` but not `reasoning_effort`
381
+ - OpenAI instances default to and ONLY operate as `vibe: true` and use MCP for tool access
382
+ - By default it comes with Claude Code tools, connected with MCP to `claude mcp serve`
383
+ - **Using the responses API requires ruby-openai >= 8.0** - the gem will validate this requirement at runtime
384
+
385
+ ```yaml
386
+ instance_name:
387
+ description: "Specialized agent focused on specific tasks"
388
+ directory: ~/project/path
389
+ model: opus
390
+ connections: [other_instance1, other_instance2]
391
+ prompt: "You are a specialized agent focused on..."
392
+ vibe: false # Set to true to skip all permission checks for this instance
393
+ allowed_tools:
394
+ - Read
395
+ - Edit
396
+ - Write
397
+ - Bash
398
+ - WebFetch
399
+ - WebSearch
400
+ disallowed_tools: # Optional: explicitly deny specific tools
401
+ - "Write(*.log)"
402
+ - "Bash(rm:*)"
403
+ mcps:
404
+ - name: server_name
405
+ type: stdio
406
+ command: command_to_run
407
+ args: ["arg1", "arg2"]
408
+ env:
409
+ VAR1: value1
410
+
411
+ # OpenAI instance examples
412
+
413
+ # GPT model with temperature
414
+ gpt_instance:
415
+ description: "OpenAI GPT-powered creative assistant"
416
+ provider: openai
417
+ model: gpt-4o
418
+ temperature: 0.7 # Supported for GPT models
419
+ api_version: chat_completion
420
+ openai_token_env: OPENAI_API_KEY
421
+ prompt: "You are a creative assistant specializing in content generation"
422
+
423
+ # O-series reasoning model with reasoning_effort
424
+ reasoning_instance:
425
+ description: "OpenAI O-series reasoning assistant"
426
+ provider: openai
427
+ model: o1-mini
428
+ reasoning_effort: medium # Only for O-series models
429
+ api_version: responses # Can use either API version
430
+ prompt: "You are a reasoning assistant for complex problem solving"
431
+ ```
432
+
433
+ ### MCP Server Types
434
+
435
+ #### stdio (Standard I/O)
436
+
437
+ ```yaml
438
+ mcps:
439
+ - name: my_tool
440
+ type: stdio
441
+ command: /path/to/executable
442
+ args: ["--flag", "value"]
443
+ env:
444
+ API_KEY: "secret"
445
+ ```
446
+
447
+ #### sse (Server-Sent Events)
448
+
449
+ ```yaml
450
+ mcps:
451
+ - name: remote_api
452
+ type: sse
453
+ url: "https://api.example.com/mcp"
454
+ headers: # Optional: custom headers for authentication
455
+ Authorization: "Bearer ${API_TOKEN}"
456
+ X-Custom-Header: "value"
457
+ ```
458
+
459
+ #### http (HTTP-based MCP)
460
+
461
+ ```yaml
462
+ mcps:
463
+ - name: http_service
464
+ type: http
465
+ url: "https://api.example.com/mcp-endpoint"
466
+ headers: # Optional: custom headers for authentication
467
+ Authorization: "Bearer ${API_TOKEN}"
468
+ X-API-Key: "${API_KEY}"
469
+ ```
470
+
471
+ ### Hooks Configuration
472
+
473
+ Claude Swarm supports configuring [Claude Code hooks](https://docs.anthropic.com/en/docs/claude-code/hooks) for each instance. Hooks allow you to run custom scripts before/after tools, on prompt submission, and more. Each instance can have its own hooks configuration.
474
+
475
+ #### Supported Hook Events
476
+
477
+ - **PreToolUse**: Run before a tool is executed
478
+ - **PostToolUse**: Run after a tool completes
479
+ - **UserPromptSubmit**: Run when a user prompt is submitted
480
+ - **Stop**: Run when the Claude instance stops
481
+ - **SessionStart**: Run when a session starts
482
+ - **And more...** (see Claude Code hooks documentation)
483
+
484
+ #### Configuration Example
485
+
486
+ ```yaml
487
+ instances:
488
+ lead:
489
+ description: "Lead developer"
490
+ directory: .
491
+ # Hooks configuration follows Claude Code's format exactly
492
+ hooks:
493
+ PreToolUse:
494
+ - matcher: "Write|Edit"
495
+ hooks:
496
+ - type: "command"
497
+ command: "$CLAUDE_PROJECT_DIR/.claude/hooks/validate-code.py"
498
+ timeout: 10
499
+ PostToolUse:
500
+ - matcher: "Bash"
501
+ hooks:
502
+ - type: "command"
503
+ command: "echo 'Bash executed by ${INSTANCE_NAME}' >> ${LOG_DIR}/commands.log"
504
+ UserPromptSubmit:
505
+ - hooks:
506
+ - type: "command"
507
+ command: "${HOOKS_DIR:=$CLAUDE_PROJECT_DIR/.claude/hooks}/add-context.py"
508
+ frontend:
509
+ description: "Frontend developer"
510
+ directory: ./frontend
511
+ hooks:
512
+ PreToolUse:
513
+ - matcher: "Write"
514
+ hooks:
515
+ - type: "command"
516
+ command: "npm run lint"
517
+ timeout: 5
518
+ ```
519
+
520
+ #### How It Works
521
+
522
+ 1. Define hooks in your instance configuration using the exact format expected by Claude Code
523
+ 2. Claude Swarm generates a `settings.json` file for each instance with hooks
524
+ 3. The settings file is passed to Claude Code SDK via the `--settings` parameter
525
+ 4. Each instance runs with its own hooks configuration
526
+
527
+ #### Environment Variables in Hooks
528
+
529
+ Hooks have access to standard Claude Code environment variables plus:
530
+
531
+ - `$CLAUDE_PROJECT_DIR` - The project directory
532
+ - `$CLAUDE_SWARM_SESSION_DIR` - The swarm session directory
533
+ - `$CLAUDE_SWARM_INSTANCE_NAME` - The name of the current instance
534
+
535
+ ### Tools
536
+
537
+ Specify which tools each instance can use:
538
+
539
+ ```yaml
540
+ allowed_tools:
541
+ - Bash # Command execution
542
+ - Edit # File editing
543
+ - Write # File creation
544
+ - Read # File reading
545
+ - WebFetch # Fetch web content
546
+ - WebSearch # Search the web
547
+
548
+ # Note: Pattern-based tool restrictions have been deprecated.
549
+ # Use allowed_tools and disallowed_tools with tool names only.
550
+ ```
551
+
552
+ Tools are passed to Claude using the `--allowedTools` and `--disallowedTools` flags with comma-separated values. Disallowed tools take precedence over allowed tools.
553
+
554
+ #### Available Tools
555
+
556
+ ```yaml
557
+ allowed_tools:
558
+ - Read # File reading
559
+ - Edit # File editing
560
+ - Write # File creation
561
+ - Bash # Command execution
562
+ - WebFetch # Fetch web content
563
+ - WebSearch # Search the web
564
+ ```
565
+
566
+ ### Examples
567
+
568
+ #### Full Stack Development Team
569
+
570
+ ```yaml
571
+ version: 1
572
+ swarm:
573
+ name: "Full Stack Team"
574
+ main: architect
575
+ instances:
576
+ architect:
577
+ description: "Lead architect responsible for system design and code quality"
578
+ directory: .
579
+ model: opus
580
+ connections: [frontend, backend, devops]
581
+ prompt: "You are the lead architect responsible for system design and code quality"
582
+ allowed_tools:
583
+ - Read
584
+ - Edit
585
+ - WebSearch
586
+
587
+ frontend:
588
+ description: "Frontend developer specializing in React and TypeScript"
589
+ directory: ./frontend
590
+ model: opus
591
+ connections: [architect]
592
+ prompt: "You specialize in React, TypeScript, and modern frontend development"
593
+ allowed_tools:
594
+ - Edit
595
+ - Write
596
+ - Bash
597
+
598
+ backend:
599
+ description: "Backend developer building APIs and services"
600
+ directory: ./backend
601
+ model: opus
602
+ connections: [database]
603
+ allowed_tools:
604
+ - Edit
605
+ - Write
606
+ - Bash
607
+
608
+ database:
609
+ description: "Database administrator managing data persistence"
610
+ directory: ./db
611
+ model: sonnet
612
+ allowed_tools:
613
+ - Read
614
+ - Bash
615
+
616
+ devops:
617
+ description: "DevOps engineer handling deployment and infrastructure"
618
+ directory: .
619
+ model: opus
620
+ connections: [architect]
621
+ allowed_tools:
622
+ - Read
623
+ - Edit
624
+ - Bash
625
+ ```
626
+
627
+ #### Research Team with External Tools
628
+
629
+ ```yaml
630
+ version: 1
631
+ swarm:
632
+ name: "Research Team"
633
+ main: lead_researcher
634
+ instances:
635
+ lead_researcher:
636
+ description: "Lead researcher coordinating analysis and documentation"
637
+ directory: ~/research
638
+ model: opus
639
+ connections: [data_analyst, writer]
640
+ allowed_tools:
641
+ - Read
642
+ - WebSearch
643
+ - WebFetch
644
+ mcps:
645
+ - name: arxiv
646
+ type: sse
647
+ url: "https://arxiv-mcp.example.com"
648
+
649
+ data_analyst:
650
+ description: "Data analyst processing research data and statistics"
651
+ directory: ~/research/data
652
+ model: opus
653
+ allowed_tools:
654
+ - Read
655
+ - Write
656
+ - Bash
657
+ mcps:
658
+ - name: jupyter
659
+ type: stdio
660
+ command: jupyter-mcp
661
+ args: ["--notebook-dir", "."]
662
+
663
+ writer:
664
+ description: "Technical writer preparing research documentation"
665
+ directory: ~/research/papers
666
+ model: opus
667
+ allowed_tools:
668
+ - Edit
669
+ - Write
670
+ - Read
671
+ ```
672
+
673
+ #### Multi-Directory Support
674
+
675
+ Instances can have access to multiple directories using an array (uses `claude --add-dir`):
676
+
677
+ ```yaml
678
+ version: 1
679
+ swarm:
680
+ name: "Multi-Module Project"
681
+ main: fullstack_dev
682
+ instances:
683
+ fullstack_dev:
684
+ description: "Full-stack developer working across multiple modules"
685
+ directory: [./frontend, ./backend, ./shared] # Access to multiple directories
686
+ model: opus
687
+ allowed_tools: [Read, Edit, Write, Bash]
688
+ prompt: "You work across frontend, backend, and shared code modules"
689
+
690
+ documentation_writer:
691
+ description: "Documentation specialist with access to code and docs"
692
+ directory: ["./docs", "./src", "./examples"] # Multiple directories as array
693
+ model: sonnet
694
+ allowed_tools: [Read, Write, Edit]
695
+ prompt: "You maintain documentation based on code and examples"
696
+ ```
697
+
698
+ When using multiple directories:
699
+
700
+ - The first directory in the array is the primary working directory
701
+ - Additional directories are accessible via the `--add-dir` flag in Claude
702
+ - All directories must exist or the configuration will fail validation
703
+
704
+ #### Mixed AI Provider Team
705
+
706
+ Combine Claude and OpenAI instances in a single swarm:
707
+
708
+ ```yaml
709
+ version: 1
710
+ swarm:
711
+ name: "Mixed AI Development Team"
712
+ main: lead_developer
713
+ instances:
714
+ lead_developer:
715
+ description: "Claude lead developer coordinating the team"
716
+ directory: .
717
+ model: opus
718
+ connections: [creative_assistant, reasoning_expert, backend_dev]
719
+ prompt: "You are the lead developer coordinating a mixed AI team"
720
+ allowed_tools: [Read, Edit, Bash, Write]
721
+
722
+ creative_assistant:
723
+ description: "OpenAI-powered assistant for creative and UI/UX tasks"
724
+ provider: openai
725
+ model: gpt-4o
726
+ temperature: 0.7 # Supported for GPT models
727
+ directory: ./frontend
728
+ prompt: "You are a creative frontend developer specializing in UI/UX design"
729
+ # OpenAI instances default to vibe: true
730
+
731
+ reasoning_expert:
732
+ description: "OpenAI O-series model for complex problem solving"
733
+ provider: openai
734
+ model: o1-mini
735
+ reasoning_effort: high # For O-series models only
736
+ directory: ./architecture
737
+ prompt: "You solve complex architectural and algorithmic problems"
738
+
739
+ backend_dev:
740
+ description: "Claude backend developer for system architecture"
741
+ directory: ./backend
742
+ model: sonnet
743
+ prompt: "You specialize in backend development and system architecture"
744
+ allowed_tools: [Read, Edit, Write, Bash]
745
+ ```
746
+
747
+ Note: OpenAI instances require the API key to be set in the environment variable (default: `OPENAI_API_KEY`).
748
+
749
+ #### Before and After Commands
750
+
751
+ You can specify commands to run before launching and after exiting the swarm using the `before` and `after` fields:
752
+
753
+ ```yaml
754
+ version: 1
755
+ swarm:
756
+ name: "Development Environment"
757
+ main: lead_developer
758
+ before:
759
+ - "echo '🚀 Setting up development environment...'"
760
+ - "npm install"
761
+ - "docker-compose up -d"
762
+ - "bundle install"
763
+ after:
764
+ - "echo '🛑 Cleaning up development environment...'"
765
+ - "docker-compose down"
766
+ - "rm -rf temp/*"
767
+ instances:
768
+ lead_developer:
769
+ description: "Lead developer coordinating the team"
770
+ directory: .
771
+ model: opus
772
+ allowed_tools: [Read, Edit, Write, Bash]
773
+ ```
774
+
775
+ The `before` commands:
776
+
777
+ - Are executed in sequence before launching any Claude instances
778
+ - Execute in the main instance's directory (including worktree if enabled)
779
+ - Must all succeed for the swarm to launch (exit code 0)
780
+ - Are only executed on initial swarm launch, not when restoring sessions
781
+ - Have their output logged to the session log file
782
+ - Will abort the swarm launch if any command fails
783
+
784
+ The `after` commands:
785
+
786
+ - Are executed after Claude exits but before cleanup processes
787
+ - Execute in the main instance's directory (including worktree if enabled)
788
+ - Run even when the swarm is interrupted by signals (Ctrl+C)
789
+ - Failures do not prevent cleanup from proceeding
790
+ - Are only executed on initial swarm runs, not when restoring sessions
791
+ - Have their output logged to the session log file
792
+
793
+ This is useful for:
794
+
795
+ - Installing dependencies in the isolated worktree environment
796
+ - Starting required services (databases, Docker containers, etc.)
797
+ - Setting up the development environment
798
+ - Running any prerequisite setup scripts
799
+ - Ensuring setup commands affect only the working directory, not the original repository
800
+
801
+ #### Mixed Permission Modes
802
+
803
+ You can have different permission modes for different instances:
804
+
805
+ ```yaml
806
+ version: 1
807
+ swarm:
808
+ name: "Mixed Mode Team"
809
+ main: lead
810
+ instances:
811
+ lead:
812
+ description: "Lead with full permissions"
813
+ directory: .
814
+ model: opus
815
+ vibe: true # This instance runs with --dangerously-skip-permissions
816
+ connections: [restricted_worker, trusted_worker]
817
+
818
+ restricted_worker:
819
+ description: "Worker with restricted permissions"
820
+ directory: ./sensitive
821
+ model: sonnet
822
+ allowed_tools: [Read, Bash] # Allow read and bash commands
823
+
824
+ trusted_worker:
825
+ description: "Trusted worker with more permissions"
826
+ directory: ./workspace
827
+ model: sonnet
828
+ vibe: true # This instance also skips permissions
829
+ allowed_tools: [] # Tools list ignored when vibe: true
830
+ ```
831
+
832
+ #### Git Worktrees
833
+
834
+ Claude Swarm supports running instances in Git worktrees, allowing isolated work without affecting your main repository state. Worktrees are created in an external directory (`~/.claude-swarm/worktrees/`) to ensure proper isolation from the main repository and avoid conflicts with bundler and other tools.
835
+
836
+ **Example Structure:**
837
+
838
+ ```
839
+ ~/.claude-swarm/worktrees/
840
+ └── [session_id]/
841
+ ├── my-repo-[hash]/
842
+ │ └── feature-x/ (worktree for feature-x branch)
843
+ └── other-repo-[hash]/
844
+ └── feature-x/ (worktree for feature-x branch)
845
+ ```
846
+
847
+ **CLI Option:**
848
+
849
+ ```bash
850
+ # Create worktrees with auto-generated name (worktree-SESSION_ID)
851
+ claude-swarm --worktree
852
+
853
+ # Create worktrees with custom name
854
+ claude-swarm --worktree feature-branch
855
+
856
+ # Short form
857
+ claude-swarm -w
858
+ ```
859
+
860
+ **Per-Instance Configuration:**
861
+
862
+ ```yaml
863
+ version: 1
864
+ swarm:
865
+ name: "Worktree Example"
866
+ main: lead
867
+ instances:
868
+ lead:
869
+ description: "Lead developer"
870
+ directory: .
871
+ worktree: true # Use shared worktree name from CLI (or auto-generate)
872
+
873
+ testing:
874
+ description: "Test developer"
875
+ directory: ./tests
876
+ worktree: false # Don't use worktree for this instance
877
+
878
+ feature_dev:
879
+ description: "Feature developer"
880
+ directory: ./features
881
+ worktree: "feature-x" # Use specific worktree name
882
+ ```
883
+
884
+ **Worktree Behavior:**
885
+
886
+ - `worktree: true` - Uses the shared worktree name (from CLI or auto-generated)
887
+ - `worktree: false` - Disables worktree for this instance
888
+ - `worktree: "name"` - Uses a specific worktree name
889
+ - Omitted - Follows CLI behavior (use worktree if `--worktree` is specified)
890
+
891
+ **Notes:**
892
+
893
+ - Auto-generated worktree names use the session ID (e.g., `worktree-20241206_143022`)
894
+ - This makes it easy to correlate worktrees with their Claude Swarm sessions
895
+ - Worktrees are stored externally in `~/.claude-swarm/worktrees/[session_id]/`
896
+ - All worktrees are automatically cleaned up when the swarm exits
897
+ - Worktrees with the same name across different repositories share that name
898
+ - Non-Git directories are unaffected by worktree settings
899
+ - Existing worktrees with the same name are reused
900
+ - The `claude-swarm clean` command also removes orphaned worktrees
901
+
902
+ ### Command Line Options
903
+
904
+ ```bash
905
+ # Use default claude-swarm.yml in current directory
906
+ claude-swarm
907
+
908
+ # Specify a different configuration file
909
+ claude-swarm start my-swarm.yml
910
+ claude-swarm start team-config.yml
911
+
912
+ # Run with --dangerously-skip-permissions for all instances
913
+ claude-swarm --vibe
914
+
915
+ # Run in non-interactive mode with a prompt
916
+ claude-swarm -p "Implement the new user authentication feature"
917
+ claude-swarm --prompt "Fix the bug in the payment module"
918
+
919
+ # Run in interactive mode with an initial prompt
920
+ claude-swarm -i "Review the codebase and suggest improvements"
921
+ claude-swarm --interactive "Help me debug this test failure"
922
+
923
+ # Use a custom session ID instead of auto-generated UUID
924
+ claude-swarm --session-id my-custom-session-123
925
+
926
+ # Stream logs to stdout in prompt mode
927
+ claude-swarm -p "Fix the tests" --stream-logs
928
+
929
+ # Run all instances in Git worktrees
930
+ claude-swarm --worktree # Auto-generated name (worktree-SESSION_ID)
931
+ claude-swarm --worktree feature-branch # Custom worktree name
932
+ claude-swarm -w # Short form
933
+
934
+ # Initialize a new configuration file
935
+ claude-swarm init
936
+ claude-swarm init --force # Overwrite existing file
937
+
938
+ # Generate configuration interactively with Claude's help
939
+ claude-swarm generate # Claude names file based on swarm function
940
+ claude-swarm generate -o my-swarm.yml # Custom output file
941
+ claude-swarm generate --model opus # Use a specific model
942
+
943
+ # Show version
944
+ claude-swarm version
945
+
946
+ # Note: The permission MCP server has been deprecated.
947
+ # Tool permissions are now handled through allowed_tools and disallowed_tools in your configuration.
948
+
949
+ # Internal command for MCP server (used by connected instances)
950
+ claude-swarm mcp-serve INSTANCE_NAME --config CONFIG_FILE --session-timestamp TIMESTAMP
951
+ ```
952
+
953
+ ### Session Monitoring
954
+
955
+ Claude Swarm provides commands to monitor and inspect running sessions:
956
+
957
+ ```bash
958
+ # List running swarm sessions with costs and uptime
959
+ claude-swarm ps
960
+
961
+ # Show detailed information about a session including instance hierarchy
962
+ claude-swarm show 20250617_235233
963
+
964
+ # Watch live logs from a session
965
+ claude-swarm watch 20250617_235233
966
+
967
+ # Watch logs starting from the last 50 lines
968
+ claude-swarm watch 20250617_235233 -n 50
969
+
970
+ # List all available sessions (including completed ones)
971
+ claude-swarm list-sessions
972
+ claude-swarm list-sessions --limit 20
973
+
974
+ # Clean up stale session symlinks and orphaned worktrees
975
+ claude-swarm clean
976
+
977
+ # Remove sessions and worktrees older than 30 days
978
+ claude-swarm clean --days 30
979
+ ```
980
+
981
+ Example output from `claude-swarm ps`:
982
+
983
+ ```
984
+ ⚠️ Total cost does not include the cost of the main instance
985
+
986
+ SESSION_ID SWARM_NAME TOTAL_COST UPTIME DIRECTORY
987
+ -------------------------------------------------------------------------------
988
+ 20250617_235233 Feature Development $0.3847 15m .
989
+ 20250617_143022 Bug Investigation $1.2156 1h .
990
+ 20250617_091547 Multi-Module Dev $0.8932 30m ./frontend, ./backend, ./shared
991
+ ```
992
+
993
+ Note: The total cost shown reflects only the costs of connected instances called via MCP. The main instance cost is not tracked when running interactively.
994
+
995
+ Example output from `claude-swarm show`:
996
+
997
+ ```
998
+ Session: 20250617_235233
999
+ Swarm: Feature Development
1000
+ Total Cost: $0.3847 (excluding main instance)
1001
+ Start Directory: /Users/paulo/project
1002
+
1003
+ Instance Hierarchy:
1004
+ --------------------------------------------------
1005
+ ├─ orchestrator [main] (orchestrator_e85036fc)
1006
+ Cost: n/a (interactive) | Calls: 0
1007
+ └─ test_archaeologist (test_archaeologist_c504ca5f)
1008
+ Cost: $0.1925 | Calls: 1
1009
+ └─ pr_analyst (pr_analyst_bfbefe56)
1010
+ Cost: $0.1922 | Calls: 1
1011
+
1012
+ Note: Main instance (orchestrator) cost is not tracked in interactive mode.
1013
+ View costs directly in the Claude interface.
1014
+ ```
1015
+
1016
+ ### Session Management and Restoration (Experimental)
1017
+
1018
+ Claude Swarm provides experimental session management with restoration capabilities. **Note: This feature is experimental and has limitations - the main instance's conversation context is not fully restored.**
1019
+
1020
+ #### Session Structure
1021
+
1022
+ All session files are organized in `~/.claude-swarm/sessions/{project}/{timestamp}/`:
1023
+
1024
+ - `config.yml`: Copy of the original swarm configuration
1025
+ - `state/`: Directory containing individual instance states
1026
+ - `{instance_id}.json`: Claude session ID and status for each instance (e.g., `lead_abc123.json`)
1027
+ - `{instance_name}.mcp.json`: MCP configuration files
1028
+ - `session.log`: Human-readable request/response tracking
1029
+ - `session.log.json`: All events in JSONL format (one JSON per line)
1030
+
1031
+ # Note: permissions.log is no longer generated as the permission MCP server has been deprecated
1032
+
1033
+ #### Listing Sessions
1034
+
1035
+ View your previous Claude Swarm sessions:
1036
+
1037
+ ```bash
1038
+ # List recent sessions (default: 10)
1039
+ claude-swarm list-sessions
1040
+
1041
+ # List more sessions
1042
+ claude-swarm list-sessions --limit 20
1043
+ ```
1044
+
1045
+ Output shows:
1046
+
1047
+ - Session ID (timestamp)
1048
+ - Creation time
1049
+ - Main instance name
1050
+ - Number of instances
1051
+ - Configuration file used
1052
+ - Full session path
1053
+
1054
+ #### Resuming Sessions
1055
+
1056
+ Resume a previous session with all instances restored to their Claude session states:
1057
+
1058
+ ```bash
1059
+ # Restore using the session's UUID
1060
+ claude-swarm restore 550e8400-e29b-41d4-a716-446655440000
1061
+ ```
1062
+
1063
+ This will:
1064
+
1065
+ 1. Load the session manifest and instance states
1066
+ 2. Restore the original swarm configuration
1067
+ 3. Resume the main instance with its Claude session ID
1068
+ 4. Restore all connected instances with their session IDs
1069
+ 5. Maintain the same working directories and tool permissions
1070
+
1071
+ #### How Session Restoration Works
1072
+
1073
+ - Each instance's Claude session ID is automatically captured and persisted
1074
+ - Instance states are stored in separate files named by instance ID to prevent concurrency issues
1075
+ - MCP configurations are regenerated with the saved session IDs
1076
+ - The main instance uses Claude's `--resume` flag (limited effectiveness)
1077
+ - Connected instances receive their session IDs via `--claude-session-id`
1078
+
1079
+ **Important Limitations:**
1080
+
1081
+ - The main instance's conversation history and context are not fully restored
1082
+ - Only the session ID is preserved, not the actual conversation state
1083
+ - Connected instances restore more reliably than the main instance
1084
+ - This is an experimental feature and may not work as expected
1085
+
1086
+ ## How It Works
1087
+
1088
+ 1. **Configuration Parsing**: Claude Swarm reads your YAML configuration and validates it
1089
+ 2. **MCP Generation**: For each instance, it generates an MCP configuration file that includes:
1090
+ - Any explicitly defined MCP servers
1091
+ - MCP servers for each connected instance (using `claude-swarm mcp-serve`)
1092
+ 3. **Tool Permissions**: Claude Swarm manages tool permissions through configuration:
1093
+ - Each instance's `allowed_tools` specifies which tools it can use
1094
+ - Connected instances are accessible via `mcp__<instance_name>__*` pattern
1095
+ - Disallowed tools take precedence over allowed tools for fine-grained control
1096
+ - Per-instance `vibe: true` skips all permission checks for that specific instance
1097
+ 4. **Session Persistence**: Claude Swarm automatically tracks session state:
1098
+ - Generates a shared session path for all instances
1099
+ - Each instance's Claude session ID is captured and saved
1100
+ - Instance states are stored using instance IDs as filenames to avoid conflicts
1101
+ - Sessions can be fully restored with all instances reconnected
1102
+ 5. **Main Instance Launch**: The main instance is launched with its MCP configuration, giving it access to all connected instances
1103
+ 6. **Inter-Instance Communication**: Connected instances expose themselves as MCP servers with these tools:
1104
+ - **task**: Execute tasks using Claude Code with configurable tools and return results. The tool description includes the instance name and description (e.g., "Execute a task using Agent frontend_dev. Frontend developer specializing in React and TypeScript")
1105
+ - **session_info**: Get current Claude session information including ID and working directory
1106
+ - **reset_session**: Reset the Claude session for a fresh start
1107
+
1108
+ ## Troubleshooting
1109
+
1110
+ ### Common Issues
1111
+
1112
+ **"Configuration file not found"**
1113
+
1114
+ - Ensure `claude-swarm.yml` exists in the current directory
1115
+ - Or specify the path with `--config`
1116
+
1117
+ **"Main instance not found in instances"**
1118
+
1119
+ - Check that your `main:` field references a valid instance key
1120
+
1121
+ **"Unknown instance in connections"**
1122
+
1123
+ - Verify all instances in `connections:` arrays are defined
1124
+
1125
+ **Permission Errors**
1126
+
1127
+ - Ensure Claude CLI is properly installed and accessible
1128
+ - Check directory permissions for specified paths
1129
+
1130
+ ### Debug Output
1131
+
1132
+ The swarm will display:
1133
+
1134
+ - Session directory location (`~/.claude-swarm/sessions/{project}/{timestamp}/`)
1135
+ - Main instance details (model, directory, tools, connections)
1136
+ - The exact command being run
1137
+
1138
+ ### Session Files
1139
+
1140
+ Check the session directory `~/.claude-swarm/sessions/{project}/{session-id}/` for:
1141
+
1142
+ - `session.log`: Human-readable logs with request/response tracking
1143
+ - `session.log.json`: All events in JSONL format (one JSON object per line)
1144
+ - `{instance}.mcp.json`: MCP configuration for each instance
1145
+ - All files for a session are kept together for easy review
1146
+
1147
+ ## Architecture
1148
+
1149
+ Claude Swarm consists of these core components:
1150
+
1151
+ - **ClaudeSwarm::CLI** (`cli.rb`): Thor-based command-line interface with `start` and `mcp-serve` commands
1152
+ - **ClaudeSwarm::Configuration** (`configuration.rb`): YAML parser and validator with path expansion
1153
+ - **ClaudeSwarm::McpGenerator** (`mcp_generator.rb`): Generates MCP JSON configs for each instance
1154
+ - **ClaudeSwarm::Orchestrator** (`orchestrator.rb`): Launches the main Claude instance with shared session management
1155
+ - **ClaudeSwarm::ClaudeCodeExecutor** (`claude_code_executor.rb`): Executor for Claude Code with session persistence
1156
+ - **ClaudeSwarm::ClaudeMcpServer** (`claude_mcp_server.rb`): FastMCP-based server providing task execution, session info, and reset capabilities
1157
+
1158
+ ## Development
1159
+
1160
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
1161
+
1162
+ To install this gem onto your local machine, run `bundle exec rake install`.
1163
+
1164
+ ### Development Commands
1165
+
1166
+ ```bash
1167
+ bin/setup # Install dependencies
1168
+ rake test # Run the Minitest test suite
1169
+ rake rubocop -A # Run RuboCop linter with auto-fix
1170
+ bin/console # Start IRB session with gem loaded
1171
+ bundle exec rake install # Install gem locally
1172
+ bundle exec rake release # Release gem to RubyGems.org
1173
+ rake # Default: runs both tests and RuboCop
1174
+ ```
1175
+
1176
+ ### Release Process
1177
+
1178
+ The gem is automatically published to RubyGems when a new release is created on GitHub:
1179
+
1180
+ 1. Update the version number in `lib/claude_swarm/version.rb`
1181
+ 2. Update `CHANGELOG.md` with the new version's changes
1182
+ 3. Commit the changes: `git commit -am "Bump version to x.y.z"`
1183
+ 4. Create a version tag: `git tag -a vx.y.z -m "Release version x.y.z"`
1184
+ 5. Push the changes and tag: `git push && git push --tags`
1185
+ 6. The GitHub workflow will create a draft release - review and publish it
1186
+ 7. Once published, the gem will be automatically built and pushed to RubyGems
1187
+
1188
+ **Note**: You need to set up the `RUBYGEMS_AUTH_TOKEN` secret in your GitHub repository settings with your RubyGems API key.
1189
+
1190
+ ## Contributing
1191
+
1192
+ Bug reports and pull requests are welcome on GitHub at https://github.com/parruda/claude-swarm.
1193
+
1194
+ ## License
1195
+
1196
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
1197
+