From 395d5c74f713454ed3b72b403d5bbabe120dd4e9 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Mon, 23 Mar 2026 16:35:29 -0700 Subject: [PATCH] fix: sidebar-agent validates cwd before spawning claude The queue entry may reference a worktree that was cleaned up between sessions. Now falls back to process.cwd() if the path doesn't exist, preventing silent spawn failures. Co-Authored-By: Claude Opus 4.6 (1M context) --- browse/src/sidebar-agent.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browse/src/sidebar-agent.ts b/browse/src/sidebar-agent.ts index 7972c7fb..76c75d19 100644 --- a/browse/src/sidebar-agent.ts +++ b/browse/src/sidebar-agent.ts @@ -162,9 +162,13 @@ async function askClaude(queueEntry: any): Promise { let claudeArgs = ['-p', prompt, '--output-format', 'stream-json', '--verbose', '--allowedTools', 'Bash,Read,Glob,Grep']; + // Validate cwd exists — queue may reference a stale worktree + let effectiveCwd = cwd || process.cwd(); + try { fs.accessSync(effectiveCwd); } catch { effectiveCwd = process.cwd(); } + const proc = spawn('claude', claudeArgs, { stdio: ['pipe', 'pipe', 'pipe'], - cwd: cwd || process.cwd(), + cwd: effectiveCwd, env: { ...process.env, BROWSE_STATE_FILE: stateFile || '' }, });