You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(plugin): resolve worktree paths from main repo root, add cleanup
Worktree paths now use `git worktree list` to always resolve to the main
repo root instead of `git rev-parse --show-toplevel`, which incorrectly
resolves to a worktree root when already inside one.
Also adds worktree cleanup to /reset and a new /cleanup skill for
removing orphaned worktrees from interrupted sessions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
**User-facing command** - Run this to clean up stale worktrees left behind by interrupted sessions.
19
+
20
+
Scans `.ai-dlc/worktrees/` for worktree directories and removes any that are orphaned (the backing git worktree entry is stale or the directory is left over from a crashed session).
21
+
22
+
This does not:
23
+
- Clear AI-DLC state (use `/reset` for that)
24
+
- Delete branches or commits
25
+
- Affect active worktrees with running sessions
26
+
27
+
## Implementation
28
+
29
+
### Pre-check: Reject Cowork Mode
30
+
31
+
```bash
32
+
if [ "${CLAUDE_CODE_IS_COWORK:-}"="1" ];then
33
+
echo"ERROR: /cleanup cannot run in cowork mode."
34
+
echo"Run this in a full Claude Code CLI session."
35
+
exit 1
36
+
fi
37
+
```
38
+
39
+
If `CLAUDE_CODE_IS_COWORK=1`, stop immediately with the message above. Do NOT proceed.
40
+
41
+
### Step 1: Discover Worktrees
42
+
43
+
```bash
44
+
REPO_ROOT=$(git worktree list --porcelain | head -1 | sed 's/^worktree //')
45
+
WORKTREES_DIR="${REPO_ROOT}/.ai-dlc/worktrees"
46
+
47
+
if [ !-d"$WORKTREES_DIR" ];then
48
+
echo"No .ai-dlc/worktrees/ directory found. Nothing to clean up."
49
+
exit 0
50
+
fi
51
+
52
+
# List all directories in .ai-dlc/worktrees/
53
+
DIRS=$(find "$WORKTREES_DIR" -mindepth 1 -maxdepth 1 -type d 2>/dev/null)
54
+
if [ -z"$DIRS" ];then
55
+
echo"No worktree directories found. Nothing to clean up."
56
+
exit 0
57
+
fi
58
+
```
59
+
60
+
### Step 2: Identify Orphaned Worktrees
61
+
62
+
```bash
63
+
# Get list of valid worktree paths from git
64
+
VALID_WORKTREES=$(git worktree list --porcelain | grep '^worktree '| sed 's/^worktree //')
65
+
66
+
ORPHANED=()
67
+
ACTIVE=()
68
+
69
+
fordirin$DIRS;do
70
+
ifecho"$VALID_WORKTREES"| grep -qF "$dir";then
71
+
ACTIVE+=("$(basename "$dir")")
72
+
else
73
+
ORPHANED+=("$(basename "$dir")")
74
+
fi
75
+
done
76
+
```
77
+
78
+
### Step 3: Report and Confirm
79
+
80
+
Show the user what was found:
81
+
82
+
```
83
+
## AI-DLC Worktree Cleanup
84
+
85
+
**Active worktrees:** {count}
86
+
{list of active worktree names, if any}
87
+
88
+
**Orphaned worktrees:** {count}
89
+
{list of orphaned worktree names, if any}
90
+
```
91
+
92
+
If there are orphaned worktrees, ask the user to confirm removal using `AskUserQuestion`.
93
+
94
+
If there are no orphaned entries but there are active worktrees, ask whether to force-remove all worktrees (with a warning that this will interrupt any running sessions).
95
+
96
+
If there is nothing to clean up, output:
97
+
98
+
```
99
+
No orphaned worktrees found. Everything is clean.
100
+
```
101
+
102
+
### Step 4: Remove
103
+
104
+
```bash
105
+
REPO_ROOT=$(git worktree list --porcelain | head -1 | sed 's/^worktree //')
106
+
107
+
# Remove orphaned directories (no valid git worktree entry)
108
+
fornamein"${ORPHANED[@]}";do
109
+
rm -rf "${REPO_ROOT}/.ai-dlc/worktrees/${name}"
110
+
done
111
+
112
+
# If user chose to force-remove active worktrees too:
Copy file name to clipboardExpand all lines: plugin/skills/elaborate/SKILL.md
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,15 +159,21 @@ If no slug provided, or the intent doesn't exist, proceed to Phase 1.
159
159
**Start fresh cleanup:** When the user chooses "Start fresh", remove the intent worktree and its branch (if they exist from a prior elaboration attempt), then clean up any leftover `.ai-dlc/{slug}/` directory:
0 commit comments