Agent Skill — SKILL.md
git-worktrees
Set up and manage isolated git worktrees for parallel tasks and agent lanes, and configure or operate Worktrunk (wt) for worktree lifecycle, hooks, LLM commits, and parallel agent workflows. Use when worktree setup, recovery, or wt configuration is the real need, not generic planning or implementation guidance.
Compatibility
Agent Skills-compatible coding agents.SKILL.md
Git worktrees
Owns the whole worktree lifecycle: raw git worktree when that is all that is available, and Worktrunk (wt) configuration, hooks, LLM commits, merge pipeline, and parallel agent lanes when wt is installed.
Use this skill when
- You need isolated workspaces for parallel changes in the same repository.
- Multiple agents or contributors may work concurrently and branch-switch churn would be risky or slow.
- You want safer experimentation while keeping the primary checkout stable.
- The user explicitly asks for a separate checkout, isolated lane, or worktree-based cleanup or recovery.
- The user asks how to configure Worktrunk (
wt config,~/.config/worktrunk/config.toml,.config/wt.toml). - The user wants LLM-generated commit messages or branch summaries from
wt. - The user needs to author or debug
wthooks (post-start,pre-merge, and the rest). - The user is setting up parallel agent lanes with
wt switch --create --execute=…. - The user asks about
wt merge,wt step, the merge pipeline, shell integration, or worktree path layout.
Do not use this skill when
- You only need a single quick edit on the current branch.
- The repository is not in a usable Git state for worktree operations.
- A disposable clone is explicitly preferred over shared object storage with the main repository.
- The real task is planning, implementation, or code review and worktree setup is only incidental.
- The task is only PR lifecycle work (create/update PR and watch checks) on an already prepared branch; route to
github-cli-pr-workflow. - Implementation is complete and the question is how to integrate the branch; route to
finishing-a-development-branch.
Inputs to gather
Required before editing
- Base ref to branch from (for example
origin/main). - Task identifier suitable for branch and directory naming.
- Whether this worktree is temporary, long-lived, or tied to a PR/issue.
- For
wtwork: whether the need is config setup, hook authoring, or a parallel agent lane, and whether config already exists (wt config show).
Helpful if present
- Existing branch naming conventions.
- Preferred worktree root location for the repository.
- Local cleanup expectations for stale worktrees.
- Repo shape details such as monorepo package paths, submodules, sparse checkout, or nested worktrees.
- Project type (Node, Rust, Python, and so on) for hook examples.
- Whether LLM commit generation is wanted and which LLM tool is available.
Only investigate if encountered
- Submodule, sparse checkout, or filesystem constraints that affect worktree behavior.
- Branch-name collisions because the same branch is already checked out elsewhere.
- Recovery needs for stale registrations, missing directories, or removal blocked by local changes.
- Detached HEADs or platform-specific filesystem constraints.
First move
- Check if Worktrunk is installed:
wt --version. If available (exit code 0), preferwtcommands throughout this workflow — see Worktrunk command equivalents. If it fails and the user asked forwtspecifically, suggestbrew install worktrunk; otherwise fall back to raw git. - Inspect current worktrees and branch state (
git worktree listandgit branch --all, orwt list). - Pick names using repository conventions or the defaults in
assets/naming-examples.md. - Create or recover the isolated worktree before making task changes.
Workflow
With Worktrunk installed (wt --version succeeds)
Configure first — always when the ask is config, hooks, or LLM commits; once per user or project otherwise.
wt config show— inspect active config and file locations.wt config createscaffolds the user config,wt config create --projectthe project config.- Set
worktree-pathin the user config. An inside-repo.worktrees/template keeps agent harness worktree managers compatible. All keys and defaults: config reference. - Add a
[commit.generation]block if LLM commit messages are wanted — see LLM commit setup. - Author project hooks in
.config/wt.tomlfor install, dev server, DB, and CI gates — see hooks reference. - Optional:
[list] summary = truein the user config for branch summaries.
Then run the lifecycle.
- Fetch and verify the intended base ref.
- Create the worktree:
wt switch --create <branch> --base <ref>— firespost-starthooks automatically (deps install, dev server, and so on). - Perform all edits, tests, and commits inside that worktree.
- Commit with an LLM message (if configured):
wt step commit. - Merge when ready:
wt merge [target]— squashes, rebases, validates via pre-merge hooks, fast-forwards, and cleans up. Add--no-squashif[commit.generation]is not configured. Stage-by-stage detail: merge pipeline. - Or: push and open a PR, then
wt removeafter the PR is merged. - For parallel agent lanes, use
wt switch --create <lane> --execute=<agent>— see parallel agent recipes.
Without Worktrunk (raw git fallback)
- Check the current repository state with
git worktree listand branch visibility withgit branch --all. - Fetch and verify the intended base ref before branching from it.
- Choose a worktree path and branch name that match the task and repository conventions.
- Create a dedicated branch and worktree for the task.
- Perform all edits, tests, and commits inside that worktree rather than the primary checkout.
- If the worktree is stale, misconfigured, or ready to retire, follow
references/recovery-and-cleanup.md. - After the task is merged or no longer needed, clean up the worktree deliberately.
Guardrails
- Must use one active worktree per independent task when isolation is the reason this skill was selected.
- Must verify the current directory and branch before applying changes.
- Must not remove a worktree without checking for uncommitted changes first.
- Must check
wt --versionbefore using anywtcommand; fall back to raw git if Worktrunk is not installed. - Must not bypass project hooks (
post-start,pre-merge) without explicit justification. - Should use consistent naming defaults, but adapt to repository conventions when they differ.
- Should keep branch names and worktree paths aligned so the branch name still makes sense if the worktree path is copied or recreated later.
- Should verify the repository root before creating the worktree in monorepos or nested checkouts.
- Should run the task's validation commands from inside the worktree that owns the changes.
- Should use
wt switch --create/wt removeinstead ofgit worktree add/git worktree removewhen Worktrunk is installed, so project hooks fire and worktree lifecycle is tracked. - Should use
wt mergefor squash + rebase + cleanup in preference to manual git steps. - Should configure
[commit.generation]before relying onwt step commitfor LLM messages. - May keep long-lived worktrees for release or maintenance branches when the workflow benefits.
- May use
--no-squashwhen commit granularity matters for the PR.
Validation
- Confirm
git worktree list(orwt list) shows the expected paths and branches. - Confirm
git statusreflects the intended branch and checkout inside the worktree. - Run relevant repository checks from inside the worktree used for the task.
- Verify the worktree is clean before removal and prune stale metadata afterward when needed.
- After config or hook changes, confirm the round trip:
wt config show # confirms settings loaded
wt switch --create test-wt-check # creates worktree, fires hooks
wt list # confirms branch with status markers
wt remove test-wt-check # cleans up
- Smoke test:
- should trigger: "Create a parallel worktree for a refactor without touching my main checkout."
- should trigger: "Configure wt hooks and parallel lanes for this repo."
- should not trigger: "Review the finished diff for merge readiness." (→
implementation-review)
Examples
- "Create
.worktrees/feature-auth-refactorfromorigin/mainfor a migration lane, then keep the main checkout untouched until the branch is ready." - "Set up one worktree per agent for parallel PR work, then remove the clean worktree only after
git statuspasses." - "Recover a worktree that points at the wrong branch without losing local edits."
- "Set up LLM commit messages for this repo: inspect
wt config show, add a[commit.generation]block, then verify on a throwaway worktree thatwt mergegenerates the message." - "Add a
post-starthook that runsnpm ciand starts the dev server on the worktree's assigned port." - "Configure two parallel agent lanes with
wt switch --create agent-lane-1 --execute=…and confirm both show status markers inwt list."
Reference files
- Naming conventions and scheme
- Naming defaults and examples
- Recovery and cleanup guide
- Worktrunk command equivalents
- Worktrunk config reference — complete config key reference with defaults
- Worktrunk hooks reference — all hook types, template variables, filters, pipeline syntax
- Worktrunk LLM commit setup — commit generation config for Claude Code, Codex, llm CLI, aichat
- Worktrunk merge pipeline —
wt mergepipeline, flags, andwt stepsub-commands - Worktrunk parallel agent recipes — one-shot alias pattern, dev server per worktree, DB per worktree, cold-start elimination
Integration
Pairs with:
github-cli-pr-workflow— after pushing from a worktree, use this for PR creation/update and check-watch workflowreview-comment-resolution— after pushing a branch from a worktree, address PR review comments in the same worktree before cleanupgithub-actions-failure-triage— if a pushed branch fails CI, diagnose the failure before removing the worktreefinishing-a-development-branch— when implementation in a worktree is complete, use this to decide how to integrate (merge, PR, keep, or discard)