
worktree-compose
io.github.mostafasudo/worktree-compose
An isolated Docker Compose stack per git worktree: start, stop, list, promote and clean them.
Documentation
worktree-compose · wtc
Zero-config Docker Compose isolation for git worktrees
Every worktree gets its own ports, database, cache, and containers.
Website · Docs · Changelog · Agent skill
Put several AI agents or developers on one repo, each in its own 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.
Install
npm install -g worktree-compose
Type
wtc, nevernpx wtc: an unrelated npm package has that name. To run it without installing, usenpx worktree-compose <command>.
Quick start
git worktree add -b feature ../myapp-feature
cd ../myapp-feature
wtc start . # build and start this worktree's stack on its own ports
wtc list # every stack with its status, URL and ports
When the work is done:
wtc promote feature # copy its changes into your checkout, uncommitted
wtc clean # tear down every stack (deletes their volumes), remove worktrees that hold no work
Commands
| Command | What it does |
|---|---|
wtc start | Sync compose files and Dockerfiles from main, write the worktree's ports into its env file, compose up -d --build |
wtc stop | Stop the containers. Data is kept and start resumes them |
wtc restart | Re-sync, then recreate what changed |
wtc list | Status, URL and ports of every stack (--json for scripts) |
wtc promote <worktree> | Copy a worktree's changes into the current checkout, uncommitted |
wtc prune | Tear down the stacks of worktrees you deleted (deletes their volumes) |
wtc clean | Tear down every stack (deletes their volumes) and remove worktrees that hold no work. Preview with --dry-run |
wtc doctor | Check git, the engine, ports and isolation, and say what to fix |
wtc skill --install | Install the agent skill |
wtc mcp | Start the MCP server on stdio |
start, stop and restart take worktrees by index, branch, directory name, path, or . for the one you're in. None means all.
How it works
- Ports. Every worktree has an index, and its host ports move by it:
20000 + port + index. A backend on8000is on28001in worktree 1 and28002in worktree 2. - Isolation. Each worktree's stack is its own compose project, like
myapp-wt-1-feature, so containers, networks and volumes are never shared. - Your compose file stays as it is. A port written as
${BACKEND_PORT:-8000}:8000gets the worktree's value from its env file. Hardcoded ports andcontainer_nameare remapped at runtime by an overridewtcgenerates (Docker Compose 2.24.4 or newer). - 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, plaindocker composecommands run in the worktree reach its stack. - Stable. A worktree keeps its index and ports. Removing one never renumbers the others.
Configuration
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:
{
"$schema": "https://unpkg.com/worktree-compose/wtc.schema.json",
"envOverrides": {
"DATABASE_URL": "postgresql://app:app@localhost:${POSTGRES_PORT}/app"
}
}
The same file sets extra files to sync, a custom env file, monorepo workspaces, port spacing and the compose command. See configuration and monorepos.
For AI agents
wtc has a built-in MCP server, so coding agents can start, list and clean up their own stacks. In Claude Code:
claude mcp add --scope user wtc -- wtc mcp
Setup for Codex, Cursor and other clients. The server is listed in the official MCP Registry as io.github.mostafasudo/worktree-compose and on Glama.
To teach an agent the workflow, install the agent skill with wtc skill --install.
Requirements
Node.js 20+, Git 2.17+, and Docker Compose v2 or Podman. OrbStack and Colima work through the docker CLI.
Docs
The full documentation has every command and flag, how ports, env files and remapping work, engines, troubleshooting and upgrading from 0.2.
Contributing
Issues and pull requests are welcome. Open an issue for a bug or an idea, and if wtc saves you time, a ⭐ helps others find it.
License
worktree-composenpm install worktree-compose