/parallel-dev-preview:parallel-dev-setupfrom parallel-dev-preview
Sets up a monorepo for parallel agent development by assigning each git worktree deterministic ports, an isolated database, and a dev launcher — so multiple agents can run dev servers simultaneously with live-previewable URLs. This skill should be used when someone asks to "set up parallel development", "enable worktree port isolation", "preview multiple branches at once", "make dev servers work in parallel", "set up isolated dev environments", "fix port conflicts between agents", or "run multiple feature branches simultaneously".
Ships in parallel-dev-preview. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Enable multiple agents to develop features simultaneously in git worktrees, each with
its own dev server on unique ports, isolated database, and previewable URL. A reviewer
visits localhost:6300 for one feature and localhost:5820 for another — at the same time.
Before starting, verify the project has:
PORT, WEB_PORT)isolation: "worktree" creates these automatically)lsof for port detection and kill for process cleanupIdentify how each service reads its port. Use the Grep tool to search for port patterns:
pattern: "PORT|listen|port" in apps/*/src/main.*
pattern: "port|PORT" in apps/*/package.json
Map each service to its port env var and default:
| Service | Env Var | Default |
|---|---|---|
| web | WEB_PORT | 5100 |
| api | API_PORT | 5110 |
If services use hardcoded ports, refactor them to read from env vars first. If the web app proxies to APIs (e.g., Next.js rewrites, Vite proxy), verify those proxy targets also read from the same env vars.
Create scripts/lib/env-utils.mjs with reusable helpers. See references/env-utils-template.mjs
for a complete template. Key exports:
parseEnvFile(filePath) — parse .env files into key-value objects (handles comments, quotes)getMainRoot(cwd) — resolve the main repo root from inside a worktreekillPort(port) — kill processes on a port via lsofisPortListening(port) — check if a port is in useCreate scripts/setup-worktree-env.mjs. See references/setup-worktree-template.mjs.
.claude/worktrees/{any-name}/
(NOT just agent-{hex} — users create named worktrees like twilio, line-notif)agent-{hex} names use the hex directly; for arbitrary
names, derive a hex hash from the directory name:
// Support both agent-{hex} and arbitrary names
const worktreeMatch = cwd.match(/\.claude\/worktrees\/([^/]+)/);
const agentHexMatch = agentDir.match(/^agent-([a-f0-9]+)$/);
const agentHex = agentHexMatch
? agentHexMatch[1]
: Array.from(agentDir).reduce((h, c) => (((h << 5) - h) + c.charCodeAt(0)) >>> 0, 0)
.toString(16).padStart(8, '0');
const hexPrefix = parseInt(agentHex.slice(0, 4), 16);
const portOffset = ((hexPrefix % 199) + 1) * 10; // always >= 10, never 0
const webPort = BASE_WEB_PORT + portOffset;
myapp_agent_{shortId}).env.local — merge base env vars with worktree-specific overridesCreate scripts/dev.mjs. See references/dev-launcher-template.mjs.
node_modules/ missing (worktrees don't share them).env.local into process.env (critical — pnpm doesn't auto-load it)Accept an optional filter arg: node scripts/dev.mjs web for single-service mode.
Also create scripts/clear-dev-ports.mjs. See references/clear-dev-ports-template.mjs.
Create scripts/list-worktrees.mjs for reviewers. See references/list-worktrees-template.mjs.
.claude/worktrees/*/ directories.env.local for port assignmentslsof)Create scripts/teardown-worktree-env.mjs. See references/teardown-worktree-template.mjs.
Three modes:
.env.local--all — drop all agent databases--stale — find DBs whose worktree directories no longer exist, drop themUpdate the root package.json:
{
"scripts": {
"dev": "node scripts/dev.mjs",
"dev:web": "node scripts/dev.mjs web",
"dev:api": "node scripts/dev.mjs api",
"dev:ports": "node scripts/list-worktrees.mjs",
"dev:teardown": "node scripts/teardown-worktree-env.mjs",
"dev:teardown:stale": "node scripts/teardown-worktree-env.mjs --stale"
}
}
Add a "Worktree Port Isolation" section so agents know:
pnpm dev — everything auto-configurespnpm dev:ports shows all URLspnpm dev:teardown or pnpm dev:teardown:stale.env.local and .migration-stamp Are GitignoredUse a hash of the agent ID to compute ports. Same worktree always gets the same ports, so URLs are bookmarkable and stable across restarts.
Offset by multiples of 10 from the base port. This groups related services (e.g., web=5200, api=5210, worker=5201) and avoids collisions with the main repo defaults.
Hash all migration files and write to .migration-stamp. Skip re-running if unchanged.
Saves 3-8 seconds on every pnpm dev after the first run.
Git worktrees share git objects but NOT node_modules/. The dev launcher must detect
missing node_modules/ and run the package manager's install automatically.
isolation: "worktree" creates from HEAD of the default
branch. New uncommitted scripts won't exist in worktrees. Always commit scripts first.nohup ... &.outputFileTracingRoot — changes module resolution root, can break
dependency resolution in dev. Gate behind a DOCKER=1 env var..env.local — the dev launcher must explicitly parse and inject
env vars into process.env before spawning child processes.agent-{hex} regex — ALL three scripts (setup-worktree-env.mjs, dev.mjs,
AND teardown-worktree-env.mjs) need the generic worktree pattern. It's easy to fix one
and forget the others. The dev launcher uses isWorktree to gate migrations — if the regex
is wrong, migrations silently skip and the API crashes with missing tables. The teardown
script's --stale mode also needs the hash derivation to map directory names to DB short IDs..env.example file path values — setup-worktree-env.mjs merges .env.example into
worktree .env.local. If .env.example has file path values (e.g., SERVICE_ACCOUNT=./key.json),
worktrees will crash trying to read non-existent files. Comment out or leave empty any
file path env vars in .env.example. Services should use existsSync() before readFileSync().defaultMode: acceptEdits, background agents
get Bash denied. Workaround: create worktrees, install packages, and run verification from
the main session. Dispatch agents with mode: acceptEdits for code-only work.main doesn't propagate to worktree
branches. Use git cherry-pick {hash} in each worktree, or merge main into the branches.After implementation, verify:
pnpm dev in main repo prints default ports, works normallypnpm dev auto-generates .env.local with unique portspnpm dev:ports lists all worktrees with ports and ACTIVE statuspnpm dev:teardown cleans up completely (processes, DB, .env.local)pnpm dev:teardown:stale finds and removes orphaned databasesreferences/env-utils-template.mjs — Shared utility module templatereferences/dev-launcher-template.mjs — Dev launcher script templatereferences/setup-worktree-template.mjs — Worktree env setup templatereferences/clear-dev-ports-template.mjs — Port cleanup script templatereferences/list-worktrees-template.mjs — Port discovery script templatereferences/teardown-worktree-template.mjs — Full teardown script templatereferences/implementation-checklist.md — Step-by-step checklist for implementorsreferences/clear-dev-ports-template.mjs (opens in a new tab)references/dev-launcher-template.mjs (opens in a new tab)references/env-utils-template.mjs (opens in a new tab)references/implementation-checklist.md (opens in a new tab)references/list-worktrees-template.mjs (opens in a new tab)references/setup-worktree-template.mjs (opens in a new tab)references/teardown-worktree-template.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
Generated from the plugin's indexed repository (liamlin/claude-plugin-parallel-preview) — no native marketplace selected
npx claudepluginhub p/liamlin-parallel-dev-preview