@devries-cameron20 / t3code-1 / commits / 9442019235
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Filter out stale worktree paths from branch listing

Worktrees in /tmp or other ephemeral locations get cleaned by the OS but remain in git's worktree list as "prunable". These stale entries caused branches to show a worktree label pointing at a non-existent directory, leading to broken state when selected. Now validates each worktree path with existsSync before including it in the branch→worktreePath map. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Julius Marminge committed Feb 11, 2026 at 15:48 UTC 94420192359d68c03241f03f47cf8d670abafa15
1 file changed +3
apps/server/src/git.ts
+3
@@ -1,4 +1,5 @@
1 import { spawn } from "node:child_process";
2 +import fs from "node:fs";
3 import os from "node:os";
4 import path from "node:path";
5
@@ -131,12 +132,14 @@ export async function listGitBranches(input: GitListBranchesInput): Promise<GitL
132 defaultRef.code === 0 ? defaultRef.stdout.trim().replace(/^refs\/remotes\/origin\//, "") : null;
133
134 // Build branch-name → worktree-path map from porcelain output.
135 + // Only include worktrees whose directories still exist on disk (skip prunable/stale ones).
136 const worktreeMap = new Map<string, string>();
137 if (worktreeList.code === 0) {
138 let currentPath: string | null = null;
139 for (const line of worktreeList.stdout.split("\n")) {
140 if (line.startsWith("worktree ")) {
141 currentPath = line.slice("worktree ".length);
142 + if (!fs.existsSync(currentPath)) currentPath = null;
143 } else if (line.startsWith("branch refs/heads/") && currentPath) {
144 worktreeMap.set(line.slice("branch refs/heads/".length), currentPath);
145 } else if (line === "") {