skills/git-worktrees/SKILL.md
Explains git worktrees and Claude Code usage; guides removal and cleanup when a branch cannot be deleted because of an active worktree. Use when "cannot delete branch used by worktree", cleaning up .claude/worktrees/, or when the user asks about worktrees.
npx skillsauth add pkuppens/pkuppens git-worktreesInstall 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.
Explains git worktrees, how Claude Code uses them, and how to remove or clean them.
git branch -D <branch> fails with "cannot delete branch used by worktree".claude/worktrees/ after sessionsA worktree lets you check out multiple branches from the same repo at once, each in its own directory. Shared: history, remotes, config. Independent per worktree: working files, index, checked-out branch.
Rule: A branch can be checked out in only one worktree at a time. That is why git branch -D <branch> fails while the worktree exists.
| Aspect | Behaviour |
|--------|-----------|
| Creation | Creates worktrees under .claude/worktrees/ when you say "work in a worktree" or use claude --worktree |
| Branch naming | Branches like claude/jolly-euler (random suffix) or claude --worktree feature-name for a named worktree |
| Isolation | Each session can have its own worktree to avoid conflicts between parallel sessions or sub-agents |
| Auto-cleanup | If no changes were made, Claude removes the worktree and branch when the session ends |
| With changes | Claude prompts to keep or discard; if kept, the worktree remains until you remove it manually |
Task tool: isolation: "worktree" in agent frontmatter makes sub-agents run in their own worktree.
Recommended: Add .claude/worktrees/ to .gitignore.
Before deleting a branch used by a worktree, remove the worktree first.
Check if the worktree has unique content worth keeping:
git log main..<branch> --oneline # Commits in branch not in main
git log <branch>..main --oneline # Commits in main not in branch
If the branch has no commits ahead of main and no uncommitted changes, it is safe to remove.
git worktree remove .claude/worktrees/<name>
If uncommitted changes exist and you still want to remove: git worktree remove --force .claude/worktrees/<name>.
git branch -D <branch>
git worktree prune
If git worktree remove fails with "not a working tree", or the branch was already deleted, the directory may be orphaned and locked by another process (IDE, Explorer). Remove it manually once nothing is using it:
Remove-Item -Recurse -Force .claude\worktrees\<name>
tools
Creates, queries, updates, and links Azure Boards work items via az boards CLI. Use when filing ADO work items, running WIQL queries, or setting area path, iteration, tags, and assignee.
tools
Creates, reviews, and completes Azure Repos pull requests and branch policies via az repos CLI. Use when opening ADO PRs, setting required reviewers, or configuring build validation policies.
development
Guides Azure Pipelines YAML structure, build validation on PRs, and staged deployment with environments and approvals. Use when authoring azure-pipelines.yml or configuring CI/CD on Azure DevOps.
tools
Orchestrates Azure DevOps work item, repo, and pipeline workflows using az CLI. Use when working with Azure DevOps, Azure Repos, Azure Boards, Azure Pipelines, or az devops commands.