Worktree Isolation & The 4 Real Pitfalls
Understand base ref vs start-from ref, Pinned worktrees, Force Delete & Preserved branches, plus concrete scripts.setup fixes for dependencies, .env files, port collisions, and shared DBs.
🎯 Goal
- Master Orca's worktree lifecycle:
base refvsstart-from ref, Pinned worktrees, Force Delete (plus Always force delete), and Preserved branches. - Eliminate the 4 real engineering pitfalls that
git worktreedoes NOT isolate automatically: missing dependencies, gitignored.envsecrets, localhost port collisions, and shared database / Docker volume pollution.
📋 Prerequisites
- At least one repository added to Orca with local dependencies (
package.json/pyproject.toml),.envconfig, or a local dev server. - Knowledge of your dev server's default port (e.g.,
:3000/:5173) and local database setup (SQLite / Postgres / Docker Compose).
Before editing your config, explore the interactive Workspace Simulator below—click across the 3 worktrees and open the Env & Ports tab to see how true workspace isolation looks across paths, .env.local, ports, and DB schemas:
🛠️ Step-by-Step
Core Worktree Model: Refs, Pinning & Safe Cleanup
Keep these four Orca primitives clear when juggling parallel branches:
| Primitive | Behavior | When to Use |
|---|---|---|
base ref | Repo-level baseline (defaults to origin/main) for diff targets and PR bases. | Change in repo settings if your main integration branch is master or develop. |
start-from ref | Per-worktree origin branch or commit selected when spawning a new worktree. | Stack work onto an unmerged feature branch, or launch 3 agents from the exact same commit hash. |
| Pinned worktrees | Keeps key worktrees anchored at the top of the sidebar. | Pin long-lived feature branches or a clean reference checkout so short-lived runs never bury them. |
| Force Delete & Preserved branches | Normal deletion warns on dirty files or unmerged work; Force Delete (and the arrow-menu Always force delete) removes the worktree directory cleanly. | Whenever a branch has local unmerged commits, Orca's Preserved branches safety guard keeps the local Git branch intact after deleting the worktree so committed work is never silently lost. |
Use Always Force Delete Intentionally
Enabling Always force delete from the delete button's arrow menu speeds up tearing down losing race branches—just remember untracked scratch files inside that worktree directory are removed immediately (only committed work is protected by Preserved branches).
Pitfall 1: Missing Dependencies (node_modules / .venv)
Why it happens: git worktree add checks out Git-tracked files only. Ignored directories like node_modules or .venv start completely absent, causing agents to fail immediately on npm test or vite.
Fix: Use pnpm (its content-addressable store hardlinks identical packages in seconds without duplicating gigabytes on disk), npm ci --prefer-offline, or uv sync --frozen, wired into scripts.setup inside orca.yaml:
scripts:
setup: |
if [ -f pnpm-lock.yaml ]; then
pnpm install --frozen-lockfile
elif [ -f package-lock.json ]; then
npm ci --prefer-offline
elif [ -f pyproject.toml ]; then
uv sync --frozen
fiPitfall 2: Missing Gitignored .env & Local Secret Files
Why it happens: .env, .env.local, and local dev certificates stay out of Git, leaving every fresh worktree without required runtime secrets.
Fix: Inside scripts.setup, copy .env* files from $ORCA_ROOT_PATH (your primary checkout) into the new worktree—never commit secrets to Git.
scripts:
setup: |
if [ -f "$ORCA_ROOT_PATH/.env.local" ]; then
cp "$ORCA_ROOT_PATH/.env.local" .env.local
fiWhy cp beats ln -s here: Pitfalls 3 and 4 require appending worktree-specific PORT and DATABASE_URL values. If .env.local is symlinked, an edit in Worktree A silently mutates every other worktree!
Pitfall 3: Localhost Port Collisions (EADDRINUSE :3000)
Why it happens: Git worktrees isolate files on disk, not TCP ports on 127.0.0.1. Running three Next.js or Vite dev servers on :3000 guarantees EADDRINUSE crashes—or worse, opens the wrong branch in your browser tab.
Fix: Assign per-worktree PORT offsets or hashed dynamic ports inside .env.local (or CLI flags like PORT=3001 / vite --port 3002), paired with Orca's per-worktree browser tabs:
scripts:
setup: |
cp "$ORCA_ROOT_PATH/.env.local" .env.local 2>/dev/null || true
PORT_NUM=$((3100 + $(printf '%s' "${ORCA_WORKSPACE_NAME:-default}" | cksum | awk '{print $1 % 800}')))
echo "PORT=$PORT_NUM" >> .env.localBecause each worktree owns its own embedded Chromium tab set in Orca, Worktree A stays pinned to http://localhost:3142 while Worktree B stays pinned to http://localhost:3589.
Pitfall 4: Shared Local Database & Docker Volume Pollution
Why it happens: Two agents running prisma migrate dev or destructive seed scripts against the exact same dev.db or localhost:5432/app_dev instance corrupt each other's schemas and break tests non-deterministically.
Fix: Isolate databases per worktree during scripts.setup and tear them down cleanly in scripts.archive:
Keep DATABASE_URL relative to the worktree root rather than pointing to a shared path under /tmp or $ORCA_ROOT_PATH:
# ✅ Each worktree owns an isolated SQLite file
DATABASE_URL="file:./prisma/dev.db"Run migrations or copy a clean seed snapshot inside scripts.setup.
⚠️ Common Pitfalls
- Symlinking
node_modulesacross worktrees
If Branch A upgrades a dependency while Branch B stays on an older lockfile, a shared symlinkednode_modulesbreaks builds unpredictably. Always letpnpmstore hardlinks orscripts.setupinstall independently per worktree. - Symlinking
.env.localand then overridingPORTorDATABASE_URLper worktree
Any write to a symlinked.env.localmodifies every parallel workspace. Copy.env.localfrom$ORCA_ROOT_PATHfirst, then append per-worktree overrides. - Thinking Force Delete wiped unpushed commits
When local unmerged commits exist on the branch, Orca's Preserved branches protection keeps the local Git branch intact—rungit branchor create a new worktree from that branch to recover your commits.
✅ Checklist & Next Steps
-
orca.yaml(or mappedconductor.json) definesscripts.setupandscripts.archive. - New worktrees auto-install dependencies and copy
.env.localsafely without committing secrets. - Running 2+ dev servers simultaneously uses distinct ports without
EADDRINUSE. - Database migrations or container seeds in one worktree do not affect parallel branches.
Next: Splits, Keyboard Navigation & Multi-Worktree Flow
Use Cmd/Ctrl-P, Cmd/Ctrl-J, the + Omnibox, and Session Restore to navigate 10+ concurrent worktrees smoothly.
Up Next: Diff Viewer, Annotate AI Diff & Review Loops
Review combined diffs against start-from ref and batch line-anchored markdown comments back to your agent.
Your First 5-Minute 3-Way Parallel Run
Go from adding a repo (`origin/main`) to racing 3 marine-named worktrees across Claude Code, Codex, and Gemini, reviewing diffs, shipping 1 PR, and managing 3x quota burn.
Splits, Keyboard Navigation & Multi-Worktree Flow
Organize Ghostty-styled terminal splits, editor tabs, and per-worktree browser tabs—and navigate 10+ concurrent worktrees at keyboard speed with Cmd/Ctrl-P, Cmd/Ctrl-J, the + Omnibox, and Session Restore.