Manage the full lifecycle of branch-isolated worktrees: bootstrap the workflow, begin work on a new branch, and finish by tearing down the worktree and its databases.
Shared Concepts
.branchfile: Written into each worktree root. Contains a sanitized branch identifier (conventional prefix stripped, alphanumeric + underscore, max 24 chars). Config files read this to select the correct database.- Branch-aware DB naming: Each worktree gets its own
APP_NAME_<branch_id>_devandAPP_NAME_<branch_id>_testdatabases. The main worktree (no.branchfile) uses default names. - Workie CLI: The workie CLI automates worktree creation/removal and runs hooks defined in
.workie.yaml. When the CLI is not installed, the skill falls back to manualgit worktreecommands + hook steps. - Prerequisites: Phoenix app with Ecto + PostgreSQL, Git, PostgreSQL running locally. Workie CLI recommended but not required.
Commands
/workie bootstrap
Set up the workie workflow in a Phoenix project so that every future worktree gets its own directory and isolated database.
What This Creates
- Environment secret files (format depends on detected strategy)
.workie.yaml— Workie configuration with hooksscripts/setup_branch_db.sh— Creates branch-specific dev + test databases, runs migrations and seedsscripts/cleanup_branch_db.sh— Drops branch databases on worktree removal- Branch-aware database naming in config
.gitignoreentries for env files and.branch
Workflow
-
Detect environment loading strategy — Inspect
mix.exs,config/runtime.exs,config/config.exs, and the root directory to determine which strategy the project uses. Seereferences/bootstrap-strategies.mdfor full detection logic and implementation for each strategy:- Strategy A: Dotenvy —
.envfiles loaded viaDotenvy.source!/2inruntime.exs. Preferred for new setups. - Strategy B: Elixir Script Import —
.env.dev.exs/.env.test.exsfiles withSystem.put_envcalls, imported viaimport_config. - Strategy C: Plain System.get_env — Secrets managed externally (shell, direnv). Only needs
.branch+ database scripts.
- Strategy A: Dotenvy —
-
Implement the detected strategy — Follow the steps in
references/bootstrap-strategies.mdfor the detected strategy (env files, config changes, branch-aware DB naming). -
Create shared scripts and config — Database setup/cleanup scripts,
.workie.yaml, and gitignore entries. Seereferences/shared-scripts.mdfor all templates. -
Replace placeholders — Substitute all placeholder values in the generated files:
| Placeholder | Replace With | Example |
|---|---|---|
APP_NAME |
Your app's database prefix (snake_case) | my_app |
app_name |
Your OTP app name (atom) | my_app |
AppName |
Your app module name | MyApp |
GITHUB_OWNER |
GitHub org or username | myorg |
GITHUB_REPO |
GitHub repository name | my_app |
/workie begin <branch-name>
Create a new worktree for a feature branch with its own isolated database.
Workflow
-
Pre-flight checks
- Verify this is a git repository
- Check that
.workie.yamlexists in the project root. If missing, offer to run/workie bootstrapfirst. - Check PostgreSQL is available:
pg_isready
-
Determine branch name
- Use the provided
<branch-name>argument - If none provided, ask the user for a branch name
- Use the provided
-
Create worktree (Workie CLI path)
- Run
workie begin <branch-name> - The CLI handles: creating the git worktree, copying
files_to_copy, writing.branch, runningpost_createhooks (mix deps.get,mix compile,setup_branch_db.sh)
- Run
-
Manual fallback (if workie CLI is not installed)
git worktree add ../<project>-<branch-name> -b <branch-name>(or use existing branch with-B)- Copy files listed in
.workie.yamlfiles_to_copyinto the new worktree cdinto the new worktree directory- Generate
.branchfile:branch_name=$(git branch --show-current); branch_name=${branch_name#*/}; echo "${branch_name//[^a-zA-Z0-9]/_}" | cut -c1-24 > .branch - Run
mix deps.get && mix compile - Run
./scripts/setup_branch_db.sh
-
Verify
- Confirm worktree appears in
git worktree list - Confirm databases were created (check
psql -loutput for the branch DB names) - Report to user: worktree path, dev DB name, test DB name
- Confirm worktree appears in
/workie finish [branch-name]
Tear down a worktree and clean up its databases.
Workflow
-
Determine target branch
- Use the provided
[branch-name]argument if given - Otherwise, detect from
.branchfile in the current directory - If neither available, list worktrees with
git worktree listand ask the user which one to remove
- Use the provided
-
Safety checks
- Check for uncommitted changes in the target worktree:
git -C <worktree-path> status --porcelain - If changes exist, warn the user and offer options: commit, stash, or discard
- Check for unpushed commits:
git -C <worktree-path> log @{u}.. --oneline 2>/dev/null - If unpushed commits exist, warn the user
- Check for uncommitted changes in the target worktree:
-
Optional PR check
- Check if a PR already exists for this branch:
gh pr list --head <branch-name> --state open - If no PR exists, offer to create one before finishing
- Check if a PR already exists for this branch:
-
Clean up (Workie CLI path)
- Run
workie finish <branch-name> - The CLI handles: running
pre_removehook (cleanup_branch_db.sh), removing the git worktree
- Run
-
Manual fallback (if workie CLI is not installed)
cdto the worktree directory and run./scripts/cleanup_branch_db.shcdback to the main worktreegit worktree remove <worktree-path>(use--forceonly if user confirmed discarding changes)- Optionally delete the branch:
git branch -d <branch-name>(or-Dif unmerged and user confirms)
-
Verify
- Confirm worktree no longer appears in
git worktree list - Confirm databases were dropped (check
psql -l) - Report cleanup summary to user
- Confirm worktree no longer appears in
Rules
- Run each
git,workie,mix,psql,createdb,dropdb,pg_isready, andghcommand as its own separate Bash call. Do not combine commands into multi-line scripts. - Always check for the workie CLI first (
which workie). Use CLI path when available, manual fallback otherwise. - Never force-remove a worktree without user confirmation if there are uncommitted changes.
- When running bootstrap, detect the existing strategy before making any changes — do not blindly install Dotenvy if the project already uses a different approach.
$ARGUMENTS