/agent-traffic-control:git-worktreefrom agent-traffic-control
Create, list, switch and clean up git worktrees — a second isolated checkout for parallel work or a pull request review. Runs the bundled `skills/git-worktree/scripts/worktree-manager.sh`, which also copies `.env` in, gitignores the dir and trusts mise or direnv. Not a bare `git worktree add`.
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
This skill provides a unified interface for managing Git worktrees across your development workflow. Whether you're reviewing PRs in isolation or working on features in parallel, this skill handles all the complexity.
Every command below runs "$WTM". Resolve it once:
# Three roots, in order. A plugin install creates NEITHER of the first two:
# CLAUDE_PLUGIN_ROOT is frequently unset in the shell a step actually runs in, and
# ~/.claude/skills/agent-traffic-control/ does not exist — the plugin lives under
# ~/.claude/plugins/cache/<marketplace>/agent-traffic-control/<version>/.
REL="skills/git-worktree/scripts/worktree-manager.sh"
WTM="${CLAUDE_PLUGIN_ROOT:+${CLAUDE_PLUGIN_ROOT}/$REL}"
[ -f "$WTM" ] || WTM="$HOME/.claude/skills/agent-traffic-control/$REL"
# Rank on the VERSION segment, not the whole path: the marketplace name precedes the
# version, so a plain `sort -V` over full paths would let aaa-mkt/2.5.0 lose to
# zzz-mkt/1.0.0. Here the version sits at NF-4 because the script nests two levels
# deeper than a flat plugin layout. Use `find`, not a glob — zsh fails a non-matching
# glob at expansion time, before 2>/dev/null can apply.
[ -f "$WTM" ] || WTM="$(find -L "$HOME/.claude/plugins/cache" -mindepth 7 -maxdepth 7 \
-path "*/agent-traffic-control/*/$REL" 2>/dev/null \
| awk -F/ '{print $(NF-4)"\t"$0}' | sort -V -k1,1 | tail -1 | cut -f2-)"
if [ ! -f "$WTM" ]; then
echo "worktree-manager.sh: not found — tried \$CLAUDE_PLUGIN_ROOT/$REL," \
"\$HOME/.claude/skills/agent-traffic-control/$REL, and" \
"\$HOME/.claude/plugins/cache/*/agent-traffic-control/*/$REL"
fi
Say "not found — tried <paths>", never a bare "not installed": a failed lookup is
not evidence about install state. Without this block the commands below expanded to
/skills/git-worktree/scripts/worktree-manager.sh on any plugin-scope machine and died
with a bare exit 127 naming no root at all.
NEVER call git worktree add directly. Always use the worktree-manager.sh script.
The script handles critical setup that raw git commands don't:
.env, .env.local, .env.test, etc. from main repo.worktrees is in .gitignore# ✅ CORRECT - Always use the script
bash "$WTM" create feature-name
# ❌ WRONG - Never do this directly
git worktree add .worktrees/feature-name -b feature-name main
Use this skill in these scenarios:
/ce:review): If NOT already on the target branch (PR branch or requested branch), offer worktree for isolated review/ce:work): Always ask if user wants parallel worktree or live branch workThe skill is automatically called from /ce:review and /ce:work commands:
# For review: offers worktree if not on PR branch
# For work: always asks - new branch or worktree?
You can also invoke the skill directly from bash:
# Create a new worktree (copies .env files automatically)
bash "$WTM" create feature-login
# List all worktrees
bash "$WTM" list
# Switch to a worktree
bash "$WTM" switch feature-login
# Copy .env files to an existing worktree (if they weren't copied)
bash "$WTM" copy-env feature-login
# Clean up completed worktrees
bash "$WTM" cleanup
create <branch-name> [from-branch]Creates a new worktree with the given branch name.
Options:
branch-name (required): The name for the new branch and worktreefrom-branch (optional): Base branch to create from (defaults to main)Example:
bash "$WTM" create feature-login
What happens:
main, develop, dev, trunk, staging, release/*) compare against themselves.envrc can source unchecked fileslist or lsLists all available worktrees with their branches and current status.
Example:
bash "$WTM" list
Output shows:
switch <name> or go <name>Switches to an existing worktree and cd's into it.
Example:
bash "$WTM" switch feature-login
Optional:
cleanup or cleanInteractively cleans up inactive worktrees with confirmation.
Example:
bash "$WTM" cleanup
What happens:
# Claude Code recognizes you're not on the PR branch
# Offers: "Use worktree for isolated review? (y/n)"
# You respond: yes
# Script runs (copies .env files automatically):
bash "$WTM" create pr-123-feature-name
# You're now in isolated worktree for review with all env vars
cd .worktrees/pr-123-feature-name
# After review, return to main:
cd ../..
bash "$WTM" cleanup
# For first feature (copies .env files):
bash "$WTM" create feature-login
# Later, start second feature (also copies .env files):
bash "$WTM" create feature-notifications
# List what you have:
bash "$WTM" list
# Switch between them as needed:
bash "$WTM" switch feature-login
# Return to main and cleanup when done:
cd .
bash "$WTM" cleanup
/ce:reviewInstead of always creating a worktree:
1. Check current branch
2. If ALREADY on target branch (PR branch or requested branch) → stay there, no worktree needed
3. If DIFFERENT branch than the review target → offer worktree:
"Use worktree for isolated review? (y/n)"
- yes → call git-worktree skill
- no → proceed with PR diff on current branch
/ce:workAlways offer choice:
1. Ask: "How do you want to work?
1. New branch on current worktree (live work)
2. Worktree (parallel work)"
2. If choice 1 → create new branch normally
3. If choice 2 → call git-worktree skill to create from main
If you see this, the script will ask if you want to switch to it instead.
Switch out of the worktree first (to main repo), then cleanup:
cd $(git rev-parse --show-toplevel)
bash "$WTM" cleanup
See where you are:
bash "$WTM" list
If a worktree was created without .env files (e.g., via raw git worktree add), copy them:
bash "$WTM" copy-env feature-name
Navigate back to main:
cd $(git rev-parse --show-toplevel)
.worktrees/
├── feature-login/ # Worktree 1
│ ├── .git
│ ├── app/
│ └── ...
├── feature-notifications/ # Worktree 2
│ ├── .git
│ ├── app/
│ └── ...
└── ...
.gitignore (updated to include .worktrees)
git worktree add for isolated environmentsOver months, sessions leave several clones and worktrees of the same repository. Before removing one, prove it holds no unique work:
# 1. Same repository? Compare remotes.
git -C /path/to/dir1 remote -v
git -C /path/to/dir2 remote -v
# 2. Which are worktrees of which?
git -C /path/to/primary worktree list
# 3. No unique work?
git -C /path/to/suspect status --short --ignored # uncommitted AND ignored files
git -C /path/to/suspect stash list # stashed work
git -C /path/to/suspect log --oneline origin/main..HEAD # unpushed commits
git -C /path/to/suspect branch --no-merged origin/main # unmerged branches
# 4. Remove
git worktree remove /path/to/worktree # never --force; it refuses on uncommitted work
git worktree remove deletes ignored files without asking (an ignored output folder can be the
only copy of a result), so read the !! lines from step 3 first. Delete a duplicate clone (not a
worktree) only after all four checks come back empty.
After squash merges, the last two commands of step 3 list work that DID land, because squashed commits are never ancestors of main. Confirm those by content instead: gh pr list --head <branch> --state merged, or verify-a-squash-merge-by-content-not-lineage.
These carry disable-model-invocation: true. They never appear in the skill
listing and the Skill tool refuses them, so the only way in is to open the file
with Read when one of these matches what you are looking at.
main-bash-cwd-persists-nested-worktree — a worktree got created at the wrong filesystem path because the main agent's bash cwd persistedshell-pinned-to-deleted-worktree-cwd-blocks-git — every shell command now fails Unable to read current working directory after a worktree was removedgit-auto-maintenance-recurring-worktree-index-lock — index.lock: File exists keeps coming back after you delete itrecover-from-an-async-post-commit-hook — a background post-commit hook breaks the next git command: unreadable objects in a sibling worktree, a branch locked by an autodocs worktree, a stalled rebase, an amend that rewrote the hook's commitworktree-does-not-isolate-shared-installed-artefacts — a worktree isolates the source tree and nothing else — venvs, caches and installed packages stay sharedworktree-historical-test-replay-missing-dirs — pytest exit 4 replaying tests in a worktree checked out at an old commitverify-pytest-imports-worktree-not-primary-checkout — an editable install makes import <pkg> resolve to the primary checkout, not your worktreeflask-debug-cross-worktree-edit-stale — the dev server keeps serving the old template after you edited it in another worktreeparallel-gate-legs-killed-for-memory-count-cannot-see-ram — a worktree does not isolate the machine: two sessions' test legs collide on memory while the heavy-leg count reads inside its limitWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verify