claude-supervisor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,970 @@
1
+ # Claude Supervisor
2
+
3
+ Spin up parallel [Claude Code](https://docs.anthropic.com/en/docs/claude-code) agents in isolated git worktrees — each with its own task, model, and mode — from a single config file.
4
+
5
+ ```bash
6
+ bash /path/to/claude-supervisor/bin/supervisor.sh /path/to/your-project
7
+ ```
8
+
9
+ On first run it scaffolds a config file. On every run after that it reads the config and spawns one agent per `[task]` block: branch created, worktree created, Claude launched in a tmux window. At the end it prints ready-to-copy commands so you can also open each agent in its own terminal tab.
10
+
11
+ ---
12
+
13
+ ## Prerequisites
14
+
15
+ | Tool | Install |
16
+ |---|---|
17
+ | **git** | `xcode-select --install` (macOS) · or `brew install git` for a newer version |
18
+ | **tmux** | `brew install tmux` |
19
+ | **Node.js / npm** | [nvm](https://github.com/nvm-sh/nvm): `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh \| bash` then `nvm install --lts` |
20
+ | **Claude Code CLI** | `npm install -g @anthropic-ai/claude-code` |
21
+
22
+ > The supervisor checks for all of these on every run. If anything is missing it will list what's needed and offer to auto-install.
23
+
24
+ To check for and apply updates via Homebrew:
25
+
26
+ ```bash
27
+ brew outdated git # check if git has an update
28
+ brew update && brew upgrade git # update git
29
+ brew upgrade # update all outdated formulae at once
30
+ ```
31
+
32
+ **Billing:** The supervisor supports two billing modes:
33
+
34
+ | Mode | Who | API key needed? |
35
+ |---|---|---|
36
+ | **Pro / Max / Team** | Claude subscription users | No — authenticate via Claude's OAuth login |
37
+ | **API key** | Anthropic Console users | Yes — `ANTHROPIC_API_KEY` required |
38
+
39
+ The supervisor remembers your billing mode choice and saves it to your project's `.env` file. On subsequent runs, it uses the saved preference without re-prompting. If it finds `ANTHROPIC_API_KEY` in the environment or in your project's `.env`, it auto-selects API mode.
40
+
41
+ To change your billing mode later, use the `--reset` flag:
42
+
43
+ ```bash
44
+ bash bin/supervisor.sh --reset /path/to/your-project
45
+ ```
46
+
47
+ API-key users can export the key beforehand (`export ANTHROPIC_API_KEY=sk-ant-...`) or enter it at the prompt — it's saved to `.env` so you only enter it once.
48
+
49
+ ---
50
+
51
+ ## Install via npm
52
+
53
+ The supervisor is published to npm. If you already have Node.js/npm installed (required for Claude Code CLI), this is the fastest way to get started.
54
+
55
+ ### Option A — Global install (personal use, run from any directory)
56
+
57
+ ```bash
58
+ npm install -g claude-supervisor
59
+ supervisor.sh ~/my-project
60
+ ```
61
+
62
+ ### Option B — Local devDependency (teams, CI, version-locked)
63
+
64
+ ```json
65
+ // your-project/package.json
66
+ {
67
+ "scripts": {
68
+ "agents": "supervisor.sh",
69
+ "agents:reset": "supervisor.sh --reset",
70
+ "agents:collect": "collect-learnings.sh --yes"
71
+ },
72
+ "devDependencies": {
73
+ "claude-supervisor": "^0.1.0"
74
+ }
75
+ }
76
+ ```
77
+
78
+ ```bash
79
+ npm install # pulls in claude-supervisor
80
+ npm run agents # first run → scaffolds tasks.conf + .claude/ → exits
81
+ # edit tasks.conf
82
+ npm run agents # spawns agents
83
+ ```
84
+
85
+ npm symlinks the bin entries into `node_modules/.bin/` and adds that directory to PATH during `npm run`. The shell scripts resolve their own location via `BASH_SOURCE[0]` which follows symlinks correctly, so `../lib/utils.sh` and `../templates/` resolve to the right place inside `node_modules/claude-supervisor/`.
86
+
87
+ ### Option C — Clone and run directly (no install required)
88
+
89
+ ```bash
90
+ git clone <this-repo-url> claude-supervisor
91
+ bash claude-supervisor/bin/supervisor.sh ~/my-project
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Quick Start
97
+
98
+ ### 1. Clone this repo
99
+
100
+ ```bash
101
+ git clone <this-repo-url> claude-supervisor
102
+ cd claude-supervisor
103
+ ```
104
+
105
+ ### 2. First run — scaffold config into your project
106
+
107
+ ```bash
108
+ bash bin/supervisor.sh /path/to/your-project
109
+ ```
110
+
111
+ This creates:
112
+
113
+ ```
114
+ your-project/
115
+ tasks.conf # Define your tasks here (gitignored — personal)
116
+ .gitignore # Updated to exclude tasks.conf
117
+ .claude/
118
+ CLAUDE.md # Project memory — shared by all agents
119
+ settings.json # PermissionRequest → Opus hook
120
+ agents/
121
+ reviewer.md # Code review subagent
122
+ debugger.md # Debugging and root cause analysis subagent
123
+ test-writer.md # Test writing subagent
124
+ _example-agent.md # Blank template — copy to create your own
125
+ commands/
126
+ techdebt.md # /techdebt — find and fix technical debt
127
+ explain.md # /explain — explain code with the why
128
+ diagram.md # /diagram — draw ASCII architecture diagrams
129
+ learn.md # /learn — Socratic learning session
130
+ ```
131
+
132
+ `tasks.conf` is automatically added to `.gitignore`.
133
+
134
+ The supervisor then displays common model IDs so you know what to put in `tasks.conf`. If an API key is available (environment variable or `.env` file), it also fetches the full list from the Anthropic API.
135
+
136
+ What to commit and what to ignore:
137
+
138
+ | File | Git | Why |
139
+ |---|---|---|
140
+ | `.claude/CLAUDE.md` | **Commit** | Shared project memory — conventions, pitfalls, context for all agents |
141
+ | `.claude/settings.json` | **Commit** | PermissionRequest hook config — same safety gating for everyone |
142
+ | `.claude/agents/` | **Commit** | Subagents are project tools — reviewer, debugger, test-writer |
143
+ | `.claude/commands/` | **Commit** | Slash commands belong to the project — `/techdebt`, `/explain`, etc. |
144
+ | `tasks.conf` | **Ignore** | Personal and ephemeral — your current batch of work. Two people running different tasks would conflict. |
145
+ | `.env` | **Ignore** | Contains your API key (API-key billing only) — automatically gitignored when created. |
146
+
147
+ The supervisor then exits with instructions.
148
+
149
+ > **Tip:** If you skip the model list during first run, that's fine — you can omit the `model` field in tasks.conf and the supervisor will show an interactive menu on the next run.
150
+
151
+ ### 3. Edit tasks.conf
152
+
153
+ Open `your-project/tasks.conf` and define your tasks. Each `[task]` block defines one agent:
154
+
155
+ ```ini
156
+ [task]
157
+ prompt = description of the task
158
+ branch = optional-branch-name
159
+ model = optional-model-id
160
+ mode = normal | plan
161
+ ```
162
+
163
+ Only `prompt` is required. Omit any other field to use its default:
164
+
165
+ | Field | Omitted means |
166
+ |---|---|
167
+ | `branch` | Auto-generated from prompt text (e.g. `fix login bug` → `fix-login-bug`) |
168
+ | `model` | You'll be prompted with a live model menu for that task |
169
+ | `mode` | Defaults to `normal` |
170
+
171
+ **Examples:**
172
+
173
+ ```ini
174
+ # Fully specified
175
+ [task]
176
+ branch = feature-auth
177
+ model = claude-sonnet-4-5-20250929
178
+ mode = normal
179
+ prompt = implement the OAuth2 login flow
180
+
181
+ # Only a prompt — branch auto-generated, model prompted, mode defaults to normal
182
+ [task]
183
+ prompt = refactor the database layer to use connection pooling
184
+
185
+ # Plan mode — only prompt and mode needed
186
+ [task]
187
+ mode = plan
188
+ prompt = review the codebase and write an implementation plan
189
+
190
+ # Explicit branch and model, mode defaults to normal
191
+ [task]
192
+ branch = fix-login-bug
193
+ model = claude-haiku-4-5-20251001
194
+ prompt = fix the login session timeout bug
195
+ ```
196
+
197
+ Blank lines and `#` comments are ignored. A `[task]` header starts a new block.
198
+
199
+ ### 4. Run again — agents spawn
200
+
201
+ ```bash
202
+ bash bin/supervisor.sh /path/to/your-project
203
+ ```
204
+
205
+ The supervisor will:
206
+ 1. Check dependencies
207
+ 2. Use saved billing mode preference, or prompt if first run (Pro subscription or API key)
208
+ 3. Resolve API key (API-key users only — prompts if not found, saves to `.env`)
209
+ 4. Fetch available models (live from API for API-key users, static list for Pro users)
210
+ 5. For each task block, prompt you to pick a model (if not specified in config)
211
+ 6. Create a git branch + worktree per task
212
+ 7. Open a tmux window per agent, launch Claude Code
213
+ 8. Auto-paste the task prompt into Claude after it loads
214
+ 9. Print instructions for accessing each agent
215
+
216
+ ### 5. Access your agents
217
+
218
+ After spawning, the supervisor prints two options:
219
+
220
+ **Option A — tmux (all agents in one place):**
221
+
222
+ ```bash
223
+ tmux attach -t your-project-agents
224
+ ```
225
+
226
+ | Key | Action |
227
+ |---|---|
228
+ | `Ctrl+b n` | Next agent |
229
+ | `Ctrl+b p` | Previous agent |
230
+ | `Ctrl+b w` | List all agents — pick one |
231
+ | `Ctrl+b 0` / `1` / `2` | Jump to agent by number |
232
+ | `Ctrl+b d` | Detach (agents keep running in background) |
233
+
234
+ > **Note:** Press `Ctrl+b`, release **both** keys, then press the second key. It's two separate keystrokes, not a three-key combo.
235
+
236
+ **Option B — separate terminal tabs (simpler navigation):**
237
+
238
+ The supervisor prints a ready-to-copy `cd ... && claude ...` command for each agent. Open a new tab in your terminal (`Cmd+T`), paste the command, and you're in. Use normal tab switching (`Cmd+1`, `Cmd+2`, etc.).
239
+
240
+ Example output:
241
+
242
+ ```
243
+ ═══════════════════════════════════════════════════════════════
244
+ ✓ Spawned 2 agent(s) in tmux session: your-project-agents
245
+ ═══════════════════════════════════════════════════════════════
246
+
247
+ Option A — Attach to tmux (all agents in one place):
248
+
249
+ tmux attach -t your-project-agents
250
+
251
+ Option B — Open each agent in its own terminal tab:
252
+
253
+ Tab 1 — implement the OAuth2 login flow
254
+ cd /path/to/your-project-feature-auth && claude --model claude-sonnet-4-5-20250929
255
+
256
+ Tab 2 — fix the login session timeout bug
257
+ cd /path/to/your-project-fix-login-bug && claude --model claude-haiku-4-5-20251001
258
+
259
+ Then paste the task prompt into Claude when it loads.
260
+
261
+ ═══════════════════════════════════════════════════════════════
262
+ ```
263
+
264
+ > **IMPORTANT — First time using Claude Code CLI?** You'll see Claude's setup wizard asking "Select login method". **Press `1`** if you have a Claude Pro/Max/Team subscription, or **press `2`** if you're using an Anthropic API key. This setup is one-time per machine.
265
+
266
+ **Detach and reattach tmux anytime:**
267
+
268
+ ```bash
269
+ # Detach (go back to your shell, agents keep running)
270
+ Ctrl+b d
271
+
272
+ # Reattach later
273
+ tmux attach -t your-project-agents
274
+
275
+ # List all sessions
276
+ tmux ls
277
+ ```
278
+
279
+ > **Tip:** The commands above work because you `cd`'d into the claude-supervisor directory. For daily use from anywhere, either use the full path — `bash /path/to/claude-supervisor/bin/supervisor.sh /path/to/project` — or set up shell shortcuts (next section).
280
+
281
+ **Usage:**
282
+
283
+ ```bash
284
+ supervisor.sh [--reset] [repo_path]
285
+ ```
286
+
287
+ - `--reset`: Re-prompt for billing mode (clears saved preference)
288
+ - `repo_path`: Project directory (defaults to current directory)
289
+
290
+ ---
291
+
292
+ ## Shell Shortcuts (Optional)
293
+
294
+ If you use the supervisor frequently, you can set up shell shortcuts to avoid typing the full path every time.
295
+
296
+ ### Quick setup
297
+
298
+ Run from the claude-supervisor directory:
299
+
300
+ ```bash
301
+ bash bin/setup-shortcuts.sh
302
+ ```
303
+
304
+ It will:
305
+ - Auto-detect the installation path
306
+ - Back up your `~/.zshrc` to `~/.zshrc.backup-YYYYMMDD-HHMMSS`
307
+ - Let you choose between adding to **PATH** or creating **aliases** (both modify `~/.zshrc`)
308
+ - Check if already installed (won't duplicate)
309
+ - Reload your shell configuration automatically (if running in zsh)
310
+
311
+ ### PATH setup (recommended)
312
+
313
+ Adds `claude-supervisor/bin` to your PATH. Then run:
314
+
315
+ ```bash
316
+ supervisor.sh # run in current directory
317
+ supervisor.sh ~/my-project
318
+ collect-learnings.sh --yes
319
+ spawn-agent.sh ~/my-project fix-bug claude-sonnet-4-5-20250929 normal 0 "fix the login bug"
320
+ ```
321
+
322
+ ### Alias setup
323
+
324
+ Creates short aliases. Then run:
325
+
326
+ ```bash
327
+ supervisor # run in current directory
328
+ supervisor ~/my-project
329
+ collect-learnings --yes
330
+ spawn-agent ~/my-project fix-bug claude-sonnet-4-5-20250929 normal 0 "fix the login bug"
331
+ ```
332
+
333
+ ### Manual setup
334
+
335
+ If you prefer to edit `~/.zshrc` yourself:
336
+
337
+ **PATH:**
338
+ ```bash
339
+ export PATH="/path/to/claude-supervisor/bin:$PATH"
340
+ ```
341
+
342
+ **Aliases:**
343
+ ```bash
344
+ alias supervisor='bash /path/to/claude-supervisor/bin/supervisor.sh'
345
+ alias collect-learnings='bash /path/to/claude-supervisor/bin/collect-learnings.sh'
346
+ alias spawn-agent='bash /path/to/claude-supervisor/bin/spawn-agent.sh'
347
+ ```
348
+
349
+ Then reload: `source ~/.zshrc`
350
+
351
+ ---
352
+
353
+ ## Example Walkthrough
354
+
355
+ Assuming you have a project and want to work on two things in parallel, here's exactly what to do.
356
+
357
+ > Commands below use full paths so they work from any directory. If you set up shell shortcuts, replace `bash /path/to/claude-supervisor/bin/supervisor.sh` with `supervisor`.
358
+
359
+ **Your tasks:**
360
+ 1. Add an "Ungroup All" feature — removes all tab groups at once
361
+ 2. Rename tab titles using AI — infer a meaningful name from tab content
362
+
363
+ **Step 1:** Run the supervisor on your project for the first time to scaffold the config:
364
+
365
+ ```bash
366
+ bash /path/to/claude-supervisor/bin/supervisor.sh /path/to/your-project
367
+ ```
368
+
369
+ **Step 2:** Open `your-project/tasks.conf`, delete the example blocks, and add your two tasks:
370
+
371
+ ```ini
372
+ [task]
373
+ prompt = Add "Ungroup All" functionality — a button/command that removes all tab groups at once
374
+
375
+ [task]
376
+ prompt = Rename tab titles using AI — infer a meaningful name from tab content and update the title
377
+ ```
378
+
379
+ Branch names will be auto-generated from the prompts, and you'll pick a model interactively for each.
380
+
381
+ **Step 3:** Run the supervisor again:
382
+
383
+ ```bash
384
+ bash /path/to/claude-supervisor/bin/supervisor.sh /path/to/your-project
385
+ ```
386
+
387
+ You'll be prompted to pick a model for each task. Pick Haiku for straightforward tasks, Sonnet or Opus for complex ones. Two worktrees and two tmux windows open automatically.
388
+
389
+ **Step 4:** Access your agents. The supervisor prints two options:
390
+
391
+ **Option A — tmux:** Attach to the tmux session and navigate between agents:
392
+
393
+ ```bash
394
+ tmux attach -t your-project-agents
395
+ ```
396
+
397
+ **Option B — separate tabs:** Copy the `cd ... && claude ...` command for each agent into a new terminal tab (`Cmd+T`).
398
+
399
+ You'll see each agent in its own color-coded tmux window with a banner showing the task.
400
+
401
+ > **First time using Claude Code CLI?** You'll see a setup wizard asking "Select login method:". **Press `1` and Enter** if you have a Claude Pro/Max/Team subscription, or **Press `2` and Enter** if you're using an Anthropic API key (Console billing). This is one-time setup per machine. After setup, Claude will show its prompt.
402
+
403
+ When Claude loads:
404
+ - **Copy the task** from the banner at the top and paste it to Claude to begin
405
+ - Switch between agents with `Ctrl+b` then `n`/`p` (tmux) or `Cmd+1`/`Cmd+2` (tabs)
406
+ - Type **`/model`** to switch models mid-session (e.g. start with Opus for planning, switch to Haiku for implementation)
407
+
408
+ Each agent works independently on its worktree.
409
+
410
+ **Step 5:** After agents finish, collect learnings, open PRs, and clean up:
411
+
412
+ ```bash
413
+ # Collect any CLAUDE.md updates agents made, before removing worktrees
414
+ bash /path/to/claude-supervisor/bin/collect-learnings.sh your-project
415
+
416
+ # Review what each agent did
417
+ git -C your-project diff main..add-ungroup-all-functionality
418
+ git -C your-project diff main..rename-tab-titles-using-ai
419
+
420
+ # Open PRs (requires gh CLI)
421
+ gh pr create --head add-ungroup-all-functionality --base main \
422
+ --title "Add Ungroup All" --body "Implemented by Claude agent"
423
+ gh pr create --head rename-tab-titles-using-ai --base main \
424
+ --title "Rename tab titles with AI" --body "Implemented by Claude agent"
425
+
426
+ # Once PRs are approved and merged, clean up worktrees locally
427
+ git worktree remove ../your-project-add-ungroup-all-functionality
428
+ git worktree remove ../your-project-rename-tab-titles-using-ai
429
+
430
+ # Kill the tmux session (stops all agents)
431
+ tmux kill-session -t your-project-agents
432
+ ```
433
+
434
+ > **Tip:** If you need to stop agents early or start over, see the "Stopping agents and cleaning up worktrees" section below.
435
+
436
+ ---
437
+
438
+ ## Modes
439
+
440
+ The `mode` field in `tasks.conf` controls how the agent behaves:
441
+
442
+ | Mode | Flag | What it does |
443
+ |---|---|---|
444
+ | `normal` | _(default)_ | Agent reads and writes freely. Full access to tools. Use for implementation tasks. |
445
+ | `plan` | `--permission-mode plan` | Agent can read and analyze but won't modify any files until you explicitly approve each action. Use for planning, code review, and risk assessment. Plan-mode windows are always **yellow** in tmux. |
446
+
447
+ **When to use `plan`:**
448
+ - You want to understand the scope before anything is written
449
+ - You want a second agent to review a plan before workers execute it
450
+ - The task is large or risky and you want a read-only audit first
451
+
452
+ **When to use `normal`:**
453
+ - The task is well-defined and scoped
454
+ - You trust the agent to proceed without a planning step
455
+ - You're running a small fix or an isolated feature
456
+
457
+ **Typical pattern for complex work:**
458
+
459
+ ```ini
460
+ # tasks.conf
461
+
462
+ # Phase 1 — read-only planning
463
+ [task]
464
+ mode = plan
465
+ prompt = review the codebase and write a detailed implementation plan for OAuth2 login
466
+
467
+ [task]
468
+ mode = plan
469
+ prompt = review the above plan as a staff engineer and flag risks or missing steps
470
+
471
+ # Phase 2 — execution (add these after approving the plan)
472
+ [task]
473
+ branch = feature-auth
474
+ model = claude-sonnet-4-5-20250929
475
+ prompt = implement the OAuth2 login flow per the approved plan
476
+
477
+ [task]
478
+ branch = write-tests
479
+ model = claude-haiku-4-5-20251001
480
+ prompt = write tests for the new auth module
481
+ ```
482
+
483
+ ---
484
+
485
+ ## Workflow
486
+
487
+ ### Recommended pattern for complex features
488
+
489
+ **Phase 1 — Plan (read-only agents)**
490
+
491
+ ```ini
492
+ [task]
493
+ mode = plan
494
+ prompt = review the codebase and write a detailed implementation plan for the feature
495
+
496
+ [task]
497
+ mode = plan
498
+ prompt = review the above plan as a staff engineer and flag risks or missing steps
499
+ ```
500
+
501
+ Plan-mode agents use `--permission-mode plan` — they can read and analyze but won't modify files until you approve. Their tmux windows are always **yellow** so you can spot them at a glance.
502
+
503
+ **Phase 2 — Execute (worker agents)**
504
+
505
+ Once you've reviewed and approved the plan, update `tasks.conf` with workers:
506
+
507
+ ```ini
508
+ [task]
509
+ branch = feature-auth
510
+ model = claude-sonnet-4-5-20250929
511
+ prompt = implement the OAuth2 login flow per the approved plan
512
+
513
+ [task]
514
+ branch = write-tests
515
+ model = claude-haiku-4-5-20251001
516
+ prompt = write tests for the new auth module
517
+ ```
518
+
519
+ Run the supervisor again to spawn the workers.
520
+
521
+ **Phase 3 — Re-plan if needed**
522
+
523
+ If a worker goes sideways, spawn a new plan-mode agent to reassess before continuing.
524
+
525
+ ### Inside each agent session
526
+
527
+ Each agent tmux window shows a banner with the task details:
528
+
529
+ ```
530
+ ╔══════════════════════════════════════════════════════╗
531
+ ║ CLAUDE AGENT ║
532
+ ╠══════════════════════════════════════════════════════╣
533
+ ║ Task : fix the login session timeout bug
534
+ ║ Branch: fix-login-bug
535
+ ║ Model : claude-haiku-4-5-20251001
536
+ ║ Mode : normal
537
+ ╠══════════════════════════════════════════════════════╣
538
+ ║ Hints: ║
539
+ ║ • /model — switch model mid-session ║
540
+ ║ • /agents — view available subagents ║
541
+ ║ • /statusline — enable context + git branch bar ║
542
+ ║ • Update CLAUDE.md after corrections ║
543
+ ║ • Explain the WHY behind every change ║
544
+ ╚══════════════════════════════════════════════════════╝
545
+
546
+ ▸ Starting Claude...
547
+
548
+ 💡 Task will be shown above - you can copy/paste it to Claude when ready
549
+ ```
550
+
551
+ **First time using Claude Code CLI on this machine?**
552
+
553
+ Before the banner appears, you'll see Claude's setup wizard:
554
+
555
+ ```
556
+ Select login method:
557
+ › 1. Claude account with subscription · Pro, Max, Team, or Enterprise
558
+ 2. Anthropic Console account · API usage billing
559
+ 3. 3rd-party platform · Amazon Bedrock, Microsoft Foundry, or Vertex AI
560
+ ```
561
+
562
+ **Press `1` and Enter** if you have a Claude Pro, Max, Team, or Enterprise subscription. **Press `2` and Enter** if you're using an Anthropic API key (Console billing). This is one-time setup per machine. After completing setup, the banner will appear and Claude will be ready.
563
+
564
+ **Start the agent:** Copy the task text from the banner and paste it to Claude when ready. The agent will begin working on it immediately.
565
+
566
+ Useful commands inside an agent:
567
+ - **`/model`** — switch to a cheaper model once complex planning is done
568
+ - **`/agents`** — list available subagents (from `.claude/agents/`)
569
+ - **`/statusline`** — enable the context usage + git branch bar (one-time global config)
570
+
571
+ ### After agents finish
572
+
573
+ Each agent works on its own branch. Open a PR per branch, review it, merge it. Worktrees are created at `../your-project-<branch>/` alongside your project directory.
574
+
575
+ ```bash
576
+ # 1. Collect agent learnings back into the main CLAUDE.md (before removing worktrees!)
577
+ bash /path/to/claude-supervisor/bin/collect-learnings.sh /path/to/your-project
578
+
579
+ # 2. Commit the updated CLAUDE.md
580
+ git -C /path/to/your-project add .claude/CLAUDE.md
581
+ git -C /path/to/your-project commit -m "docs: merge agent learnings"
582
+
583
+ # 3. List all active worktrees and branches
584
+ git worktree list
585
+
586
+ # 4. Open a PR for a branch (requires gh CLI)
587
+ gh pr create --head feature-auth --base main
588
+ --title "Feature: OAuth2 login" --body "Implemented by Claude agent"
589
+
590
+ # 5. After the PR is merged, remove the worktree
591
+ git worktree remove ../your-project-feature-auth
592
+ ```
593
+
594
+ > **Important:** Run `collect-learnings.sh` _before_ `git worktree remove`. Once a worktree is gone, its CLAUDE.md updates are gone with it.
595
+
596
+ ### Stopping agents and cleaning up worktrees
597
+
598
+ **To stop all agents and kill the tmux session:**
599
+
600
+ ```bash
601
+ # Kill the entire tmux session (stops all agents immediately)
602
+ tmux kill-session -t your-project-agents
603
+ ```
604
+
605
+ **To list and remove worktrees:**
606
+
607
+ ```bash
608
+ # 1. List all active worktrees
609
+ git worktree list
610
+
611
+ # 2. Remove a specific worktree
612
+ git worktree remove ../your-project-feature-auth
613
+
614
+ # 3. Force remove (if there are uncommitted changes)
615
+ git worktree remove --force ../your-project-feature-auth
616
+
617
+ # 4. Remove all agent worktrees for a project
618
+ git worktree list | grep "your-project-" | awk '{print $1}' | xargs -I {} git worktree remove --force {}
619
+ ```
620
+
621
+ **Common scenarios:**
622
+
623
+ | Scenario | Commands |
624
+ |---|---|
625
+ | **Agents stuck/hung** | `tmux kill-session -t project-agents` |
626
+ | **Start fresh** | Kill session → remove worktrees → edit `tasks.conf` → run supervisor again |
627
+ | **Agent finished, want to keep work** | Don't remove worktree yet — open PR from that branch first |
628
+ | **Agent failed, want to retry** | Remove worktree → remove branch → run supervisor again (it will recreate) |
629
+ | **Force closed terminal** | Agents still running — use `tmux attach` to reconnect, or `tmux kill-session` to stop |
630
+ | **Killed session, want to resume** | Just run the supervisor again with the same `tasks.conf` — it detects existing worktrees and reuses them, no work is lost |
631
+
632
+ **To remove branches after removing worktrees:**
633
+
634
+ ```bash
635
+ # List all branches
636
+ git branch -a
637
+
638
+ # Delete a local branch (after merging)
639
+ git branch -d feature-auth
640
+
641
+ # Force delete a local branch (without merging)
642
+ git branch -D feature-auth
643
+ ```
644
+
645
+ ---
646
+
647
+ ## Model Selection
648
+
649
+ There are two separate model choices:
650
+
651
+ **1. Agent model** — you pick this per task. It does the actual work.
652
+
653
+ - **Pro users:** the supervisor shows a static list of common models. You can also type `/model` inside any agent session to switch models on the fly.
654
+ - **API-key users:** models are fetched live from the Anthropic API.
655
+ - For any task with an empty `model` field, the supervisor presents an interactive menu. You can also hardcode a model ID in `tasks.conf`.
656
+
657
+ **2. PermissionRequest hook model** — hardcoded to `claude-opus-4-6` in `.claude/settings.json`. This only fires when an agent tries a risky action (e.g., deleting a file). Opus evaluates for a few seconds and returns allow/deny. It does not run continuously.
658
+
659
+ ```
660
+ User picks Haiku for agent → agent does 95% of the work cheaply
661
+
662
+ Agent tries to delete a file → PermissionRequest hook fires
663
+
664
+ Opus evaluates for ~2s: "is this safe given the task?" → allow / deny
665
+
666
+ Agent continues on Haiku
667
+ ```
668
+
669
+ Opus is the gatekeeper, not the worker. The bulk of compute stays on cheap models.
670
+
671
+ **When models are deprecated:**
672
+
673
+ Anthropic periodically retires old model IDs. If `.claude/settings.json` still references a deprecated model, the `PermissionRequest` hook fails silently — risky actions go through ungated, with no error visible to you.
674
+
675
+ The supervisor detects this automatically. On every normal run it checks whether the hook model is still in the live model list:
676
+
677
+ ```
678
+ ⚠ PermissionRequest hook uses 'claude-opus-4-6' — this model is no longer available.
679
+ → Update .claude/settings.json with a current model.
680
+ → Recommended replacements (from live model list):
681
+ claude-opus-5-0
682
+ ```
683
+
684
+ When you see this warning, open `.claude/settings.json` in your project and update the `"model"` field to the model shown. The supervisor fetches the list live so the suggestion is always current.
685
+
686
+ ---
687
+
688
+ ## Project Memory (CLAUDE.md)
689
+
690
+ `.claude/CLAUDE.md` is copied into every worktree. Every agent reads it automatically at session start. Fill in:
691
+
692
+ - **Project Overview** — what it does, stack, entry point
693
+ - **Conventions** — style, naming, tests, branching
694
+ - **Known Pitfalls** — grows over time as agents document corrections
695
+
696
+ When an agent makes a mistake and gets corrected, it should add a note to Known Pitfalls. The next agent spawned will inherit that knowledge automatically.
697
+
698
+ ### Syncing learnings back to the main repo
699
+
700
+ Each worktree gets its own **copy** of CLAUDE.md. Updates an agent makes are local to that worktree — the main repo's copy is not automatically updated. When you remove a worktree, any unsynced knowledge is lost.
701
+
702
+ **Why agents don't update the main CLAUDE.md directly:**
703
+
704
+ - **Race conditions** — Multiple agents run in parallel. If they all wrote to the same file simultaneously, you'd get conflicts and corruption.
705
+ - **Isolation** — Worktrees are separate git checkouts on separate branches. An agent reaching into the main repo's working directory to modify files would break the isolation model that makes parallel work safe.
706
+ - **Review gate** — Not every agent-discovered "pitfall" is correct or relevant. The owner should review before merging into the shared memory that all future agents inherit.
707
+
708
+ **The fix — two steps:**
709
+
710
+ 1. Tell agents to commit their CLAUDE.md changes with the rest of their work. The template already includes this instruction in the Agent Instructions section.
711
+
712
+ 2. Before removing worktrees, run `collect-learnings.sh` to diff each worktree's CLAUDE.md against the main and apply the new lines:
713
+
714
+ ```bash
715
+ # Interactive — prompts for each worktree
716
+ bash /path/to/claude-supervisor/bin/collect-learnings.sh /path/to/your-project
717
+
718
+ # Non-interactive — auto-approve all merges (CI, scripts, testing)
719
+ bash /path/to/claude-supervisor/bin/collect-learnings.sh --yes /path/to/your-project
720
+ ```
721
+
722
+ The script walks all active worktrees, shows any new lines, and asks whether to apply each one (unless `--yes` is passed). New Known Pitfalls bullets are inserted into the correct section; other additions are appended at the end. Then commit the result:
723
+
724
+ ```bash
725
+ git -C /path/to/your-project add .claude/CLAUDE.md
726
+ git -C /path/to/your-project commit -m "docs: merge agent learnings"
727
+ ```
728
+
729
+ This is the step that turns individual agent corrections into shared project memory.
730
+
731
+ ---
732
+
733
+ ## Custom Subagents
734
+
735
+ Subagents are defined in `.claude/agents/` — each file has YAML frontmatter and a system prompt. Claude Code reads them automatically at session start.
736
+
737
+ **How delegation works:** Claude automatically delegates tasks based on the task description in your request, the `description` field in subagent configurations, and current context. That's why the `description:` needs to be specific and concrete — it's essentially a routing rule. You can also add `"Use proactively"` in the description to make the agent trigger more aggressively. You can also force it explicitly: *"Use the debugger subagent to look at this error."*
738
+
739
+ Three subagents are included out of the box:
740
+
741
+ | Agent | Purpose |
742
+ |---|---|
743
+ | `reviewer.md` | Reviews code before a PR — flags critical issues, minor problems, and nits. Ends with APPROVE / REQUEST CHANGES. |
744
+ | `debugger.md` | Diagnoses errors and failures, traces root causes, applies minimal fixes. |
745
+ | `test-writer.md` | Writes unit and integration tests matching the project's existing style. |
746
+
747
+ `_example-agent.md` is a blank template you can copy to create your own. Add as many as you need — each focused on one job.
748
+
749
+ Any agent can delegate to a subagent via the `/agents` command or the `Task` tool.
750
+
751
+ ---
752
+
753
+ ## Spawning a Single Agent
754
+
755
+ `spawn-agent.sh` is independently runnable — you don't have to use the supervisor:
756
+
757
+ ```bash
758
+ bash /path/to/claude-supervisor/bin/spawn-agent.sh /path/to/repo my-branch claude-sonnet-4-5-20250929 normal 0 "fix the login bug"
759
+ ```
760
+
761
+ Arguments: `<repo_path> <branch_name> <model_id> <mode> <agent_index> "<task_prompt>"`
762
+
763
+ - `agent_index` — assigns a color to the tmux window (0-7 for different colors). Use `0` if spawning just one agent.
764
+
765
+ This creates the worktree, copies `.claude/`, opens a tmux window, and launches Claude — same as what the supervisor does, but for a single agent.
766
+
767
+ ---
768
+
769
+ ## Terminal Setup
770
+
771
+ - **tmux** — each agent gets its own tmux window, color-coded by index from a fixed palette. Plan-mode windows are always yellow.
772
+ - **Statusline** — run `/statusline` once in any Claude session to enable the context usage + git branch bar globally.
773
+
774
+ ---
775
+
776
+ ## File Structure
777
+
778
+ ```
779
+ claude-supervisor/
780
+ bin/
781
+ supervisor.sh # Entry point — run this
782
+ spawn-agent.sh # Single agent launcher (also standalone)
783
+ collect-learnings.sh # Merge CLAUDE.md updates from worktrees back to main
784
+ setup-shortcuts.sh # Shell shortcuts installer (adds to ~/.zshrc)
785
+ lib/
786
+ utils.sh # Shared functions (both scripts source this)
787
+ templates/ # Internal — never edit directly
788
+ tasks.conf # Scaffolded into project on first run
789
+ CLAUDE.md # Scaffolded into project .claude/
790
+ .claude/
791
+ settings.json # PermissionRequest → Opus hook
792
+ agents/
793
+ reviewer.md # Code review subagent
794
+ debugger.md # Debugging subagent
795
+ test-writer.md # Test writing subagent
796
+ _example-agent.md # Blank template
797
+ commands/
798
+ techdebt.md # /techdebt skill
799
+ explain.md # /explain skill
800
+ diagram.md # /diagram skill
801
+ learn.md # /learn skill
802
+ ```
803
+
804
+ ---
805
+
806
+ ## How Agents Run
807
+
808
+ The supervisor uses **tmux** to run agents in the background. Each agent gets its own tmux window with a descriptive name. This works in any terminal (iTerm, Terminal.app, Ghostty, VS Code, etc.).
809
+
810
+ After spawning, you have two ways to access agents:
811
+
812
+ | Method | Best for | How |
813
+ |---|---|---|
814
+ | **tmux attach** | Monitoring all agents at once | `tmux attach -t session` + navigate with `Ctrl+b` |
815
+ | **Separate tabs** | Easier navigation, familiar workflow | Copy the `cd ... && claude ...` commands into new tabs |
816
+
817
+ ---
818
+
819
+ ## Effective Prompts & Patterns
820
+
821
+ Patterns that work well when working with agents day-to-day.
822
+
823
+ ---
824
+
825
+ ### CLAUDE.md as a correction loop
826
+
827
+ After every mistake an agent makes and you correct it, tell it:
828
+
829
+ > *"Update CLAUDE.md so you don't make that mistake again."*
830
+
831
+ Over time this creates a project-specific rulebook. The next agent you spawn will inherit it and skip the same mistake entirely. The key habit is being ruthless about it — every correction, every time.
832
+
833
+ The template CLAUDE.md has a **Known Pitfalls** section for exactly this. Keep it updated.
834
+
835
+ ---
836
+
837
+ ### Autonomous bug fixing
838
+
839
+ Point an agent at the problem and say "fix":
840
+
841
+ ```ini
842
+ [task]
843
+ prompt = go fix the failing CI tests — run them, read the errors, iterate until they pass
844
+
845
+ [task]
846
+ prompt = the login flow throws a null pointer on logout — read the stack trace in logs/app.log and fix it
847
+
848
+ [task]
849
+ prompt = read docker logs for the auth service and fix whatever is causing the 500s
850
+ ```
851
+
852
+ You can also paste a raw error message or Slack thread directly into the task prompt. The agent will figure out where to start.
853
+
854
+ ---
855
+
856
+ ### Claude as a harsh reviewer
857
+
858
+ Use a plan-mode agent to review before merging:
859
+
860
+ ```ini
861
+ [task]
862
+ mode = plan
863
+ prompt = review the diff between main and feature-auth — act as a staff engineer, be harsh, flag anything that looks wrong, fragile, or incomplete. Do not approve until you are satisfied.
864
+
865
+ [task]
866
+ mode = plan
867
+ prompt = prove that the new auth flow actually works — trace the happy path and every failure case through the code
868
+
869
+ [task]
870
+ mode = plan
871
+ prompt = the last solution was too complex — scrap the approach and think through a simpler implementation
872
+ ```
873
+
874
+ The "prove this works" pattern is especially useful. A reviewer agent that has to justify the logic tends to catch things a writing agent glosses over.
875
+
876
+ ---
877
+
878
+ ### Turning repeat work into skills
879
+
880
+ There are two places to put reusable work:
881
+
882
+ - **`.claude/commands/`** — slash commands you invoke yourself (`/techdebt`, `/explain`, `/diagram`, `/learn`). Use for workflows you trigger intentionally.
883
+ - **`.claude/agents/`** — subagents Claude delegates to automatically based on the task. Use for specialized roles (reviewer, debugger, test writer).
884
+
885
+ If you do something more than once a week, it belongs in one of these. The rule of thumb: if *you* decide when to run it, it's a command. If *Claude* should decide when to delegate it, it's a subagent.
886
+
887
+ More ideas for commands:
888
+
889
+ | Command | What it does |
890
+ |---|---|
891
+ | `pr-description.md` | Reads the diff and writes a detailed PR body |
892
+ | `changelog.md` | Summarizes commits since the last tag into a CHANGELOG entry |
893
+ | `onboarding.md` | Generates an HTML walkthrough of a module for a new engineer |
894
+ | `db-query.md` | Writes and runs queries against your database CLI |
895
+
896
+ The database pattern deserves special mention: give the agent access to any DB with a CLI (`psql`, `sqlite3`, `bq`, etc.) and describe your intent in plain English. You stop writing queries and start describing outcomes.
897
+
898
+ ---
899
+
900
+ ### Learning mode
901
+
902
+ Enable explanatory output for any agent session via `/config` → output style → Explanatory. The agent will explain the *why* behind every change it makes, not just the *what*.
903
+
904
+ Four built-in skills accelerate understanding:
905
+
906
+ | Command | What it does |
907
+ |---|---|
908
+ | `/explain` | Explains what a file or function does, why it exists, and how it fits in |
909
+ | `/diagram` | Draws an ASCII diagram of the architecture, data flow, or call chain |
910
+ | `/learn` | Starts a Socratic learning session — you explain, Claude asks follow-ups, saves a summary |
911
+
912
+ Ad-hoc prompts that also work well:
913
+
914
+ > *"Generate an HTML presentation of this codebase I can step through like slides — one concept per slide."*
915
+
916
+ > *"I'll explain my understanding of this code. Ask follow-up questions to fill any gaps."*
917
+
918
+ These are especially useful when onboarding to an unfamiliar codebase before spawning worker agents.
919
+
920
+ ---
921
+
922
+ ### Shell aliases for session navigation
923
+
924
+ Add these to your `~/.zshrc` or `~/.bashrc` to hop between agent windows in one keystroke:
925
+
926
+ ```bash
927
+ # Jump to agent window by letter — adjust session name as needed
928
+ alias za='tmux select-window -t agents:0'
929
+ alias zb='tmux select-window -t agents:1'
930
+ alias zc='tmux select-window -t agents:2'
931
+ alias zd='tmux select-window -t agents:3'
932
+
933
+ # Or jump by branch name (fuzzy)
934
+ agent() { tmux select-window -t "$(tmux list-windows -F '#{window_name}' | fzf --query="$1" --select-1)"; }
935
+ ```
936
+
937
+ The `agent` function with `fzf` lets you type `agent login` and jump straight to the `feature-login` window without counting indices.
938
+
939
+ ---
940
+
941
+ ## Running Tests
942
+
943
+ Smoke tests verify that all functions and scripts work correctly:
944
+
945
+ ```bash
946
+ bash tests/smoke.sh
947
+ ```
948
+
949
+ The test suite checks: `slugify`, `print_banner`, `check_deps`, auto-init scaffolding, `tasks.conf` parsing, and `spawn-agent.sh` argument validation — all without needing an API key or tmux.
950
+
951
+ ---
952
+
953
+ ## Release Workflow
954
+
955
+ ```bash
956
+ # Bump version, update VERSION file, commit, and tag — all in one:
957
+ npm version patch # or minor / major
958
+ npm publish # runs smoke tests, then publishes to npm registry
959
+
960
+ # Git tag is created automatically by npm version
961
+ git push && git push --tags
962
+ ```
963
+
964
+ `npm version` updates `package.json`, writes the new version to `VERSION`, stages it, and creates a git commit + tag. `npm publish` runs the smoke tests first — if they fail, the publish is aborted.
965
+
966
+ ---
967
+
968
+ ## License
969
+
970
+ See [LICENSE](LICENSE).