Repository avatar
Version Control
v1.1.2
active

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 logo

worktree-compose · wtc

Zero-config Docker Compose isolation for git worktrees

Every worktree gets its own ports, database, cache, and containers.

npm version downloads license DevHunt Glama MCP server

Website · Docs · Changelog · Agent skill

worktree-compose demo: isolated Docker stacks per git worktree

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, never npx wtc: an unrelated npm package has that name. To run it without installing, use npx 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

CommandWhat it does
wtc startSync compose files and Dockerfiles from main, write the worktree's ports into its env file, compose up -d --build
wtc stopStop the containers. Data is kept and start resumes them
wtc restartRe-sync, then recreate what changed
wtc listStatus, URL and ports of every stack (--json for scripts)
wtc promote <worktree>Copy a worktree's changes into the current checkout, uncommitted
wtc pruneTear down the stacks of worktrees you deleted (deletes their volumes)
wtc cleanTear down every stack (deletes their volumes) and remove worktrees that hold no work. Preview with --dry-run
wtc doctorCheck git, the engine, ports and isolation, and say what to fix
wtc skill --installInstall the agent skill
wtc mcpStart 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 on 8000 is on 28001 in worktree 1 and 28002 in 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}: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).
  • 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.
  • 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

MIT

NPM
worktree-compose
Install Command
npm install worktree-compose
Runtime: npx