agentleFS
sunduq-aisunduq-ai/falq/skills/worktree-isolation/SKILL.md

worktree-isolation

Skill4 starsChanged 6 months agoMITView on GitHub

Prepare any repository for running multiple git worktrees in parallel with isolated runtimes. Use whenever the user mentions parallel worktrees, parallel AI agents/sessions on one repo, port conflicts between checkouts, per-worktree databases or env files, `claude -w`, worktrunk, or asks why two dev servers collide — even if they don't name falq.

  • Reads credentials

5 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions5 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 5

    1. alex-voloshin-dev/ai-skills★ 2same name
    2. nicolai-bernsen/backlogd★ 2same name
    3. aditya-deokar/software-factory★ 1same name
    4. orkait/hyperstack★ 1same name
    5. niksavis/basicly★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repositoryOne other file it gives its agents.

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every config file: .env*, config/, settings.*, application*.yml, vite.config.*, next.config.*, appsettings*.json, launchSettings.json, …

    line 45
  2. Very specific:

    Write falq.yaml at the repo root.

    line 85
  3. Distinctive:

    Prefer the generate tier (render a full template file) over patch (dotted-path edits).

    line 87
  4. Very specific:

    Make the worktree runnable in one apply: add the dependency-install line for the stack(s) present (pnpm install, uv sync, bundle install, …

    line 97
  5. Very specific:

    Every resource created in post_apply needs a matching pre_remove: createdb ↔ dropdb, stream create ↔ stream delete, queue declare ↔ queue …

    line 102
  6. Very specific:

    Always include an agent_context.template naming this worktree's PORT, DB, and compose project — agents that can't see those facts hardcode …

    line 108
  7. Distinctive:

    Never declare the repo ready without this:

    line 147
  8. Distinctive:

    If anything failed, see references/troubleshooting.md (port thieves, zombie compose stacks, stale slots) — fix and re-prove.

    line 168

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Worktree Isolation with falq

Git worktrees isolate files. Nothing isolates the runtime: parallel worktrees collide on ports, database names, queue prefixes, cache keys, and docker compose project names. Your job: inspect this repo, write a falq.yaml manifest that makes every worktree self-contained, validate it, and prove it by booting two worktrees side by side.

How falq works: each worktree gets a slot (main = 0, others = lowest free integer). Ports derive as base + slot × stride. falq apply provisions the current worktree from the manifest; a git post-checkout hook runs it automatically; falq remove tears down. Templates are minijinja with variables slot, port, stride, branch, branch_slug, repo, worktree_path, main_path (arithmetic allowed: {{ port + 1 }}). Full schema: references/manifest-schema.md.

Step 1 — Discover

First, identify the architecture — it shapes everything below:

  • Workspace files (pnpm-workspace.yaml, root package.json workspaces, nx.json, turbo.json, lerna.json, Cargo [workspace], go.work, settings.gradle) → monorepo: enumerate every package and the port its dev server wants.
  • Several compose files / many services → multi-service.
  • One app at the root → single app.
  • Independent repos run together → polyrepo (one manifest each).

Patterns for each: references/architectures.md.

Then read the repo before writing anything (works for any stack — the per-stack map of where ports/DBs/queues live and what to feed is in references/stacks.md):

  • Every config file: .env*, config/, settings.*, application*.yml, vite.config.*, next.config.*, appsettings*.json, launchSettings.json, config/runtime.exs, Procfile.
  • Compose files (docker-compose.{yml,yaml}, compose.{yml,yaml}): list every service, port mapping, volume, network.
  • Dev-server commands in package.json scripts (per package in a monorepo), Makefile, Taskfile, justfile, mix.exs, *.csproj — note every port.
  • Grep for EVERY hardcoded port/host — including build-target configs. A literal --port 8000 in an Nx project.json, turbo.json, Procfile, or package.json script binds that port regardless of the manifest, and it's the #1 reason a worktree still collides after a clean apply. Use the explicit recipe and file list in references/discovery.md; don't rely on a narrow localhost:3000 grep.
  • Identify DB/queue/cache clients (postgres, mysql, mongo, redis, nats, kafka, rabbitmq, sqlite paths) and where their names/prefixes come from. Per-stack map: references/stacks.md.

Step 2 — Classify

Split every discovered value into:

  • Per-worktree-varying: ports, database names, queue/cache key prefixes, compose project name, debug ports, local file paths for sockets/caches. These go in the manifest.
  • Shared: API keys, feature flags, third-party URLs. These stay in the copied env file untouched — falq copies env.copy files from main and only rewrites the keys you list in upsert.
  • Hardcoded ports/hosts: distinguish wiring from logic.
    • Wiring — a port literal in a build-target/config file (project.json, Procfile, vite.config.*, package.json script): part of the isolation contract. Compute the env-reading refactor (--port "${PORT:-8000}", keeping the literal as the fallback so main is unchanged), present the diff, and write it to .worktree/pending-refactors.md so it's never lost. The human applies it (falq never edits code); falq doctor keeps flagging any that remain. Details: references/discovery.md.
    • Logic — a literal in feature/business code: flag as a proposed diff and stop. Never edit it.

Step 3 — Generate

Write falq.yaml at the repo root. Guidelines:

  • Prefer the generate tier (render a full template file) over patch (dotted-path edits). Generate is format-agnostic and merge-proof; patch only when the app has no local-override file layer. Format guidance: references/formats.md.
  • Choose base/stride so every needed port fits one stride per worktree and stays inside 1024–9999 (avoid 6000/6665/6666/6697 — browser-blocked). Monorepo: one slot owns a contiguous port BLOCK; give each package a fixed offset (web=+0, api=+1, …), size stride to hold the largest offset (20–50 for big workspaces), and generate a per-package env file. Full pattern: references/architectures.md.
  • Make the worktree runnable in one apply: add the dependency-install line for the stack(s) present (pnpm install, uv sync, bundle install, …) to post_apply, so a fresh worktree has node_modules/.venv after the hook runs and falq run -- pnpm dev works first try. Per-ecosystem recipes: references/post_apply_recipes.md.
  • Every resource created in post_apply needs a matching pre_remove: createdb ↔ dropdb, stream create ↔ stream delete, queue declare ↔ queue delete. Asymmetric hooks leak resources.
  • With compose, interpolate host ports from env ("${APP_PORT:-3000}:3000") and let falq set COMPOSE_PROJECT_NAME. Details and the additive-merge !override gotcha: references/compose.md.
  • Always include an agent_context.template naming this worktree's PORT, DB, and compose project — agents that can't see those facts hardcode 3000. Point agent_context.files at a gitignored file (default .falq/context.md, imported once from a committed CLAUDE.md/AGENTS.md via @.falq/context.md) so the per-worktree block never shows as a git change. You add that one import line during setup; falq gitignores .falq/. Details + the CLAUDE.local.md shortcut: references/manifest-schema.md.

Then: falq init (if not done), keep your manifest, and confirm the post-checkout hook is installed (falq hook status).

Step 4 — Validate

falq doctor --json

Fix every finding: stale slots, unignored outputs (everything falq writes must be gitignored), compose lints (container_name:, fixed host ports, network_mode: host, external networks, top-level name:), hook version. Re-run until "ok": true. doctor also warns about hardcoded ports it finds in build-target configs (--port 8000 in project.json, etc.) — these don't fail doctor but tell you which wiring refactors from Step 2 still need applying. Then falq apply --dry-run and read the plan — it must match what you intended.

Step 5 — Prove

First commit the manifest. git worktree add populates a new worktree from committed state — an uncommitted or untracked falq.yaml (plus its generate templates and .gitignore changes) will NOT exist in the worktree, so falq apply there exits 13 (no manifest) and the worktree comes up unprovisioned. Commit before adding any worktree:

git add falq.yaml .gitignore .worktree/   # + any generate templates
git commit -m "chore: add falq worktree-isolation manifest"

Never declare the repo ready without this:

git worktree add ../$(basename "$PWD").proof-a -b proof-a
git worktree add ../$(basename "$PWD").proof-b -b proof-b
(cd ../*proof-a && falq run -- <dev server command> &)
(cd ../*proof-b && falq run -- <dev server command> &)
# hit BOTH health endpoints — expect 200 from two DIFFERENT ports
curl -s -o /dev/null -w '%{http_code}\n' "http://localhost:$(cd ../*proof-a && grep '^PORT=' .env | cut -d= -f2)/health"
curl -s -o /dev/null -w '%{http_code}\n' "http://localhost:$(cd ../*proof-b && grep '^PORT=' .env | cut -d= -f2)/health"

Show the user the two distinct live ports (and distinct COMPOSE_PROJECT_NAMEs if compose is involved). Then tear down cleanly:

(cd ../*proof-a && falq remove) && git worktree remove --force ../*proof-a
(cd ../*proof-b && falq remove) && git worktree remove --force ../*proof-b
falq slots   # must show no proof-* entries

If anything failed, see references/troubleshooting.md (port thieves, zombie compose stacks, stale slots) — fix and re-prove.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.