From git-tooling
This skill should be used when the user asks to "create a worktree", "add a worktree", "set up worktrees for PRs", "create worktrees for open pull requests", "inspect worktrees", "show worktree status", "clean up worktrees", "prune worktrees", "audit worktrees", "worktree audit", "list worktrees", "remove stale worktrees", "new branch worktree", "parallel branch development", or mentions git worktree management. Provides workflows for creating, managing, auditing, and cleaning up git worktrees for efficient parallel branch development.
How this skill is triggered — by the user, by Claude, or both
Slash command
/git-tooling:git-worktreeThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Manage git worktrees for parallel branch development. Worktrees allow working on multiple branches simultaneously without stashing or switching, each in its own directory.
Manage git worktrees for parallel branch development. Worktrees allow working on multiple branches simultaneously without stashing or switching, each in its own directory.
Default behavior: Assume the user does NOT want to commit and push directly to main — always create a worktree on a feature branch so changes go through a PR.
Hook prompt: This plugin ships a PreToolUse(Bash) hook that routes git commit on a repo's default branch through Claude Code's permission prompt (permissionDecision: "ask"). If you see the prompt referencing GIT_TOOLING_ALLOW_DEFAULT_BRANCH_COMMIT, consider jumping to Workflow 2 (Create a New Branch and Worktree) instead of approving the commit on the default branch.
Repository root:
!`git rev-parse --show-toplevel 2>/dev/null`
Current branch:
!`git branch --show-current 2>/dev/null`
Existing worktrees:
!`git worktree list 2>/dev/null`
Remote tracking:
!`git remote get-url origin 2>/dev/null`
Nested repositories (independent git repos inside this repo):
!`ls -d services/*/.git tooling/*/.git 2>/dev/null`
Create worktrees with git (you control the path), then optionally enter them with the built-in EnterWorktree tool so the session tracks the worktree and ExitWorktree handles cleanup.
# 1. Create worktree in standard location
git worktree add -b feat-branch worktrees/feat-branch origin/main
# 2. Enter it — session tracks it, ExitWorktree works for cleanup
EnterWorktree(path: "worktrees/feat-branch")
When to use EnterWorktree: In the main session when switching into a worktree for extended work. It switches the session's working directory and enables ExitWorktree for clean return.
When NOT to use EnterWorktree: In subagents — they should just cd into the worktree directory. Also never call EnterWorktree without path — that creates worktrees in .claude/worktrees/ which is buried and not IDE-friendly.
Never use isolation: "worktree" on the Agent tool — it has no path control and nests dangerously if the parent is already in a worktree.
CRITICAL: If nested repositories are detected above, you MUST determine which repo the user wants the worktree in BEFORE creating it. Nested repos are independent git repositories with their own branches, remotes, and worktrees. They are NOT tracked by the parent repo (they are gitignored).
Rules:
cd into that repo first. All git commands (fetch, branch, worktree add) must run from the nested repo's root.<nested-repo>/worktrees/<branch-name>/.gh pr list.Example — creating a worktree in a nested repo:
cd services/home-agent
git fetch origin
git worktree add -b feat/my-feature worktrees/feat-my-feature origin/main
# Work in: services/home-agent/worktrees/feat-my-feature/
All worktrees are created under a worktrees/ directory at the repository root:
<repo-root>/
├── worktrees/
│ ├── <branch-1>/ # Worktree for branch-1
│ ├── <branch-2>/ # Worktree for branch-2
│ └── feature-xyz/ # Worktree for feature-xyz
├── src/ # Main working tree
└── ...
Branch names containing slashes (e.g., feature/login) are flattened to use hyphens (e.g., feature-login) for directory names.
Ensure worktrees/ is added to .gitignore to avoid committing worktree directories.
Analyze the user's request and determine which workflow to execute. If unclear, ask using AskUserQuestion.
Fetch all open pull requests from GitHub and create a worktree for each.
Steps:
gh auth status
gh auth login and stopmkdir -p worktrees.gitignore for worktrees/ entry; add it if missinggit fetch --all --prunegh pr list --state open --json number,headRefName,title
git worktree list to determine what to skip/ with -)git worktree add worktrees/<sanitized-name> <branch-name>git worktree add worktrees/<sanitized-name> -b <branch-name> origin/<branch-name>Error handling:
gh is not authenticated, prompt the user to run gh auth logingit worktree add fails for a specific branch, log the error and continue with remaining branchesInteractively create a new branch with a worktree for feature development.
Steps:
/, -, _, .git branch --list <name> — must not existgit branch -r --list origin/<name> — must not existmain or master)git rev-parse --abbrev-ref origin/HEAD.gitignore/ with -)git fetch origingit worktree add -b <branch-name> worktrees/<dir-name> <base>git worktree listEnterWorktree(path: "worktrees/<dir-name>") so the session tracks itError handling:
git fetch origin fails (network error), warn the user and offer to proceed with local stategit worktree add fails (permissions, disk space), report the error message and suggest remediationRemove worktrees for branches that have been merged or deleted.
Steps:
${CLAUDE_PLUGIN_ROOT}/scripts/worktree-audit.sh
--no-gh to skip GitHub PR checks (faster/offline mode)--no-fetch to skip git fetch --all --prune (use cached state)git worktree remove worktrees/<name> (use --force for dirty)git branch -d <branch-name>git branch -D <branch-name>git worktree prune to clean up stale administrative entriesSafety rules:
Display the current worktree state with useful context.
Steps:
git worktree list --porcelain for machine-readable outputbranch line in porcelain outputgit -C <worktree-path> log -1 --onelinegit -C <worktree-path> rev-list --left-right --count @{upstream}...HEAD 2>/dev/nullgit -C <worktree-path> status --porcelain | wc -llocked line in porcelain outputError handling:
git worktree prunegit fetch --all --prune before PR-based operations to ensure branch data is current.worktrees/ is in .gitignore. Check and add it if missing.git worktree lock), do not remove it without asking.After completing any workflow, provide a summary:
**Worktree Summary**
| Action | Branch | Directory | Status |
|--------|--------|-----------|--------|
| Created | feature-login | worktrees/feature-login | Ready |
| Skipped | bugfix-typo | worktrees/bugfix-typo | Already exists |
| Removed | old-feature | worktrees/old-feature | Merged into main |
Total worktrees: X active
Creates bite-sized, testable implementation plans from specs or requirements, with file structure and task decomposition. Activates before coding multi-step tasks.
npx claudepluginhub jedwards1230/claude-plugins --plugin git-tooling