skills/worktree-setup/SKILL.md
Set up git worktree management with isolated databases, caches, and ports for parallel development. Run once per project to generate standalone scripts.
npx skillsauth add flrngel/worktree-skill-plugin worktree-setupInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are setting up git worktree management for this project. Your job is to analyze the project, then generate standalone shell scripts that manage worktrees with fully isolated resources (databases, caches, ports, env files). After setup, everything works via git wt with zero dependency on Claude Code.
Follow the phases below. At each step, make decisions based on what you actually find in the project — do not assume any specific stack.
Confirm the working directory is inside a git repo. If not, stop and tell the user.
If .worktree/ already exists, ask the user whether to re-run setup (overwrite scripts but preserve existing worktree entries in config).
Look for manifest files to determine the language, framework, and package manager. Check for:
package.json, and which lockfile exists (package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lockb) to determine the package managerrequirements.txt, Pipfile, pyproject.toml, poetry.lock, uv.lockGemfilego.modCargo.tomlcomposer.jsonbuild.gradle, pom.xmlmix.exsFrom this, determine the dependency install command that should run in each new worktree (e.g., the correct install command for the detected package manager).
For Node.js projects, also check package.json scripts to identify the dev server command (commonly dev, start:dev, serve, or start). Note this for the summary but don't put it in the scripts — worktrees are for development, the user starts their own server.
Read the .env file (and .env.local, .env.development, etc. if they exist). Identify:
Database connection — Look for any of these patterns:
DATABASE_URL (connection string format: postgresql://, postgres://, mysql://, mongodb://, sqlite:, etc.)DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORDPGDATABASE, PGHOST, PGPORT, PGUSER, PGPASSWORDMYSQL_HOST, MYSQL_DATABASE, etc.TYPEORM_DATABASE, PRISMA_DATABASE_URL, etc.From the connection info, extract: database type, host, port, user, password, database name.
Cache/queue connection — Look for:
REDIS_URL (connection string: redis://host:port/db or rediss://)REDIS_HOST, REDIS_PORT, REDIS_DBMEMCACHED_URL, CACHE_URL, etc.Application port — Look for:
PORT, APP_PORT, SERVER_PORT, HTTP_PORTNEXT_PUBLIC_PORT, VITE_PORT, FLASK_RUN_PORT, RAILS_PORTOther env vars that need per-worktree isolation — Look for:
APP_NAME, APP_URL (may contain port)SESSION_NAME, COOKIE_NAME (session isolation)Record exactly which env var keys you found and their current values. You need this to write correct env patching logic in the scripts.
Check for Docker Compose files (docker-compose.yml, docker-compose.yaml, compose.yml, compose.yaml). If found, read them to understand:
This serves as a fallback or confirmation for the env var detection above.
Check which command-line tools are installed on the system. You need this to decide how to implement the scripts. Things to check:
jq, python3, node)createdb, dropdb, pg_dump, psql; for MySQL: mysql, mysqldump, mysqladmin)redis-cli)lsof or ss or netstat available?sed, awk, grep — these are virtually always available but note the platform (macOS sed vs GNU sed differ in -i flag behavior)Based on what's available, you choose the implementation approach for the scripts. For example:
jq is available, use it for JSON. If not, use python3 -c or node -e or even awk/sed — whatever works.createdb isn't available but psql is, use psql -c "CREATE DATABASE ...".The scripts must work with whatever is on the machine. Do not require the user to install additional tools — adapt to what exists. If a critical operation can't be done (e.g., no way to process JSON at all), then tell the user what to install.
Create .worktree/config.json storing everything the scripts need. The config serves as:
Include only the sections relevant to what was detected. Example for a project with Postgres and Redis:
{
"base_port": 3000,
"database": {
"type": "postgres",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "postgres",
"main_db": "myapp"
},
"cache": {
"type": "redis",
"host": "localhost",
"port": 6379
},
"init_commands": ["npm install"],
"env_file": ".env",
"env_mappings": {
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/myapp",
"REDIS_URL": "redis://localhost:6379/0",
"PORT": "3000"
},
"worktrees": {}
}
Considerations:
env_mappings records the original env var keys and values that need per-worktree patching. The scripts use this to know exactly what to replace.worktrees is an object keyed by sanitized name, storing: branch, port, database name, cache DB number, path, created timestamp.database if none detected. Omit cache if none detected.Create scripts in .worktree/bin/. These must be complete, standalone, and functional — no placeholders, no TODOs, no references back to this skill. The user (or any developer) should be able to read and understand them.
You are writing five scripts. The implementation details are up to you based on what you detected, but each must fulfill the contract described below.
.worktree/bin/git-wt — Command RouterContract:
git wt commandscreate, delete (aliases: rm, remove), list (alias: ls), checkout (aliases: cd, go), helphelp or unknown command.worktree/bin/wt-create.sh — Create WorktreeArguments: <branch-name> [from-ref] where from-ref defaults to HEAD.
Contract — must do all of the following:
Sanitize the branch name for use as directory name and database suffix. Replace characters that are problematic in paths or DB names (/ -> -, strip special chars). Keep the mapping so the user can still reference by original branch name.
Reject duplicates. Check the config for an existing worktree with the same sanitized name. Also check if the directory already exists on disk.
Allocate a unique port. Start from base_port + 1, scan existing worktree entries in config to find the first unused number. Then verify the port isn't actually in use on the system (a worktree might have been deleted outside of git wt). Skip ports that are occupied.
Clone the database (if database detected):
{main_db}_wt_{sanitized_name}createdb -T), but this fails if the source has active connections — fall back to dump-and-restore. For MySQL, use mysqldump | mysql. For other DBs, do what makes sense or skip with a warning.Allocate a cache namespace (if cache detected):
Create the git worktree. Use git worktree add <path> -b <branch> <from-ref>.
Copy and patch the env file. This is critical — copy the env file to the worktree directory, then replace the relevant values:
Considerations for env patching:
sed -i behaves differently on macOS vs Linux. Use sed -i.bak + rm *.bak for portability, or use another approach..env, .env.local). Copy all that exist.Run init commands in the worktree directory. Run the detected install command(s). If they fail, warn but don't abort — the worktree itself is still valid.
Update config.json with the new worktree entry including all allocated resources and a creation timestamp.
Print a summary of what was created: path, branch, port, database, cache DB.
.worktree/bin/wt-delete.sh — Delete WorktreeArguments: <branch-name>
Contract:
Look up the worktree in config. Accept both the original branch name and the sanitized form. If not found, list available worktrees and exit.
Drop the database (if one was created). Use the appropriate tool for the DB type. Use --if-exists or equivalent to avoid errors. If the tool isn't available or the drop fails, warn but continue.
Clean up the cache namespace (if one was allocated). For Redis, flush the allocated DB. Warn on failure but continue.
Remove the git worktree. Use git worktree remove --force, falling back to manual directory removal if that fails. Run git worktree prune afterward.
Remove the entry from config.json.
Print confirmation of what was deleted.
.worktree/bin/wt-list.sh — List WorktreesContract:
.worktree/bin/wt-checkout.sh — Switch to a Worktree or Main Repo DirectoryArguments: [worktree-name] (optional; accepts original branch name or sanitized name)
Contract:
- or main: Output the main repository root path. This lets the user switch back to the main repo from any worktree.feat/foo and feat-foo). If not found, list available worktrees and exit with an error.Note: A git alias runs in a subshell and cannot change the parent shell's working directory. git wt checkout outputs the path to stdout so the user can compose it with cd:
cd $(git wt checkout feat/foo)
Zero tracked changes. Nothing you do should appear in git status.
Exclude .worktree from git by adding it to .git/info/exclude (NOT .gitignore). Check if it's already there before adding.
Create a local git alias so git wt routes to the script:
git config alias.wt '!.worktree/bin/git-wt'
This is stored in .git/config (local only, not committed).
Make all scripts executable.
Verify the setup works by running git wt help and confirming it produces output.
Print a clear summary covering:
git wt create/delete/list/checkout) with examplescd $(git wt checkout <name>) usage patternThis is critical. All scripts need to find the main repository root where .worktree/ lives — not the current worktree's root.
git rev-parse --show-toplevel returns the root of whichever working tree you're currently in. If you're inside a worktree at .worktree/feat-foo/, it returns that path — not the main repo. So using --show-toplevel alone would fail to find .worktree/config.json when running from inside a worktree.
The scripts must resolve the main repo root regardless of whether the user is in the main working tree or any worktree. git rev-parse --git-common-dir returns the path to the shared .git directory, which always belongs to the main repo. From that, the main repo root can be derived (it's the parent of the .git directory). There may be other approaches — choose whatever is robust and works across git versions.
Every script must use this resolution. Do not assume the user is in the main working tree.
sed -i portability (macOS requires a backup extension argument, GNU doesn't)./usr/bin/env bash shebang for portability./, ., and other characters. The sanitization must produce safe directory names and database identifiers.git wt delete must clean up ALL allocated resources, not just the git worktree.development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.
development
Run, watch, debug, and extend OpenClaw QA testing with qa-lab and qa-channel. Use when Codex needs to execute the repo-backed QA suite, inspect live QA artifacts, debug failing scenarios, add new QA scenarios, or explain the OpenClaw QA workflow. Prefer the live OpenAI lane with regular openai/gpt-5.4 in fast mode; do not use gpt-5.4-pro or gpt-5.4-mini unless the user explicitly overrides that policy.
development
End-to-end Parallels smoke, upgrade, and rerun workflow for OpenClaw across macOS, Windows, and Linux guests. Use when Codex needs to run, rerun, debug, or interpret VM-based install, onboarding, gateway smoke tests, latest-release-to-main upgrade checks, fresh snapshot retests, or optional Discord roundtrip verification under Parallels.