The short answer
- 01
List them with
git worktree list. Add--porcelainto see which are locked or prunable. - 02
Remove one with
git worktree remove <path>. Git refuses unless the worktree is clean: no untracked files and no changes to tracked files. - 03
Do not add
--forceby reflex. It deletes untracked and modified files with the folder. Git-ignored files such as.envare deleted even without it. - 04
The branch stays. Delete it separately with
git branch -d, which refuses if it is not merged. - 05
Folder already deleted by hand? Run
git worktree prune --dry-run, thengit worktree pruneto drop the stale registration.
Example repo~/code/shopmain worktree, never removed
Careful fix-login is kept: it is locked
A Claude Code run left a lock on it. A lock also blocks git worktree remove. Unlock it only when no agent is using it, then check again.
git worktree unlock ~/code/shop/.claude/worktrees/fix-login
Safe shop-billing can go
Run it inside ~/code/shop. No --force: git refuses if anything changed since the check.
git worktree remove ~/code/shop-billing
The branch billing-page is kept. Delete it later with git branch -d billing-page if you want.
Never shop-search is kept: 3 changed files
git refuses to remove a worktree with changes. Adding --force would delete them with the folder.
Commit the changes, or open the folder and decide. It was also used 2 days ago.
Careful shop-ios is kept: 2 unpushed commits
git would remove it, and the branch keeps the commits, but they exist only on this Mac.
Push ios-widgets first, then check again.
Deleted a worktree folder by hand? git still lists it. Preview, then prune the stale entry.
git worktree prune --dry-run
git worktree prune
Prune also drops a worktree on a disk that is not mounted. Lock those with git worktree lock.
On this page
- Step 1: list every worktree
- Step 2: check what a worktree still holds
- How do I remove a git worktree?
- Is git worktree remove --force safe?
- What happens to the branch when I remove a worktree?
- Prune, lock and repair
- Where do AI coding agents create worktrees?
- Why do worktrees take so much space?
- When is it safe to remove a worktree?
- Questions
A worktree is an extra working folder linked to one repository, so you can have several branches checked out at once. AI coding agents now create them by the dozen. To clean up git worktrees safely, let git do the removal: deleting the folder yourself leaves a stale registration behind, and forcing it can delete work. The git worktree commands below follow the git-worktree documentation, and the behavior described was checked with git 2.39.
Step 1: list every worktree
One command lists every worktree with its path, commit and branch, and removes nothing.
git worktree list
Shows the main worktree and each linked one with its path, commit and branch. Removes nothing.
git worktree list --porcelain
The same list in a stable format for scripts. It adds locked and prunable lines, so you can see which worktrees are locked and which folders are already missing.
Step 2: check what a worktree still holds
Run these inside the worktree before removing it. All of them only read.
git status --short --ignored
Lists modified, untracked and ignored files. Ignored files (lines starting with !!) are the ones people forget: .env files, local databases, build output.
git log @{upstream}..HEAD --oneline
Lists commits not yet pushed. If git says there is no upstream, the branch was never pushed and its commits exist only on this Mac.
git merge-base --is-ancestor HEAD main && echo merged
Prints merged when the worktree's commit is already in main. Use your default branch name. A squash merge will not show up here, so check the pull request too.
How do I remove a git worktree?
Remove a worktree with git worktree remove, not by deleting the folder, so git drops its registration too.
git worktree remove <path>
Deletes the worktree folder and its registration. Git's rule: only clean worktrees can be removed, meaning no untracked files and no changes to tracked files. Worktrees with submodules need --force, and the main worktree cannot be removed at all.
Ignored files go with the folder. Git's definition of clean does not count ignored files, so git worktree remove deletes a git-ignored .env, local database or secrets file without asking, even without --force. Check git status --ignored first and copy out anything that exists nowhere else.
Is git worktree remove --force safe?
Not by default: --force deletes work that git would otherwise protect.
The docs say remove refuses an unclean worktree unless --force is used, and that a locked worktree needs --force twice. Forcing means:
- Untracked files that were never committed are deleted.
- Uncommitted changes to tracked files are deleted.
- Twice, it overrides a lock that someone or some tool set on purpose.
Git's refusal is the safety check. When it refuses, read the message, commit or stash what matters, and run plain remove again.
What happens to the branch when I remove a worktree?
The git-worktree page says nothing about branches, and remove leaves the branch in place. Your commits are safe in the repository after the folder is gone.
git branch -d <branch>
Deletes the branch only if it is merged. It also refuses while any worktree still has the branch checked out.
git branch -D <branch>
Deletes it even if unmerged. Its commits then survive only in the reflog for a while, so use this only when you are sure.
Prune, lock and repair
git worktree prune --dry-run
Reports which registrations prune would remove. Removes nothing.
git worktree prune
Removes entries in $GIT_DIR/worktrees whose folders are missing. Useful after deleting a folder by hand. Git also prunes stale entries on its own, per gc.worktreePruneExpire. A worktree on an unplugged disk counts as missing, so prune drops it too.
git worktree lock --reason "on external SSD" <path>
Protects a worktree from pruning, moving and deletion. The docs recommend it for worktrees on a portable device or network share. git worktree unlock <path> lifts it.
git worktree repair
Re-links worktrees after you moved the main repository or a worktree by hand.
Where do AI coding agents create worktrees?
Agents often leave worktrees behind. These are the locations their own documentation gives, except where noted.
| Tool | Location | Own cleanup |
|---|---|---|
| Claude Code | <repo>/.claude/worktrees/<name>/, branch worktree-<name> | Removes clean unnamed worktrees on exit and asks about ones with work; a periodic sweep skips any with changes, untracked files or unpushed commits |
| Codex app | $CODEX_HOME/worktrees | Keeps the 15 most recent managed worktrees by default and saves a snapshot before deleting one |
| Cursor | Not in its docs; Cursor staff on its forum point to ~/.cursor/worktrees/<repo> | Settings cursor.worktreeCleanupIntervalHours and cursor.worktreeMaxCount |
| Conductor | ~/conductor/workspaces/<repo>/<workspace> | Not documented |
Claude Code's docs say a worktree left behind can be removed with git worktree remove, and to run git worktree unlock first if git says it is locked. Its docs also suggest --force for worktrees with changes; check them as in step 2 before you do.
Why do worktrees take so much space?
Each worktree is a full checkout with its own build output, so many worktrees mean many copies of the same dependencies.
Claude Code's docs describe each worktree as a fresh checkout where you set up your development environment again. Every worktree gets its own node_modules, target, .build, .venv or Pods, and these are git-ignored, so git worktree list never shows their size.
du -sh .claude/worktrees/*
Shows the size of each Claude Code worktree, from the repository root. Removes nothing.
git clean -ndX
Run inside a worktree, lists every ignored file and folder git would delete. Removes nothing. Do not run it without -n: -X includes .env files too.
To free space but keep a worktree you still use, delete only its build folders, or use the tool's own clean command, such as cargo clean for target. For Node and Xcode, see node_modules and npm caches and Xcode DerivedData. Worktrees are developer-only clutter that no Disk Cleanup on macOS checklist covers.
When is it safe to remove a worktree?
Remove a whole worktree only when two independent signals agree and nothing blocks it.
- Anchor: its branch is merged into the default branch, squash merged, or deleted on the remote.
- Second signal: untouched for 14 days or more, sitting in a temp folder, or made by an agent.
- Blockers, any one keeps it: changed or untracked files, unpushed or never-pushed commits, a lock, populated submodules, a process with files open inside, or activity in the last 14 days.
Find stale worktrees in every repo, and keep the branch
Hoardless finds worktrees across your home folder, including the Claude Code, Codex, Cursor and Conductor folders above and agent scratch folders in /private/tmp, and applies the rule above. It reads remote state only from refs fetched in the last 7 days and never fetches. Removal runs git worktree remove without --force, re-checks every blocker first, then prunes only when a dry run shows nothing else would be dropped. If git refuses, you see git's message and nothing else runs: no retry, never an rm fallback. The branch is kept, and the undo log records the command to recreate the worktree; build output inside is not recoverable. For worktrees you keep, Free build folders moves only git-ignored build folders to the Trash.
14-day full trial. macOS 14 or later.
Questions
How do I remove a git worktree?
Run git worktree remove <path> from any checkout of the repository. Git removes the folder and its registration, and refuses if the worktree has untracked or modified files.
What does git worktree prune do?
It removes administrative entries in $GIT_DIR/worktrees for worktrees whose folders are missing. Run it with --dry-run first to see what it would drop.
Does removing a worktree delete the branch?
No. The branch stays in the repository. Delete it with git branch -d <branch> once it is merged.
Why does git say the worktree is locked?
Someone ran git worktree lock on it, or a tool did. Claude Code, for example, leaves a lock on worktrees from its non-interactive runs until a later cleanup sweep. Make sure nothing is using it, then run git worktree unlock <path>.
Can I just rm -rf a worktree folder?
The folder goes, but git still lists the worktree, and its branch still counts as checked out, until you run git worktree prune. Use git worktree remove instead.
When is git worktree remove --force safe?
Only after git status --ignored shows nothing you need, because it deletes untracked and modified files. A locked worktree needs it twice, which also overrides the lock.
Where does Claude Code put worktrees?
In .claude/worktrees/<name>/ at the repository root, on a branch named worktree-<name>. Its docs suggest adding .claude/worktrees/ to .gitignore.
Why do my worktrees take up so much space?
Each one is a full checkout with its own dependencies and build output, such as node_modules, target or .build. Ten worktrees can mean ten copies.
New guides by email
New guides and Hoardless releases, twice a month at most.
Confirm first. Unsubscribe in one click. Privacy.