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 || '' }, });