worktree-compose 1.1.1 → 1.1.2

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 (2) hide show
  1. package/README.md +47 -716
  2. package/package.json +9 -2
package/README.md CHANGED
@@ -1,784 +1,115 @@
1
1
  <div align="center">
2
2
 
3
- <img src="https://raw.githubusercontent.com/mostafasudo/worktree-compose/main/worktree-compose.jpg" alt="worktree-compose logo" width="140" />
3
+ <img src="https://raw.githubusercontent.com/mostafasudo/worktree-compose/main/worktree-compose.jpg" alt="worktree-compose logo" width="120" />
4
4
 
5
5
  # worktree-compose · `wtc`
6
6
 
7
7
  ### Zero-config Docker Compose isolation for git worktrees
8
8
 
9
- Every worktree gets its own ports, database, cache, and containers — **automatically**.
9
+ Every worktree gets its own ports, database, cache, and containers.
10
10
 
11
11
  [![npm version](https://img.shields.io/npm/v/worktree-compose?label=npm&color=cb3837&logo=npm)](https://www.npmjs.com/package/worktree-compose)
12
12
  [![downloads](https://img.shields.io/npm/dm/worktree-compose?color=cb3837)](https://www.npmjs.com/package/worktree-compose)
13
- [![node](https://img.shields.io/node/v/worktree-compose?color=339933&logo=node.js&logoColor=white)](https://nodejs.org)
14
13
  [![license](https://img.shields.io/npm/l/worktree-compose?color=blue)](https://github.com/mostafasudo/worktree-compose/blob/main/LICENSE)
15
14
  [![DevHunt](https://img.shields.io/badge/DevHunt-%231%20Product%20of%20the%20Week-ff6154)](https://devhunt.org/tool/worktree-compose)
15
+ [![Glama MCP server](https://glama.ai/mcp/servers/mostafasudo/worktree-compose/badges/score.svg)](https://glama.ai/mcp/servers/mostafasudo/worktree-compose)
16
16
 
17
- **[worktree-compose.com](https://www.worktree-compose.com)** · [Changelog](https://github.com/mostafasudo/worktree-compose/blob/main/CHANGELOG.md) · [Agent skill](https://github.com/mostafasudo/worktree-compose/blob/main/SKILL.md) · [GitHub](https://github.com/mostafasudo/worktree-compose)
17
+ **[Website](https://www.worktree-compose.com)** · [Docs](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md) · [Changelog](https://github.com/mostafasudo/worktree-compose/blob/main/CHANGELOG.md) · [Agent skill](https://github.com/mostafasudo/worktree-compose/blob/main/SKILL.md)
18
18
 
19
- <img src="https://raw.githubusercontent.com/mostafasudo/worktree-compose/main/wtc-explainer.gif" alt="worktree-compose demo — isolated Docker stacks per git worktree" width="820" />
20
-
21
- <em>The full <code>wtc</code> workflow: an isolated Docker stack per worktree, four AI agents building in parallel, compared live on their own ports — then promote the winner and clean up. <a href="https://www.worktree-compose.com/#demo">Watch the video</a>.</em>
19
+ <img src="https://raw.githubusercontent.com/mostafasudo/worktree-compose/main/wtc-explainer.gif" alt="worktree-compose demo: isolated Docker stacks per git worktree" width="820" />
22
20
 
23
21
  </div>
24
22
 
25
- ```bash
26
- npm install -g worktree-compose
27
- ```
28
-
29
- ```
30
- wtc list
31
-
32
- ┌───────┬──────────────┬────────┬────────────────────────┬────────────────────────────────────────────────────────────┐
33
- │ Index │ Branch │ Status │ URL │ Ports │
34
- ├───────┼──────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
35
- │ - │ main │ - │ - │ postgres:5434 backend:8000 frontend:5173 │
36
- ├───────┼──────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
37
- │ 1 │ feature-auth │ up │ http://localhost:25174 │ POSTGRES_PORT=25435 BACKEND_PORT=28001 FRONTEND_PORT=25174 │
38
- ├───────┼──────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
39
- │ 2 │ fix-billing │ exited │ http://localhost:25175 │ POSTGRES_PORT=25436 BACKEND_PORT=28002 FRONTEND_PORT=25175 │
40
- └───────┴──────────────┴────────┴────────────────────────┴────────────────────────────────────────────────────────────┘
41
- ```
42
-
43
- > **Type `wtc`, not `npx wtc`.** An unrelated npm package is named `wtc`, so without the global install `npx wtc` downloads and runs that package instead. For a one-off run without installing, use `npx worktree-compose <command>` (for example `npx worktree-compose list`).
44
-
45
- ## Contents
46
-
47
- - [Why wtc?](#why-wtc)
48
- - [How is this different from `docker compose -p`?](#how-is-this-different-from-docker-compose--p)
49
- - [Quick Start](#quick-start)
50
- - [Usage](#usage)
51
- - [Selecting worktrees](#selecting-worktrees)
52
- - [Preparing your compose file](#preparing-your-compose-file)
53
- - [Monorepos & custom env files](#monorepos--custom-env-files)
54
- - [How It Works](#how-it-works) — [stable identity](#stable-worktree-identity), [ports](#port-allocation), [project names](#container-isolation-and-compose_project_name), [runtime remapping](#runtime-remapping), [file sync](#file-sync), [env files](#env-files)
55
- - [Commands](#commands) — [what each one does to your data](#what-each-command-does-to-your-data)
56
- - [Configuration (Optional)](#configuration-optional)
57
- - [Docker, Podman, OrbStack, Colima](#docker-podman-orbstack-colima)
58
- - [MCP Server](#mcp-server)
59
- - [Agent Skill](#agent-skill)
60
- - [Full Example](#full-example)
61
- - [Upgrading from 0.2](#upgrading-from-02)
62
- - [Requirements](#requirements)
63
- - [Troubleshooting](#troubleshooting)
64
- - [Contributing](#contributing)
65
- - [License](#license)
66
-
67
- ## Why wtc?
68
-
69
- Spin up multiple developers or AI agents on the same repo — each in its own [git worktree](https://git-scm.com/docs/git-worktree) — and they immediately fight over a single Docker Compose setup: port conflicts, a shared database, a shared cache, colliding containers. You can't run two stacks side by side.
70
-
71
- `wtc` reads your existing compose file and turns every worktree into a fully isolated, side-by-side environment — unique host ports, separate containers, networks, and volumes — with **zero configuration**.
72
-
73
- - ⚡ **Zero config** — reads your existing `docker-compose.yml` / `compose.yaml` as it is: hardcoded host ports and `container_name` are remapped at runtime, never edited
74
- - 🔌 **Automatic ports** — unique, collision-free host ports per worktree
75
- - 📦 **Full isolation** — separate containers, networks, and volumes for each stack
76
- - 📌 **Stable identity** — a worktree keeps its index, ports, and project name; removing one never renumbers the others
77
- - 🧪 **True side-by-side** — run `N` stacks at once and compare them in the browser
78
- - 🔄 **One-command promote** — pull a worktree's changes back into your branch
79
- - 🐳 **Docker or Podman** — Docker Compose v2, Podman, OrbStack, Colima
80
- - 🩺 **`wtc doctor`** — finds what would break isolation before it bites
81
- - 🤖 **Built-in MCP server + agent skill** — let AI agents start, stop, and manage their own stacks
82
-
83
- <table>
84
- <tr><th>Without <code>wtc</code></th><th>With <code>wtc</code></th></tr>
85
- <tr><td>
23
+ Put several AI agents or developers on one repo, each in its own [git worktree](https://git-scm.com/docs/git-worktree), and they fight over one Docker Compose setup: the same ports, the same database, the same container names. `wtc` reads the compose file you already have and gives each worktree a stack of its own, so they all run side by side. Think `docker compose -p` with the rest done for you: free ports, env files, file sync, promote and cleanup.
86
24
 
87
- ```bash
88
- git worktree add ../app-feat feat
89
- # hand-pick non-colliding host ports
90
- # edit ../app-feat/.env per service
91
- # copy compose file + Dockerfiles over
92
- docker compose -p app-feat up -d --build
93
- # ...remember to tear it all down later
94
- ```
95
-
96
- </td><td>
25
+ ## Install
97
26
 
98
27
  ```bash
99
- git worktree add ../app-feat feat
100
- wtc start
101
-
102
- # ...and when you're done:
103
- wtc clean
28
+ npm install -g worktree-compose
104
29
  ```
105
30
 
106
- </td></tr>
107
- </table>
108
-
109
- ## How is this different from `docker compose -p`?
31
+ > Type `wtc`, never `npx wtc`: an unrelated npm package has that name. To run it without installing, use `npx worktree-compose <command>`.
110
32
 
111
- `docker compose -p` only namespaces the project. You'd still hand-pick free host ports, hand-edit each worktree's `.env`, copy infra files in, remember which project belongs to which worktree, and tear everything down yourself. `wtc` builds on that same project-name isolation and automates the rest: collision-free **port allocation** (hardcoded host ports included), a **stable index and project name** per worktree, per-worktree **env file injection** (including `COMPOSE_PROJECT_NAME`, so plain `docker compose` in the worktree hits the right stack), infra-file **sync**, one-command **`promote`**, safe **cleanup**, and a built-in **MCP server** so AI agents can drive it all themselves.
112
-
113
- ## Quick Start
33
+ ## Quick start
114
34
 
115
35
  ```bash
116
- # 1. Install once, globally
117
- npm install -g worktree-compose
118
-
119
- # 2. Create a worktree for some parallel work
120
36
  git worktree add -b feature ../myapp-feature
121
-
122
- # 3. Boot an isolated stack for it ("." = the worktree you're in)
123
37
  cd ../myapp-feature
124
- wtc start .
125
-
126
- # 4. See every stack, its status, URL, and ports
127
- wtc list
128
-
129
- # 5. Something off? Ask the doctor
130
- wtc doctor
131
- ```
132
-
133
- `wtc` works from the main checkout or from any worktree: it always reads the compose file, config, and env files from the main checkout.
134
-
135
- ## Usage
136
-
137
- ```bash
138
- wtc start # start every worktree's stack
139
- wtc start . # just the worktree you're in
140
- wtc start 1 fix-billing # by index, branch, directory name, or path
141
- wtc start --no-build # skip the image rebuild
142
- wtc start --env .env.development --workspace server # monorepo env files
143
-
144
- wtc list # status, URL, and ports (alias: wtc ls; --json for scripts)
145
- wtc stop 1 # stop the containers; data is kept and start resumes them
146
- wtc restart . # re-sync files and env, recreate what changed
147
-
148
- wtc promote fix-billing # copy a worktree's changes into the current checkout
149
-
150
- wtc prune # tear down stacks of worktrees you already deleted
151
- wtc clean --dry-run # preview the full cleanup
152
- wtc clean # tear down every stack (deletes volumes), remove worktrees that hold no work
153
-
154
- wtc doctor # check git, engine, ports, isolation, orphans
155
- wtc skill --install # install the agent skill
156
- wtc mcp # MCP server for AI agents (stdio)
157
- ```
158
-
159
- ## Selecting worktrees
160
-
161
- `start`, `stop`, and `restart` take any number of worktrees (none means all); `promote` takes exactly one. Each one can be given as:
162
38
 
163
- | Selector | Example | Matches |
164
- |----------|---------|---------|
165
- | index | `2` | the worktree's stable index (the `Index` column of `wtc list`) |
166
- | branch | `fix-billing` | the branch checked out in the worktree |
167
- | directory name | `myapp-fix-billing` | the basename of the worktree's directory |
168
- | path | `../myapp-fix-billing` | a path, resolved against the current directory (symlinks such as macOS `/tmp` are followed) |
169
- | `.` | `.` | the worktree that contains the current directory |
170
-
171
- - A name that matches several worktrees (say, two directories with the same basename in different places) is an error listing them; use the index instead.
172
- - A number is an index, unless it also names a *different* worktree (a branch or directory called `2`). Then `wtc` refuses and asks for the branch, the directory name, or a path — the message suggests one that works from where you are (e.g. `../2`).
173
- - Through MCP, a JSON number is always an index; a string follows the rules above.
174
-
175
- ## Preparing your compose file
176
-
177
- `wtc` looks for `compose.yaml`, `compose.yml`, `docker-compose.yaml`, or `docker-compose.yml` (in that order) at the root of the main checkout.
178
-
179
- You don't have to change it. Each worktree gets its own host ports either way:
180
-
181
- ```yaml
182
- # A variable (upper-case name): wtc sets it per worktree and writes it to the worktree's env file
183
- ports:
184
- - "${BACKEND_PORT:-8000}:8000"
185
-
186
- # Hardcoded: wtc remaps it per worktree at runtime; the file stays as it is
187
- ports:
188
- - "8080:8080"
189
- ```
190
-
191
- Hardcoded host ports (and a fixed `container_name`) are [remapped at runtime](#runtime-remapping) through a compose override `wtc` generates, which needs Docker Compose 2.24.4 or newer. `wtc start` says what it remapped:
192
-
193
- ```
194
- ℹ Remapping hardcoded host ports per worktree at runtime (your compose file is unchanged): nginx 8080:80. To use one in env values, give it a variable, e.g. "${NGINX_PORT:-8080}:80".
195
- ```
196
-
197
- Use a variable when something else needs the port's per-worktree value: the variable is written to the worktree's env file and can be used in [`envOverrides`](#envoverrides) (a `DATABASE_URL`, an API URL), while a remapped port is only published. With an engine that can't remap, `wtc` warns about hardcoded ports instead, and they stay the same in every worktree:
198
-
199
- ```
200
- ⚠ Service "nginx" uses a raw port mapping (8080:80). To enable port isolation, change it to: "${NGINX_PORT:-8080}:80"
201
- ```
202
-
203
- ### Supported port formats
204
-
205
- ```yaml
206
- # Standard
207
- - "${BACKEND_PORT:-8000}:8000"
208
-
209
- # Same var for host and container
210
- - "${FRONTEND_PORT:-5173}:${FRONTEND_PORT:-5173}"
211
-
212
- # IP-bound
213
- - "127.0.0.1:${API_PORT:-3000}:3000"
214
-
215
- # With protocol
216
- - "${BACKEND_PORT:-8000}:8000/tcp"
217
-
218
- # Multiple ports per service
219
- - "${BACKEND_PORT:-8000}:8000"
220
- - "${DEBUG_PORT:-9229}:9229"
221
-
222
- # Long-form syntax
223
- - target: 8000
224
- published: "${BACKEND_PORT:-8000}"
225
- protocol: tcp
226
- ```
227
-
228
- ### Settings that break isolation
229
-
230
- `wtc start` and `wtc doctor` warn about compose settings that make worktree stacks collide or share data (`wtc list` only prints how many there are):
231
-
232
- - **Hardcoded host ports and `container_name: db`** — every stack would publish the same ports and use the same container name, so the second one fails to start. `wtc` [remaps both at runtime](#runtime-remapping) and only warns when it can't; then write the port as `"${DB_PORT:-5432}:5432"`, and remove `container_name` or make it per-stack: `container_name: ${COMPOSE_PROJECT_NAME:-myapp}-db`.
233
- - **Host port ranges** (`"8000-8010:8000-8010"`) — not remapped: every stack binds the same ports.
234
- - **Top-level volumes or networks with a fixed `name:` or `external: true`** — every stack shares them. A `name:` that contains `${COMPOSE_PROJECT_NAME}` is per-stack and fine.
235
- - **Cross-worktree port collisions** — see [`portStride`](#clustered-default-ports-and-portstride).
236
-
237
- ### Included compose files
238
-
239
- If your compose file pulls in others via the top-level [`include:`](https://docs.docker.com/reference/compose-file/include/) directive, `wtc` follows them recursively — services defined in included files get the same port isolation as top-level ones, and the included files are copied into each worktree alongside the main one.
240
-
241
- ```yaml
242
- include:
243
- - ./db/compose.yml
244
- - path: ./services/api/compose.yml
39
+ wtc start . # build and start this worktree's stack on its own ports
40
+ wtc list # every stack with its status, URL and ports
245
41
  ```
246
42
 
247
- Build contexts in an included file resolve relative to that file's own directory, just as Docker Compose does. (Included files that live outside the repo still have their ports isolated, but aren't copied into the worktree.)
248
-
249
- ## Monorepos & custom env files
250
-
251
- In a monorepo, local env files usually live next to each app (`apps/server/.env.development`) instead of at the repo root, and the filename isn't always `.env`. Use `envFile` plus workspace selectors to keep every worktree's env files consistent:
43
+ When the work is done:
252
44
 
253
45
  ```bash
254
- # Copy + inject apps/server/.env.development and apps/homepage/.env.development
255
- # into the worktree, in addition to the root env file
256
- wtc start --env .env.development --workspace server --workspace homepage
46
+ wtc promote feature # copy its changes into your checkout, uncommitted
47
+ wtc clean # tear down every stack (deletes their volumes), remove worktrees that hold no work
257
48
  ```
258
49
 
259
- Or make it the project default in `.wtcrc.json`:
260
-
261
- ```json
262
- {
263
- "$schema": "https://unpkg.com/worktree-compose/wtc.schema.json",
264
- "envFile": ".env.development",
265
- "workspaces": ["server", "homepage"],
266
- "workspaceEnvOverrides": {
267
- "server": {
268
- "DATABASE_URL": "postgresql://postgres:postgres@localhost:${POSTGRES_PORT}/postgres"
269
- }
270
- }
271
- }
272
- ```
273
-
274
- How workspace selection works:
275
-
276
- - Workspaces come from `package.json#workspaces` (npm/bun/yarn) or `pnpm-workspace.yaml#packages`. Only directories with a `package.json` count. In a repo that declares no workspaces, `--workspace server` looks for a `package.json` in `server`, `apps/server`, `packages/server`, or `libs/server`.
277
- - `--workspace` matches by package **name**, directory name, or repo-relative path, and may be repeated. On the command line it replaces the configured `workspaces` for that run; `--env` likewise replaces `envFile`.
278
- - The **repo root is always processed** — docker compose interpolates `${POSTGRES_PORT:-5434}` from the root env file, so skipping it would break port isolation. Only the root env file gets `COMPOSE_PROJECT_NAME`.
279
- - Every target gets the allocated port variables. A selected workspace with no env file (and no `.env.example`) is skipped with a warning.
280
- - `workspaceEnvOverrides` keys match a workspace by package name, then by directory name (only when no other workspace shares it), then by repo-relative path.
281
- - `restart` checks `--env` and `--workspace` before stopping anything, so a typo never leaves stacks stopped.
282
-
283
- > **Why `--env`, not `--env-file`?** Node.js intercepts `--env-file` in its own argv parsing — even after the script path — so the flag never reaches `wtc`. `--env` is the safe spelling; the config key stays `envFile`. It must be a bare filename such as `.env.development`.
284
-
285
- ## How It Works
286
-
287
- ### Stable worktree identity
288
-
289
- The first time `wtc` acts on a worktree (`start`, `stop`, …), it records the worktree's **index** (which decides its ports) and its **compose project name** in `.git/wtc/state.json`: inside the git directory every worktree shares, never committed. From then on they don't change. `wtc list`, `wtc doctor`, and dry runs only read: they show the identity a new worktree will get without recording it.
290
-
291
- - **Removing a worktree never renumbers the others.** (0.2 derived the index from the position in `git worktree list`, so removing worktree 1 silently moved worktree 2 onto new ports and a new project, orphaning its running stack — [#9](https://github.com/mostafasudo/worktree-compose/issues/9).)
292
- - **A new worktree gets the lowest index no record holds.**
293
- - **Renaming the branch keeps the project name**, and **`git worktree move` keeps the index, ports, and project**: `wtc` keeps an id in the worktree's git admin directory (`.git/worktrees/<name>/wtc-id`), which a move keeps and `git worktree remove` deletes. Restart a moved worktree so bind mounts follow the new path.
294
- - **A worktree you delete becomes an orphan.** After `git worktree remove` or `rm -rf`, `wtc list` shows it as `(removed)`. Its index stays reserved, because its stack may still be running on those ports, until `wtc prune` (or `wtc clean`) tears the stack down and forgets it.
295
- - **A worktree git still lists is never an orphan**, even when `wtc` can't start it: a [locked](https://git-scm.com/docs/git-worktree#_commands) worktree whose directory is missing (an unmounted drive) shows as `(locked, missing on disk)` and keeps its index, record, and stack until it is back; `prune` and `clean` leave it alone.
296
-
297
- ```
298
- git worktree remove ../myapp-spike-cache
299
- git worktree add -b docs ../myapp-docs
300
- wtc list
301
-
302
- ┌───────┬───────────────────────┬────────┬────────────────────────┬────────────────────────────────────────────────────────────┐
303
- │ Index │ Branch │ Status │ URL │ Ports │
304
- ├───────┼───────────────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
305
- │ - │ main │ - │ - │ postgres:5434 backend:8000 frontend:5173 │
306
- ├───────┼───────────────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
307
- │ 1 │ feature-auth │ up │ http://localhost:25174 │ POSTGRES_PORT=25435 BACKEND_PORT=28001 FRONTEND_PORT=25174 │
308
- ├───────┼───────────────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
309
- │ 2 │ fix-billing │ exited │ http://localhost:25175 │ POSTGRES_PORT=25436 BACKEND_PORT=28002 FRONTEND_PORT=25175 │
310
- ├───────┼───────────────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
311
- │ 3 │ spike-cache (removed) │ up │ - │ POSTGRES_PORT=25437 BACKEND_PORT=28003 FRONTEND_PORT=25176 │
312
- ├───────┼───────────────────────┼────────┼────────────────────────┼────────────────────────────────────────────────────────────┤
313
- │ 4 │ docs │ down │ http://localhost:25177 │ POSTGRES_PORT=25438 BACKEND_PORT=28004 FRONTEND_PORT=25177 │
314
- └───────┴───────────────────────┴────────┴────────────────────────┴────────────────────────────────────────────────────────────┘
315
- (removed) = the worktree is gone but its stack/record remains. Run 'wtc prune' to tear it down.
316
- ```
317
-
318
- **Coming from 0.2?** On the first run, `wtc` gives existing worktrees the same positional indices 0.2 used, and a worktree whose 0.2 stack is still running adopts that stack's index and project (matched by the directory compose ran in). Running stacks are picked up, not duplicated. If `state.json` is ever lost or unreadable, it is rebuilt the same way (an unreadable file is first moved aside as `state.json.bak-<time>`).
319
-
320
- ### Port Allocation
321
-
322
- Each worktree gets unique ports from its index: `20000 + default_port + (worktree_index × portStride)`
323
-
324
- `portStride` defaults to `1`, so by default the table below holds:
325
-
326
- | Service | Main (default) | Worktree 1 | Worktree 2 | Worktree 3 |
327
- |----------|---------------|------------|------------|------------|
328
- | postgres | 5434 | 25435 | 25436 | 25437 |
329
- | backend | 8000 | 28001 | 28002 | 28003 |
330
- | frontend | 5173 | 25174 | 25175 | 25176 |
331
-
332
- The table is illustrative — every value follows the formula above. (If an allocation would exceed `65535`, `wtc` falls back to `default_port + 100 × index`.)
333
-
334
- #### Clustered default ports and `portStride`
335
-
336
- With the default stride of `1`, two worktrees collide on a port whenever a pair of services has default host ports whose difference equals the worktrees' index difference. Projects with **clustered** default ports (e.g. mocks on `8081`–`8086`) therefore collide even between adjacent worktrees, and the second `docker compose up` fails to bind.
337
-
338
- When `wtc` detects such a collision across the indices in use (live worktrees and orphans) it warns, naming the colliding ports and the recommended stride. Set `portStride` in your config (`.wtcrc.json` or `package.json#wtc`) to spread each worktree's ports far enough apart:
339
-
340
- ```json
341
- { "portStride": 100 }
342
- ```
343
-
344
- A stride of `100` gives every worktree a 100-port band, which is collision-free unless some pair of default ports differs by an exact multiple of the stride. The recommended value in the warning is the smallest stride that is collision-free over a generous worktree horizon. The canonical `docker compose up` in the main checkout is unaffected — only the worktrees' ports change.
345
-
346
- ### Container isolation and `COMPOSE_PROJECT_NAME`
347
-
348
- Each worktree's stack runs as the compose project `{repo}-wt-{index}-{branch}`, lowercased with anything other than `a-z`, `0-9`, and `-` turned into `-` — for example `myapp-wt-1-feature-auth`. Compose names containers, networks, and volumes after the project, so nothing is shared. `{repo}` is the main checkout's directory name (for a bare repository, the repository's own name), so it is the same from every worktree.
349
-
350
- `wtc` passes `-p <project>` on every compose call, exports `COMPOSE_PROJECT_NAME` and the allocated ports into compose's environment, and writes `COMPOSE_PROJECT_NAME=<project>` into the worktree's root env file (plus `COMPOSE_FILE` when it [remaps hardcoded settings](#runtime-remapping)). With the default `.env`, a plain `docker compose ps` / `logs` / `exec` (or a Makefile) run inside the worktree therefore reaches the same stack on the same ports.
351
-
352
- Compose only reads a file named `.env` on its own. With a custom `envFile` such as `.env.development`, pass it explicitly (`docker compose --env-file .env.development ps`) or pass `-p <project>` (the `project` field of `wtc list --json`). `-p` is enough for `ps`, `logs`, and `exec`; `up` also needs `--env-file`, so it loads the [runtime remapping](#runtime-remapping)'s `COMPOSE_FILE` (or run `wtc restart .`).
353
-
354
- `${COMPOSE_PROJECT_NAME}` is also available in `envOverrides` and `workspaceEnvOverrides` values, e.g. `"QUEUE_PREFIX": "${COMPOSE_PROJECT_NAME}-jobs"`.
355
-
356
- ### Runtime remapping
357
-
358
- A hardcoded host port (`"8080:80"`) or a fixed `container_name` would make every worktree stack collide. Instead of asking you to edit the compose file, `wtc` writes a compose override for each worktree stack:
359
-
360
- ```yaml
361
- # .git/wtc/compose/myapp-wt-1-feature-auth.yaml (generated, rewritten on every start)
362
- services:
363
- web:
364
- ports: !override
365
- - "28081:80"
366
- container_name: !reset null
367
- networks:
368
- default:
369
- aliases:
370
- - "web"
371
- ```
372
-
373
- - `ports: !override` replaces the service's port list: every entry as written, with only the hardcoded host ports swapped for the worktree's (same IP, protocol, and long-form fields). A plain override can't do this, because compose merges port lists and would still publish `8080`.
374
- - `container_name: !reset null` drops the fixed name, so compose names the containers after the project (`myapp-wt-1-feature-auth-web-1`). The old name stays a network alias on the stack's own networks, so containers that reach the service by it (`DB_HOST=mydb`) still do, and reach this stack's copy. Not on a network every stack shares (fixed `name:` or `external`), where the alias would answer for all of them, nor with `network_mode`.
375
- - Every compose call on the stack (`start`, `stop`, teardown) runs with `COMPOSE_FILE` listing the compose file, the worktree's own `compose.override.yaml` if it has one, and this file. `wtc` also writes that `COMPOSE_FILE` into the worktree's root env file, so a plain `docker compose up` run from the worktree's root uses the same ports. (From a subdirectory, compose finds the compose file itself and ignores `COMPOSE_FILE` in `.env`.)
376
- - The file lives in `.git/wtc/compose/`, never in your working tree. `start` rewrites it after syncing the compose file; `stop` and teardown use it as the stack was started. It is deleted when `wtc prune` or `wtc clean` forgets the worktree; a worktree that `clean` keeps also keeps its override, since its env file still lists it.
377
- - `wtc list` shows a remapped port as `<service>:<default port>`, e.g. `web:8080=28081`, as `start` allocates it for that worktree. It has no variable, so nothing is written to env files for it and `envOverrides` can't refer to it; give it a variable in the compose file when an env value needs it.
378
-
379
- `!override` and `!reset` need Docker Compose 2.24.4 or newer. `wtc` checks once per run that the engine applies them (`compose config` on a throwaway file; no containers, no daemon) and otherwise remaps nothing and warns as before. It also leaves alone:
380
-
381
- - what the worktree's own `compose.override.yaml` (or `docker-compose.override.yml`, …) sets for a service: its `ports` (or `extends`) or `container_name` would be discarded;
382
- - the ports of a service that uses `extends`, which may inherit ports `wtc` can't see;
383
- - the ports of a service from an `include:`d file whose ports use variables: compose fills those in from that file's own `.env`, while an override is filled in from the main project's;
384
- - host port ranges, a hardcoded port too high to move, and one whose new port the stack already publishes (they stay as they are, with a warning);
385
- - a `container_name` another service joins by name (`network_mode: container:mydb`, `volumes_from`, `ipc`, `pid`): an alias can't stand in for the container itself;
386
- - everything, when you set `COMPOSE_FILE` yourself: in your environment, the root env file, the main checkout's `.env`, `envOverrides`, or a worktree's own `.env` (either `COMPOSE_FILE=` or `COMPOSE_FILE:`), or set a different `COMPOSE_PATH_SEPARATOR` there. A `COMPOSE_FILE` that is exactly the list `wtc` wrote (a worktree's `.env` exported by direnv, say) doesn't count; one you added a file to does.
387
-
388
- `wtc doctor` lists what is remapped, or why it can't be.
389
-
390
- ### File Sync
391
-
392
- Before every start, `wtc` copies infrastructure files from the main checkout into the worktree, so every worktree runs the latest Docker setup:
393
-
394
- - the compose file, plus every file it pulls in via `include:` (inside the repo);
395
- - every Dockerfile a service's `build` points to (remote build contexts and `dockerfile_inline` have none);
396
- - the extra paths listed in [`sync`](#sync). Entries must stay inside the repository; absolute or `../` entries are skipped with a warning.
397
-
398
- Sync copies over what is at those paths and removes nothing else: files that only the worktree has stay. Symlinks are recreated as symlinks, never followed. `wtc` never writes through a symlink it finds at a destination (it replaces the link) and skips any destination whose directory resolves outside the worktree. Where main has a symlink but the worktree has a real directory, the directory is left alone with a warning.
399
-
400
- ### Env Files
401
-
402
- On every `start` and `restart`, for the root and each selected workspace:
403
-
404
- 1. **Copy fresh from main:** `<envFile>` (default `.env`), falling back to `.env.example`. The root gets an empty file if neither exists; a workspace with neither is skipped.
405
- 2. **Inject:** `COMPOSE_PROJECT_NAME` (root only; with [runtime remapping](#runtime-remapping) also `COMPOSE_FILE`), every allocated port variable, then `envOverrides` (root) or `workspaceEnvOverrides` (that workspace). **A key that already exists is rewritten in place** — comments, ordering, and all other lines are preserved. Keys that don't exist are appended in a marked block, which is replaced on every run and never accumulates.
406
-
407
- With `"envOverrides": { "DATABASE_URL": "postgresql://app:app@localhost:${POSTGRES_PORT}/app" }` and a main `.env` of
408
-
409
- ```bash
410
- POSTGRES_PORT=5434
411
- DATABASE_URL=postgresql://app:app@localhost:5434/app
412
- ```
413
-
414
- worktree 1 gets:
415
-
416
- ```bash
417
- POSTGRES_PORT=25435
418
- DATABASE_URL=postgresql://app:app@localhost:25435/app
419
-
420
- # --- wtc port overrides ---
421
- COMPOSE_PROJECT_NAME=myapp-wt-1-feature-auth
422
- BACKEND_PORT=28001
423
- FRONTEND_PORT=25174
424
- # --- end wtc ---
425
- ```
426
-
427
- Two consequences of copying fresh every time:
428
-
429
- - **Edits made only in a worktree's env file are lost on the next start.** Put lasting values in main's env file, or in `envOverrides` / `workspaceEnvOverrides`.
430
- - **Only the keys above are written.** A value with a port inside it, like `DATABASE_URL` above, keeps main's port unless you add an override for it.
431
-
432
- If a worktree's env file is a symlink (for example to main's `.env`), `wtc` replaces the link with a regular copy and never writes through it.
433
-
434
- The allocated ports are also exported into the environment of the compose process `wtc` launches. Compose resolves `${VAR:-default}` from the process environment, `--env-file`, and the project `.env` — never from a service's `env_file:`, and never from a custom filename like `.env.development`. Exporting the ports keeps published host ports correct when the project uses a custom `envFile`.
435
-
436
- ### Repository layouts
437
-
438
- Besides a plain clone, `wtc` handles bare repositories with worktrees (the worktree on the repository's default branch acts as the main checkout and is never started, synced into, or removed), submodules, and `--separate-git-dir` checkouts. Locked worktrees work normally; a locked worktree whose directory is missing (an unmounted drive) is skipped with a warning, and its stack and index are kept.
439
-
440
- Two layouts don't tell from every worktree which checkout is the main one: a bare repository whose default-branch worktree is mid-rebase, mid-bisect, or on another branch for now, and a `--separate-git-dir` repository seen from a linked worktree. `wtc` remembers the main checkout (in `.git/wtc/state.json`) once it has run there or found it, and uses that. When it can't tell at all, it warns, uses the current checkout's compose and config files for `list`, `doctor`, `stop`, `promote`, and `prune`, records nothing, and refuses `start`, `restart`, and `clean` — they would sync files into, start, or remove checkouts based on the wrong one. The error says how to fix it: check the default branch out in your main worktree, or run `wtc start` from the main checkout.
441
-
442
50
  ## Commands
443
51
 
444
- ### `wtc start`
445
-
446
- ```
447
- wtc start [worktrees...] [--env <name>] [--workspace <name>]... [--no-build]
448
- ```
449
-
450
- For each selected worktree (all when none are given): sync infrastructure files, copy and inject env files, then run `compose -p <project> up -d --build`. Stops at the first failure; on success it prints `wtc list`. A worktree whose directory is missing is refused (see `wtc prune`). The main checkout's own stack is not managed by `wtc`: run `docker compose` there as usual.
451
-
452
- | Flag | |
453
- |------|-|
454
- | `--env <name>` | Env filename to copy and inject for this run (default: `envFile`, else `.env`) |
455
- | `--workspace <name>` | Workspace to also inject env into; repeatable (see [Monorepos](#monorepos--custom-env-files)) |
456
- | `--no-build` | Run `compose up -d` without `--build` |
457
-
458
- ### `wtc stop`
459
-
460
- ```
461
- wtc stop [worktrees...]
462
- ```
463
-
464
- Runs `compose stop`: containers are stopped, **not removed**, and all volumes are kept — including the anonymous ones images like postgres and redis create — so `wtc start` resumes the same containers with their data. `wtc list` shows a stopped stack as `exited`. One failure doesn't stop the rest; the exit code is 1 if any stack failed to stop.
465
-
466
- ### `wtc restart`
467
-
468
- ```
469
- wtc restart [worktrees...] [--env <name>] [--workspace <name>]... [--no-build]
470
- ```
471
-
472
- `compose stop`, then everything `start` does, with `up -d --build --remove-orphans`: unchanged services start again, changed ones are recreated (keeping their volumes), and containers of services you removed from the compose file go away. Use it after migrations, Dockerfile changes, or config updates. Env options and selectors are validated before anything is stopped.
473
-
474
- ### `wtc list`
475
-
476
- ```
477
- wtc list [--json] # alias: wtc ls
478
- ```
479
-
480
- Every worktree with its index, branch, status, URL, and ports, plus a row for main's default ports. Status is `up`, `partial` (with running/total, e.g. `partial 2/3`), `exited` (containers stopped), `down` (no containers), or `?` (no reachable engine). One-off `docker compose run` containers are not counted. Removed worktrees whose record remains are shown as `(removed)`; worktrees git still lists but `wtc` can't start as `(locked, missing on disk)` or `(now the main checkout)`. Read-only: it never writes the registry.
481
-
482
- `--json` prints an array of `{ index, branch, path, project, status, running, total, url, ports, orphan, unavailable }` to stdout (`unavailable` is `"missing"`, `"main"`, or `null`); warnings go to stderr. The URL is the first service whose name contains `frontend`, `web`, `app`, or `ui`, else the last isolated port.
483
-
484
- ### `wtc promote`
52
+ | Command | What it does |
53
+ |---------|--------------|
54
+ | `wtc start` | Sync compose files and Dockerfiles from main, write the worktree's ports into its env file, `compose up -d --build` |
55
+ | `wtc stop` | Stop the containers. Data is kept and `start` resumes them |
56
+ | `wtc restart` | Re-sync, then recreate what changed |
57
+ | `wtc list` | Status, URL and ports of every stack (`--json` for scripts) |
58
+ | `wtc promote <worktree>` | Copy a worktree's changes into the current checkout, uncommitted |
59
+ | `wtc prune` | Tear down the stacks of worktrees you deleted (deletes their volumes) |
60
+ | `wtc clean` | Tear down every stack (deletes their volumes) and remove worktrees that hold no work. Preview with `--dry-run` |
61
+ | `wtc doctor` | Check git, the engine, ports and isolation, and say what to fix |
62
+ | `wtc skill --install` | Install the agent skill |
63
+ | `wtc mcp` | Start the MCP server on stdio |
485
64
 
486
- ```
487
- wtc promote <worktree> [--force]
488
- ```
489
-
490
- Copies a worktree's changes into the checkout you run it from (usually main) as uncommitted changes: everything it changed since it branched — committed, staged, unstaged, and untracked — with deleted files deleted and renames applied as delete + add. Compose files and local env files (`.env`, `.env.development`, … — committed templates like `.env.example` still promote) are skipped, because `wtc` rewrites them per worktree. Symlinks are copied as symlinks; directories such as submodules are skipped with a warning. Works without Docker.
491
-
492
- It refuses, before writing anything:
65
+ `start`, `stop` and `restart` take worktrees by index, branch, directory name, path, or `.` for the one you're in. None means all.
493
66
 
494
- - **conflicts** — a file it would touch has uncommitted or untracked changes in the target (unless the target already has identical content). Commit or stash first.
495
- - **reverts** — a file it would touch was also changed (committed) on the target branch since the worktree branched. Promote copies whole files, so this would silently undo those commits. Merge the target branch into the worktree first (the error prints the command), or pass `--force` to overwrite them anyway.
496
- - **unsafe paths** — a path that escapes the repository or passes through a symlinked directory on either side.
497
- - promoting a worktree into itself.
498
-
499
- ### `wtc clean`
500
-
501
- ```
502
- wtc clean [--dry-run] [--force] [--keep-worktrees] [--sweep]
503
- ```
67
+ ## How it works
504
68
 
505
- Ends the session for every worktree:
69
+ - **Ports.** Every worktree has an index, and its host ports move by it: `20000 + port + index`. A backend on `8000` is on `28001` in worktree 1 and `28002` in worktree 2.
70
+ - **Isolation.** Each worktree's stack is its own compose project, like `myapp-wt-1-feature`, so containers, networks and volumes are never shared.
71
+ - **Your compose file stays as it is.** A port written as `${BACKEND_PORT:-8000}:8000` gets the worktree's value from its env file. Hardcoded ports and `container_name` are remapped at runtime by an override `wtc` generates (Docker Compose 2.24.4 or newer).
72
+ - **Env files.** Every start copies the env file fresh from main and writes in the worktree's ports and `COMPOSE_PROJECT_NAME`. With the default `.env`, plain `docker compose` commands run in the worktree reach its stack.
73
+ - **Stable.** A worktree keeps its index and ports. Removing one never renumbers the others.
506
74
 
507
- 1. **Tears down every stack `wtc` knows** — all live worktrees and all orphans — with `compose down -v --remove-orphans`. **This deletes their volumes**, including the stacks of worktrees that step 2 keeps and with `--keep-worktrees`. To stop everything but keep the data, use `wtc stop`.
508
- 2. **Removes worktrees that hold no work of their own** (skipped entirely with `--keep-worktrees`). Never removed: the main checkout and the worktree you run `clean` from. Kept unless you pass `--force`:
509
- - uncommitted changes, tracked or untracked — other than the files `wtc` itself wrote there (the env files it injects, and compose/Dockerfile/`sync` copies that still match main);
510
- - a detached HEAD with commits no branch, tag, or remote contains;
511
- - submodules with commits not pushed to any remote;
512
- - locked worktrees.
75
+ ## Configuration
513
76
 
514
- Each kept worktree is listed with the reason.
515
- 3. **Sweeps leftover containers, networks, and volumes, one at a time — only of stacks this checkout owns:** projects in its registry, or `<repo>-wt-<n>-…` projects whose containers ran from the main checkout, one of its worktrees, or a recorded worktree path. Stacks that are merely *named* like this repo's (another clone with the same directory name) are listed and never removed. Ownership is judged from containers: volumes and networks of a project with **no container left** carry no working directory, so they are listed, never removed — see [leftovers](#troubleshooting).
516
- 4. Runs `git worktree prune`, and forgets the records of removed worktrees and torn-down orphans. Worktrees that stay keep their index.
517
-
518
- | Flag | |
519
- |------|-|
520
- | `--dry-run` | Print exactly what would be stopped, removed, and swept; change nothing (not even `wtc`'s registry) |
521
- | `--force` | Also remove worktrees with uncommitted changes, unreachable commits, unpushed submodule commits, and locked ones |
522
- | `--keep-worktrees` | Tear down the stacks (deleting their volumes), keep every worktree |
523
- | `--sweep` | Also remove `<repo>-wt-<n>-…` stacks whose working directory no longer exists — e.g. left behind by wtc 0.2 — judged from their containers: volumes or networks with no container left are listed, never removed. Never a stack whose directory exists |
524
-
525
- ### `wtc prune`
526
-
527
- ```
528
- wtc prune [--dry-run]
529
- ```
530
-
531
- Tears down (`compose down -v --remove-orphans`, deleting volumes) and forgets **orphans only**: stacks of worktrees you deleted with `git worktree remove` or `rm -rf`. Live worktrees are not touched — nor is any worktree git still lists, such as a locked one on an unmounted drive; each orphan is re-checked right before teardown. Also runs `git worktree prune` when git still lists worktrees whose directory is gone.
532
-
533
- ### `wtc doctor`
534
-
535
- ```
536
- wtc doctor [--json]
537
- ```
538
-
539
- A ✔ / ⚠ / ✖ checklist with hints: git version; repository and main-checkout detection; compose file found and parsed (services, included files); config parsed (`.wtcrc.json` or `package.json#wtc`); compose engine and version (when it doesn't work, whether `WTC_COMPOSE_COMMAND`, `composeCommand`, or auto-detection chose it); daemon reachable; isolatable ports, including hardcoded ones [remapped at runtime](#runtime-remapping) (or why they can't be); [isolation warnings](#settings-that-break-isolation); cross-worktree port collisions; missing worktrees; orphaned stacks; each worktree's stack state; and allocated ports already taken by something else for worktrees whose stack isn't running. Read-only. Exits 1 if any check fails.
540
-
541
- ### `wtc skill`
542
-
543
- ```
544
- wtc skill [--install] [--dir <path>]
545
- ```
546
-
547
- Prints the bundled [agent skill](#agent-skill). `--install` writes it to `~/.claude/skills/worktree-compose/SKILL.md`; `--dir <path>` installs it to `<path>/worktree-compose/SKILL.md` instead.
548
-
549
- ### `wtc mcp`
550
-
551
- Starts the [MCP server](#mcp-server) on stdio.
552
-
553
- ### What each command does to your data
554
-
555
- | Command | Containers | Volumes (your data) | Worktrees |
556
- |---------|-----------|---------------------|-----------|
557
- | `wtc stop` | stopped, kept | kept | kept |
558
- | `wtc restart` | stopped, then started; changed services recreated | kept | kept |
559
- | `wtc prune` | removed (deleted worktrees' stacks only) | **deleted** (those stacks only) | — |
560
- | `wtc clean` | removed (every stack) | **deleted** (every stack) | removed unless they hold work; never main or the current one |
561
- | `wtc clean --keep-worktrees` | removed (every stack) | **deleted** (every stack) | kept |
562
-
563
- Exit codes: any error exits 1. `stop`, `clean`, and `prune` also exit 1 when a stack, removal, or sweep failed (worktrees kept on purpose don't count); `doctor` exits 1 when a check fails.
564
-
565
- ## Configuration (Optional)
566
-
567
- `wtc` works zero-config. For project-specific needs, create `.wtcrc.json` at the root of the main checkout:
77
+ None is needed. When an env value has a port inside it, like a `DATABASE_URL`, add it to `.wtcrc.json` and each worktree gets its own port in it:
568
78
 
569
79
  ```json
570
80
  {
571
81
  "$schema": "https://unpkg.com/worktree-compose/wtc.schema.json",
572
- "sync": [".generated/prisma-client", "local-certs/"],
573
- "envFile": ".env.development",
574
- "workspaces": ["server", "homepage"],
575
82
  "envOverrides": {
576
- "VITE_API_URL": "http://localhost:${BACKEND_PORT}"
577
- },
578
- "workspaceEnvOverrides": {
579
- "server": {
580
- "DATABASE_URL": "postgresql://postgres:postgres@localhost:${POSTGRES_PORT}/postgres"
581
- }
582
- },
583
- "portStride": 100,
584
- "composeCommand": "podman compose"
585
- }
586
- ```
587
-
588
- Or use a `"wtc"` key in `package.json`. (`.wtcrc.json` takes precedence.) The `$schema` line gives editors completion and validation for every key; `wtc` ignores it.
589
-
590
- ### `sync`
591
-
592
- Extra files/directories to copy from main into each worktree on start. Use for gitignored or generated files that Docker needs but aren't committed — like generated clients, local certificates, or build artifacts. Paths are repo-relative; entries that are absolute or leave the repository are skipped with a warning.
593
-
594
- ### `envFile`
595
-
596
- Env filename to copy from main and inject overrides into, for the root and every selected workspace. Defaults to `.env`. Must be a bare filename. Per-run override: `--env`.
597
-
598
- ### `workspaces`
599
-
600
- Monorepo workspaces that also get their env file copied and injected, in addition to the root. Accepts package names, directory names, or repo-relative paths. Omitted → root only. Per-run override: `--workspace`. See [Monorepos & custom env files](#monorepos--custom-env-files).
601
-
602
- ### `envOverrides`
603
-
604
- Additional env vars injected into the **root** env file. Values interpolate `${VAR}` with the allocated port variables and `${COMPOSE_PROJECT_NAME}`. Existing keys are rewritten in place; new keys are appended in the override block.
605
-
606
- ### `workspaceEnvOverrides`
607
-
608
- Per-workspace overrides, keyed by workspace package name (a unique directory name or the repo-relative path also work). Applied only to that workspace's env file, with the same interpolation and in-place rewrite behavior as `envOverrides`.
609
-
610
- ### `portStride`
611
-
612
- Port spacing between consecutive worktree indices (default `1`, must be a positive integer). Allocated port = `20000 + default_port + worktree_index × portStride`. Raise it (e.g. `100`) when your project exposes clustered default ports that would otherwise collide across worktrees — see [Port Allocation](#port-allocation). `wtc` warns and recommends a value when it detects a collision.
613
-
614
- ### `composeCommand`
615
-
616
- Which compose tool to use instead of auto-detection: exactly one of `"docker compose"`, `"podman compose"`, `"docker-compose"`, or `"podman-compose"` (a string, or an array such as `["podman", "compose"]`). Repository config is limited to these four so a cloned repository can't make `wtc` run an arbitrary program; anything custom goes in the `WTC_COMPOSE_COMMAND` environment variable, which takes precedence. See [Docker, Podman, OrbStack, Colima](#docker-podman-orbstack-colima).
617
-
618
- ## Docker, Podman, OrbStack, Colima
619
-
620
- `wtc` picks the compose command in this order:
621
-
622
- 1. **`WTC_COMPOSE_COMMAND`** environment variable — any command, split on whitespace: `WTC_COMPOSE_COMMAND="podman compose"`, an absolute path, or global flags such as `WTC_COMPOSE_COMMAND="docker --context colima compose"`.
623
- 2. **`composeCommand`** in `.wtcrc.json` / `package.json#wtc` — one of the four standard commands below.
624
- 3. **Auto-detection**, in order: `docker compose` (Compose v2) → `podman compose` → `docker-compose` (standalone, including legacy v1) → `podman-compose`. When more than one is installed, the first whose daemon answers wins, so a quit Docker Desktop doesn't shadow a running Podman machine.
625
-
626
- | Engine | How |
627
- |--------|-----|
628
- | Docker Desktop / Docker Engine | `docker compose` (auto-detected) |
629
- | OrbStack, Colima | through the `docker` CLI and its current context (auto-detected); for another context, `WTC_COMPOSE_COMMAND="docker --context <name> compose"` |
630
- | Podman | `podman compose` or `podman-compose` (auto-detected); on macOS and Windows, start its VM with `podman machine start` |
631
- | Anything else (e.g. `nerdctl compose`) | `WTC_COMPOSE_COMMAND` |
632
-
633
- Status checks, teardown, and cleanup use the same CLI and global flags as compose, so they always talk to the same daemon. `wtc doctor` shows which engine was picked and its version, and whether its daemon is reachable. `wtc promote` doesn't need an engine at all.
634
-
635
- ## MCP Server
636
-
637
- Built-in [MCP](https://modelcontextprotocol.io/) server, so AI agents can manage their stacks themselves. It works on the git repository of the directory it starts in — your agent's project. The setups below use the global install.
638
-
639
- ### Setup
640
-
641
- **Claude Code** — for every project:
642
-
643
- ```bash
644
- claude mcp add --scope user wtc -- wtc mcp
645
- ```
646
-
647
- (Without `--scope user`, Claude Code registers it for the current project only.) Or share it with your team through a project `.mcp.json`:
648
-
649
- ```json
650
- {
651
- "mcpServers": {
652
- "wtc": { "command": "wtc", "args": ["mcp"] }
83
+ "DATABASE_URL": "postgresql://app:app@localhost:${POSTGRES_PORT}/app"
653
84
  }
654
85
  }
655
86
  ```
656
87
 
657
- **Codex** — `~/.codex/config.toml`:
658
-
659
- ```toml
660
- [mcp_servers.wtc]
661
- command = "wtc"
662
- args = ["mcp"]
663
- ```
664
-
665
- **Cursor** — `.cursor/mcp.json`, with the same JSON as `.mcp.json` above.
666
-
667
- **Without a global install**, use `npx` with the package name (never `npx wtc`):
88
+ The same file sets extra files to sync, a custom env file, monorepo workspaces, port spacing and the compose command. See [configuration](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md#configuration-optional) and [monorepos](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md#monorepos--custom-env-files).
668
89
 
669
- ```json
670
- { "command": "npx", "args": ["-y", "worktree-compose", "mcp"] }
671
- ```
90
+ ## For AI agents
672
91
 
673
- After upgrading `wtc`, restart your MCP client so it runs the new version.
674
-
675
- ### Tools
676
-
677
- | Tool | Parameters | What it does | Safety |
678
- |------|-----------|--------------|--------|
679
- | `wtc_start` | `indices?: (number \| string)[]`, `envFile?: string`, `workspaces?: string[]`, `build?: boolean` (default `true`) | Same as `wtc start` | not destructive |
680
- | `wtc_stop` | `indices?: (number \| string)[]` | Same as `wtc stop` (`compose stop`) | not destructive: containers and volumes are kept |
681
- | `wtc_restart` | same as `wtc_start` | Same as `wtc restart` | not destructive |
682
- | `wtc_list` | — | First content item is the JSON array of `wtc list --json`; warnings follow as separate items | read-only: never writes the registry |
683
- | `wtc_promote` | `index: number \| string`, `force?: boolean` | Same as `wtc promote`, into the checkout the server runs in | **destructive**: overwrites and deletes files there |
684
- | `wtc_clean` | `force?`, `keepWorktrees?`, `dryRun?`, `sweep?` (all `boolean`) | Same as `wtc clean` | **destructive**: deletes volumes, removes worktrees |
685
- | `wtc_prune` | `dryRun?: boolean` | Same as `wtc prune` | **destructive**: deletes removed worktrees' volumes |
686
- | `wtc_doctor` | — | Same checks as `wtc doctor`, as JSON | read-only |
687
-
688
- `indices` / `index` take [selectors](#selecting-worktrees): a JSON number is always an index; a string can be an index, branch, directory name, path, or `.`. Omit `indices` for all worktrees.
689
-
690
- - Tools that change stacks or files (start, stop, restart, promote, clean, prune) run one at a time, so a client retry can't launch a second `compose up` for the same stack.
691
- - Cancelling a request stops the compose command it started; a request cancelled while it waits its turn does not run at all. Requests with a `progressToken` get progress notifications while compose runs.
692
- - Every tool returns its progress lines. Failures come back as `isError: true` with the reason (including the tail of compose's error output) — also when a teardown or removal inside `wtc_stop`, `wtc_clean`, or `wtc_prune` failed.
693
- - Tool annotations mark `wtc_list` and `wtc_doctor` read-only and `wtc_promote`, `wtc_clean`, and `wtc_prune` destructive, so clients can ask before running them.
694
- - stdout carries only JSON-RPC; all logging goes to stderr.
695
-
696
- ## Agent Skill
697
-
698
- `wtc` ships an [agent skill](https://docs.claude.com/en/docs/claude-code/skills) ([`SKILL.md`](https://github.com/mostafasudo/worktree-compose/blob/main/SKILL.md)) that teaches AI coding agents the worktree workflow: commands and selectors, stop vs. clean, ports, env files, config, and the MCP tools. Install the copy that matches your installed version:
699
-
700
- ```bash
701
- wtc skill --install # ~/.claude/skills/worktree-compose/SKILL.md
702
- wtc skill --dir ~/my-agent/skills # <dir>/worktree-compose/SKILL.md
703
- wtc skill # print it
704
- ```
705
-
706
- Re-run `wtc skill --install` after upgrading `wtc`.
707
-
708
- ## Full Example
92
+ `wtc` has a built-in [MCP](https://modelcontextprotocol.io) server, so coding agents can start, list and clean up their own stacks. In Claude Code:
709
93
 
710
94
  ```bash
711
- cd myapp
712
- npm install -g worktree-compose
713
-
714
- git worktree add -b agent-1-auth ../myapp-agent-1
715
- git worktree add -b agent-2-auth ../myapp-agent-2
716
-
717
- wtc start
718
- # Worktree 1: BACKEND_PORT=28001 FRONTEND_PORT=25174
719
- # Worktree 2: BACKEND_PORT=28002 FRONTEND_PORT=25175
720
-
721
- # Compare side by side
722
- # http://localhost:25174 (agent 1)
723
- # http://localhost:25175 (agent 2)
724
-
725
- wtc promote agent-1-auth
726
- git add -A && git commit -m "feat: auth from agent 1"
727
-
728
- wtc clean --dry-run # preview
729
- wtc clean # worktrees with uncommitted work are kept; --force discards them
95
+ claude mcp add --scope user wtc -- wtc mcp
730
96
  ```
731
97
 
732
- ## Upgrading from 0.2
98
+ [Setup for Codex, Cursor and other clients](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md#setup). The server is listed in the official [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.mostafasudo/worktree-compose` and on [Glama](https://glama.ai/mcp/servers/mostafasudo/worktree-compose).
733
99
 
734
- 1.0 changes a few behaviors; the [changelog](https://github.com/mostafasudo/worktree-compose/blob/main/CHANGELOG.md#upgrading-from-02) has the full list.
735
-
736
- - **Node.js 20+.**
737
- - **Install globally and type `wtc`** — without an install, `npx wtc` runs an unrelated package. Update MCP configs to `"command": "wtc", "args": ["mcp"]`.
738
- - **Indices are stable.** Your existing stacks keep their names on the first run; after that, removing a worktree never shifts the others. Deleted worktrees show as `(removed)` until `wtc prune`.
739
- - **`wtc stop` keeps containers** (`compose stop` instead of `down`); `start` resumes them. Only `clean` and `prune` remove stacks and volumes.
740
- - **`wtc clean` keeps worktrees that hold work** (uncommitted changes, unreachable commits, unpushed submodule commits, locked) unless you pass `--force`, and only removes Docker resources of stacks it owns. Stale 0.2 stacks that still have containers: `wtc clean --sweep`. 0.2's `wtc stop` kept named volumes, so a worktree deleted after `wtc stop` can leave volumes with no container; `wtc clean` lists those but never removes them. Find them with `docker volume ls --filter label=com.docker.compose.project=<project>` and remove them with `docker volume rm`.
741
- - **Env keys are rewritten in place**, and the root env file now gets `COMPOSE_PROJECT_NAME`.
742
- - **`wtc promote`** also aborts when the target branch changed the same files since the worktree branched (`--force` overrides), and untracked files in the target now count as conflicts.
100
+ To teach an agent the workflow, install the [agent skill](https://github.com/mostafasudo/worktree-compose/blob/main/SKILL.md) with `wtc skill --install`.
743
101
 
744
102
  ## Requirements
745
103
 
746
- - **Node.js** >= 20
747
- - **Git** 2.17 or newer, with worktree support (2.31+ recommended)
748
- - **Docker** with Compose v2 (`docker compose`), or **Podman** (`podman compose` / `podman-compose`) — see [engines](#docker-podman-orbstack-colima)
749
- - Docker Compose 2.24.4 or newer to [remap hardcoded host ports and `container_name`](#runtime-remapping); with older engines, write host ports as `${VAR:-default}`
750
-
751
- ## Troubleshooting
752
-
753
- Start with **`wtc doctor`**: it checks the engine, the daemon, ports, isolation settings, missing worktrees, and orphaned stacks, and says what to do.
754
-
755
- **`npx wtc` does something unexpected** — when worktree-compose isn't installed, it downloads and runs an unrelated npm package named `wtc`. Install globally (`npm install -g worktree-compose`) and type `wtc`, or use `npx worktree-compose <command>`.
756
-
757
- **"No compose file found"** — `wtc` reads the compose file from the root of the main checkout, not the current directory: `compose.yaml`, `compose.yml`, `docker-compose.yaml`, or `docker-compose.yml`.
758
-
759
- **"No extra worktrees found"** — Create worktrees first: `git worktree add -b my-branch ../my-feature`
760
-
761
- **Ports not changing** — `wtc doctor` lists which ports are isolated, and whether hardcoded ones are remapped at runtime or why not (it needs Docker Compose 2.24.4+). Otherwise write host ports as `${VAR:-default}`, with an upper-case variable. A plain `docker compose up` run from a subdirectory of the worktree ignores `COMPOSE_FILE` in `.env` and publishes the hardcoded ports; run it from the worktree's root, or use `wtc restart .`.
762
-
763
- **"Bind for 0.0.0.0:25435 failed: port is already allocated"** — Something else listens on that port. `wtc doctor` reports allocated ports that are already taken; stop the other process, or raise `portStride`. If you run `docker compose` yourself with a custom `envFile`, pass `--env-file <envFile>` (Compose only reads `.env` on its own) or export the port (e.g. `POSTGRES_PORT=25435 docker compose up`).
764
-
765
- **A stack shows as `(removed)`** — its worktree was deleted but its stack or record remains. `wtc prune` tears it down (and frees its index); preview with `wtc prune --dry-run`.
766
-
767
- **Leftover containers, networks, or volumes** — `wtc clean --dry-run` shows what `wtc clean` would remove. Leftovers of stacks whose worktree directory no longer exists (e.g. from wtc 0.2) are listed, and removed with `wtc clean --sweep` as long as the stack still has a container (that is where the working directory is recorded). Volumes or networks with no container left, and resources merely *named* like this repo's stacks, are listed and never removed by `wtc`. Inspect one project exactly before removing anything yourself: `docker ps -a --filter label=com.docker.compose.project=<project>` shows nothing for volume-only leftovers, so also run `docker volume ls --filter label=com.docker.compose.project=<project>` and `docker network ls --filter label=com.docker.compose.project=<project>`.
768
-
769
- **"Refusing to start worktree stacks: cannot locate the main checkout"** (also `restart`, `clean`) — the repository layout doesn't say which checkout is the main one (see [repository layouts](#repository-layouts)). In a bare repository, check the default branch out in your main worktree again (finish the rebase or bisect), or add a worktree for it; with `--separate-git-dir`, run it from the main checkout (after one `wtc start` there, linked worktrees find it too).
770
-
771
- **`wtc clean` kept a worktree** — it prints why (uncommitted changes, unreachable commits, unpushed submodule commits, locked, or the worktree you're in). Commit or push the work, or pass `--force` to discard it.
772
-
773
- **"Timed out waiting for the wtc state lock"** — another `wtc` command (or MCP call) is updating `.git/wtc/state.json`; retry when it finishes. If no `wtc` process is running at all, delete the lock file the message names.
104
+ Node.js 20+, Git 2.17+, and Docker Compose v2 or Podman. OrbStack and Colima work through the `docker` CLI.
774
105
 
775
- **"…was written by a newer wtc (state version N); upgrade wtc."** — an older `wtc` (often an MCP server started by a cached install) met a registry written by a newer one. Upgrade it (`npm install -g worktree-compose@latest`) and restart your MCP client. The older version leaves the file untouched.
106
+ ## Docs
776
107
 
777
- **Wrong engine, or the daemon is down** — `wtc doctor` shows which engine was picked and whether its daemon answers. Start the daemon, or set `WTC_COMPOSE_COMMAND` (e.g. `"podman compose"`).
108
+ The [full documentation](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md) has every command and flag, [how ports, env files and remapping work](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md#how-it-works), [engines](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md#docker-podman-orbstack-colima), [troubleshooting](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md#troubleshooting) and [upgrading from 0.2](https://github.com/mostafasudo/worktree-compose/blob/main/docs/README.md#upgrading-from-02).
778
109
 
779
110
  ## Contributing
780
111
 
781
- Issues and pull requests are welcome. Found a bug or have an idea? [Open an issue](https://github.com/mostafasudo/worktree-compose/issues) — and if `wtc` saves you time, a ⭐ on the [repo](https://github.com/mostafasudo/worktree-compose) helps others find it. Docs and demos live at [worktree-compose.com](https://www.worktree-compose.com).
112
+ Issues and pull requests are welcome. [Open an issue](https://github.com/mostafasudo/worktree-compose/issues) for a bug or an idea, and if `wtc` saves you time, a ⭐ helps others find it.
782
113
 
783
114
  ## License
784
115
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktree-compose",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Zero-config Docker Compose isolation for git worktrees",
5
5
  "mcpName": "io.github.mostafasudo/worktree-compose",
6
6
  "type": "module",
@@ -32,7 +32,14 @@
32
32
  "parallel",
33
33
  "development",
34
34
  "mcp",
35
- "podman"
35
+ "podman",
36
+ "git-worktree",
37
+ "docker-compose",
38
+ "ai-agents",
39
+ "coding-agents",
40
+ "claude-code",
41
+ "mcp-server",
42
+ "dev-environment"
36
43
  ],
37
44
  "repository": {
38
45
  "type": "git",