Repository navigation
Description
Bug Description
Component: Skill - git-worktree
Summary: The list and cleanup commands in worktree-manager.sh report "No worktrees found" even when worktrees exist, because the script checks if .git is a directory (-d), but in git worktrees .git is a regular file containing a gitdir: pointer.
Environment
- Plugin Version: compound-engineering v2.30.0 (commit: e4ff6a8)
- Claude Code Version: 2.1.37
- OS: Darwin 25.2.0 arm64 (macOS)
What Happened
Running /git-worktree list with 3 existing worktrees in .worktrees/ reports:
Available worktrees:
No worktrees found
Main repository:
Branch: master
Meanwhile git worktree list correctly shows all 3:
/path/to/repo f760365 [master]
/path/to/repo/.worktrees/feat-worktree-support b2d18ab [feat/worktree-support]
/path/to/repo/.worktrees/test-port-2 f760365 [test-port-2]
/path/to/repo/.worktrees/test-port-3 f760365 [test-port-3]
The cleanup command is also affected — it silently finds no worktrees to clean.
Expected Behavior
/git-worktree list should detect and display all 3 worktrees. /git-worktree cleanup should find and offer to remove inactive worktrees.
Steps to Reproduce
- Create a worktree:
bash worktree-manager.sh create test-branch - Return to main repo
- Run
bash worktree-manager.sh list - Observe: "No worktrees found" despite the worktree existing
Root Cause
In worktree-manager.sh, both list_worktrees() (line 137) and cleanup_worktrees() (line 234) use:
if [[ -d "$worktree_path" && -d "$worktree_path/.git" ]]; thenThe -d flag checks if .git is a directory. However, in git worktrees, .git is a regular file containing a gitdir: pointer back to the main repository's .git/worktrees/ directory. This is standard git behavior — only the main working tree has a .git directory.
Verified:
$ ls -la .worktrees/feat-worktree-support/.git
-rw-r--r-- 1 user staff 100 Feb 8 09:17 .worktrees/feat-worktree-support/.git
$ cat .worktrees/feat-worktree-support/.git
gitdir: /path/to/repo/.git/worktrees/feat-worktree-supportSuggested Fix
Change -d to -e (exists) on both lines 137 and 234:
# Line 137 (list_worktrees)
- if [[ -d "$worktree_path" && -d "$worktree_path/.git" ]]; then
+ if [[ -d "$worktree_path" && -e "$worktree_path/.git" ]]; then
# Line 234 (cleanup_worktrees)
- if [[ -d "$worktree_path" && -d "$worktree_path/.git" ]]; then
+ if [[ -d "$worktree_path" && -e "$worktree_path/.git" ]]; thenUsing -e is preferred over -f because it matches both the file case (worktrees) and directory case (if the main repo directory were ever checked), making the check robust for all scenarios.
Additional Context
- The
create_worktree()function is not affected because it doesn't use this check - PR Remove the confirmation prompt when creating git worktrees #144 addresses a separate worktree issue (confirmation prompts) and does not fix this
Reported via /report-bug command
Activity
fix(git-worktree): detect worktrees where .git is a file, not a direc…