source dump of claude code
at main 27 lines 847 B view raw
1import { execFile as execFileCb } from 'child_process' 2import { promisify } from 'util' 3 4const execFileAsync = promisify(execFileCb) 5 6/** 7 * Portable worktree detection using only child_process — no analytics, 8 * no bootstrap deps, no execa. Used by listSessionsImpl.ts (SDK) and 9 * anywhere that needs worktree paths without pulling in the CLI 10 * dependency chain (execa → cross-spawn → which). 11 */ 12export async function getWorktreePathsPortable(cwd: string): Promise<string[]> { 13 try { 14 const { stdout } = await execFileAsync( 15 'git', 16 ['worktree', 'list', '--porcelain'], 17 { cwd, timeout: 5000 }, 18 ) 19 if (!stdout) return [] 20 return stdout 21 .split('\n') 22 .filter(line => line.startsWith('worktree ')) 23 .map(line => line.slice('worktree '.length).normalize('NFC')) 24 } catch { 25 return [] 26 } 27}