Skip to content

[compound-engineering] Bug: git-worktree list/cleanup fails to detect worktrees (.git file vs directory check) #158

Closed

Description

@dalley

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

  1. Create a worktree: bash worktree-manager.sh create test-branch
  2. Return to main repo
  3. Run bash worktree-manager.sh list
  4. 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" ]]; then

The -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-support

Suggested 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" ]]; then

Using -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


Reported via /report-bug command

Activity

  1. added a commit that references this issue on Feb 8, 2026
    ecbd77a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions