The best way to control Claude Code, Codex and more from any computer or phone
fix(web): deleting a thread no longer offers to remove a shared worktree (#24489)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 30, 2026 at 16:06 UTC
f5bc64b7b7bcc2ff021febbfcf96f0b5043016cf
2 files changed
+35
-15
apps/web/src/worktreeCleanup.test.ts
+23
@@ -51,6 +51,29 @@ describe("getOrphanedWorktreePathForThread", () => {
51
expect(result).toBeNull();
52
});
53
54
+ it.each([
55
+ ["/tmp/repo/worktrees/feature-a", "/tmp/repo/worktrees/feature-a/"],
56
+ ["/tmp/repo/worktrees/feature-a", "/tmp/repo/worktrees/feature-a//"],
57
+ ["C:\\repo\\worktrees\\feature-a", "c:/repo/worktrees/feature-a/"],
58
+ ])("treats %s and %s as the same worktree", (targetPath, otherPath) => {
59
+ const threads = [
60
+ makeThread({ id: ThreadId.make("thread-1"), worktreePath: targetPath }),
61
+ makeThread({ id: ThreadId.make("thread-2"), worktreePath: otherPath }),
62
+ ];
63
+ expect(getOrphanedWorktreePathForThread(threads, ThreadId.make("thread-1"))).toBeNull();
64
+ expect(getOrphanedWorktreePathForThread(threads, ThreadId.make("thread-2"))).toBeNull();
65
+ });
66
+
67
+ it("keeps case-sensitive POSIX worktrees apart", () => {
68
+ const threads = [
69
+ makeThread({ id: ThreadId.make("thread-1"), worktreePath: "/tmp/repo/worktrees/Feature" }),
70
+ makeThread({ id: ThreadId.make("thread-2"), worktreePath: "/tmp/repo/worktrees/feature" }),
71
+ ];
72
+ expect(getOrphanedWorktreePathForThread(threads, ThreadId.make("thread-1"))).toBe(
73
+ "/tmp/repo/worktrees/Feature",
74
+ );
75
+ });
76
+
77
it("ignores threads linked to different worktrees", () => {
78
const threads = [
79
makeThread({
apps/web/src/worktreeCleanup.ts
+12
-15
@@ -1,12 +1,6 @@
1
-import type { ThreadShell } from "./types";
1
+import { normalizeProjectPathForComparison } from "@t3tools/shared/path";
2
3
-function normalizeWorktreePath(path: string | null): string | null {
4
- const trimmed = path?.trim();
5
- if (!trimmed) {
6
- return null;
7
- }
8
- return trimmed;
9
-}
3
+import type { ThreadShell } from "./types";
4
5
export function getOrphanedWorktreePathForThread(
6
threads: ReadonlyArray<Pick<ThreadShell, "id" | "worktreePath">>,
@@ -17,17 +11,20 @@ export function getOrphanedWorktreePathForThread(
11
return null;
12
}
13
20
- const targetWorktreePath = normalizeWorktreePath(targetThread.worktreePath);
14
+ const targetWorktreePath = targetThread.worktreePath?.trim();
15
if (!targetWorktreePath) {
16
return null;
17
}
18
25
- const isShared = threads.some((thread) => {
26
- if (thread.id === threadId) {
27
- return false;
28
- }
29
- return normalizeWorktreePath(thread.worktreePath) === targetWorktreePath;
30
- });
19
+ // Threads can store one worktree as `/repo/wt` and `/repo/wt/`, and
20
+ // confirming deletion force-removes the checkout for every thread on it.
21
+ const targetKey = normalizeProjectPathForComparison(targetWorktreePath);
22
+ const isShared = threads.some(
23
+ (thread) =>
24
+ thread.id !== threadId &&
25
+ thread.worktreePath !== null &&
26
+ normalizeProjectPathForComparison(thread.worktreePath) === targetKey,
27
+ );
28
29
return isShared ? null : targetWorktreePath;
30
}