Run 5 coding agents in parallel. Zero port clashes. Zero shared databases. No containers.
Renamed from
nocollide; the npm package is stillnocollide. Oldnocollide.jsonfiles, hooks and env files keep working;slotenv doctortells you what to rename.
Status: v0.3 handles ports,
.envfiles, Postgres, MySQL, SQLite, Redis and Docker Compose, and can set up new worktrees by itself through a git hook.
npx nocollide initOr install it once with npm install -g nocollide; that gives you the slotenv command (nocollide works too). The npm package keeps its first name because npm reserves slotenv for being close to dotenv. Requires Node.js 22 or newer and git 2.31 or newer. Works on macOS, Linux and Windows.
Git worktrees give every agent its own copy of the files. They do not give it its own runtime:
- Agent A runs
npm run devon port 3000. Agent B runs it too:EADDRINUSE. - Both agents run migrations against the same
app_devdatabase and break each other's tests. .envis not copied into new worktrees, so the agent starts without settings, or with the wrong ones.- Docker Compose project names collide, and one agent's
docker compose downkills the other's services.
Container-per-agent tools solve this, but they are heavy, slow to start, and replace your whole dev setup. slotenv is the thin layer in between.
Each worktree gets a slot number. Everything else is derived from it.
main worktree slot 0 WEB_PORT=3000 db app_dev redis /0 compose shop
../feat-login slot 1 WEB_PORT=3010 db app_dev_s1 redis /1 compose shop-s1
../fix-cart slot 2 WEB_PORT=3020 db app_dev_s2 redis /2 compose shop-s2
- The main worktree always keeps slot 0, so your normal setup does not change.
- Other worktrees get the lowest free slot. A slot is skipped when one of its ports is already in use.
- Slot numbers are unique across all your repositories, so two projects with the same ports or database names never collide.
- Slots live in
~/.slotenv/slots.jsonbehind a lock, so ten agents runningupat the same moment still get ten different slots. git worktree movekeeps the slot and its databases.
slotenv init # once per repository: writes slotenv.json
slotenv hook install # once per clone: new worktrees run "slotenv up" by themselves
slotenv up # in a worktree: claims a slot and writes .env.local
slotenv run -- npm run dev # runs a command with the slot variables set
slotenv env # prints the slot variables (--shell sh|powershell|cmd, --json)
slotenv port WEB_PORT # prints one port, handy in scripts
slotenv ls # every slot of this repository (--json for tools)
slotenv down # releases the slot, drops its databases, removes .env.local
slotenv gc # the same for worktrees that were deleted
slotenv doctor # checks the setup and says what to fixinit reads ports from .env.example (WEB_PORT=3000) and from package.json scripts (--port 3000, -p 3000, PORT=3000), falls back to the framework default (Vite 5173, Next.js 3000, Astro 4321, Angular 4200, Django 8000, Flask 5000, Rails 3000), finds database URLs in .env.example, notices a Compose file, and writes:
{
"ports": { "WEB_PORT": 3000, "API_PORT": 4000 },
"step": 10,
"env": { "from": ".env.example", "to": ".env.local" },
"databases": {
"DATABASE_URL": { "kind": "postgres", "url": "postgres://postgres:postgres@localhost:5432/app_dev" },
"REDIS_URL": { "kind": "redis", "url": "redis://localhost:6379/0" }
},
"compose": true
}Ports of shared services such as DB_PORT=5432 or REDIS_PORT=6379 are left out, because every slot should keep talking to the same server. With a Compose file they are kept, because each slot then runs its own containers.
Commit slotenv.json. Until you do, new worktrees fall back to the copy in the main worktree.
up copies env.from to env.to, sets every port variable and SLOTENV_SLOT, and fills ${...} placeholders:
DATABASE_URL=postgres://localhost/app_s${SLOTENV_SLOT}
PUBLIC_URL=http://localhost:${WEB_PORT}slotenv never overwrites an env file it did not write. Move your own values into the template, or pass --force. run, env and port never write the env file, so they also work next to a hand-written .env.local.
Each entry in databases is an env variable. Slot 0 keeps the value as written; every other slot gets its own database:
| kind | slot 2 gets | on up |
on down |
|---|---|---|---|
postgres |
app_dev_s2 |
created with CREATE DATABASE ... TEMPLATE app_dev, so schema and seed data come along |
dropped |
mysql |
app_dev_s2 |
created and filled with mysqldump app_dev | mysql app_dev_s2 |
dropped |
sqlite |
its own copy of path inside the worktree |
copied from the main worktree if missing | kept with the worktree |
redis |
DB index base + 2 |
nothing to create | nothing to drop |
- Postgres uses the
psqlclient and MySQL usesmysqlandmysqldump; they must be on yourPATH.mysql://andmariadb://URLs both work. Set"template": falseto start each slot with an empty database instead. - Copying a template needs nobody connected to it. If the main dev server is running, slotenv tells you to stop it or to use
"template": false. down --keep-dataandgc --keep-datakeep the databases. slotenv only drops databases it created itself; a database that already existed is used as it is and left alone.- If a drop fails, the slot stays claimed so
slotenv downcan be run again. - Passwords are passed to
psqlandmysqlthroughPGPASSWORDandMYSQL_PWD, never on the command line, and are hidden in every message.
With "compose": true, every slot gets COMPOSE_PROJECT_NAME (shop, shop-s1, shop-s2, ...), so containers, networks and volumes stay apart and docker compose down in one worktree leaves the others alone. Run Compose through slotenv so it sees the slot ports too:
slotenv run -- docker compose upMost frameworks read PORT or a variable you pass in config. If a script hard-codes a port, either make it read the variable, or start it through slotenv:
slotenv run -- npm run devslotenv hook installThis adds a git post-checkout hook, so git worktree add (and every tool built on it) claims a slot and writes .env.local before the agent even starts. An existing hook is kept: slotenv adds a marked block and slotenv hook uninstall removes only that block. core.hooksPath is respected, and with Husky v9 the hook goes into .husky/post-checkout.
eval "$(slotenv env)" # bash, zsh
slotenv env --shell powershell | Invoke-Expression # PowerShellAdd one line to AGENTS.md or your agent's instructions file:
Before starting a dev server or tests in a worktree, run `npx nocollide up` and use the ports and database URLs in .env.local.
Orchestrators can read slotenv ls --json and slotenv env --json instead of parsing text.
- Not a worktree manager. Keep using
git worktree, or your favourite wrapper. - Not a sandbox. Agents still share your machine; use containers if you need security isolation.
See ROADMAP.md.
MIT
