From 2da82900409fe231fb913df2c61b580f1a453924 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 26 Feb 2026 18:29:10 -0800 Subject: [PATCH] Require base branch before first send in worktree mode - show an explicit error when New worktree mode has no base branch selected - sync thread branch/worktree path immediately after creation - run setup script in the new worktree terminal before continuing Co-authored-by: codex --- apps/web/src/components/ChatView.tsx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 95ab08d6c8f25513d1f64879b033c0a0b50aa934..ea9e11ed29b7fa032db8b3b9c7688d8a3bc77568 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -1424,6 +1424,19 @@ export default function ChatView({ threadId }: ChatViewProps) { }, ]); + // In worktree mode, require an explicit base branch so we don't silently + // fall back to local execution when branch selection is missing. + const shouldCreateWorktree = + activeThread.messages.length === 0 && envMode === "worktree" && !activeThread.worktreePath; + if (shouldCreateWorktree && !activeThread.branch) { + dispatch({ + type: "SET_ERROR", + threadId: activeThread.id, + error: "Select a base branch before sending in New worktree mode.", + }); + return; + } + setThreadError(threadIdForSend, null); promptRef.current = ""; setPrompt(""); @@ -1449,11 +1462,20 @@ export default function ChatView({ threadId }: ChatViewProps) { branch: result.worktree.branch, worktreePath: result.worktree.path, }); + // Keep local thread state in sync immediately so terminal drawer opens + // with the worktree cwd/env instead of briefly using the project root. + dispatch({ + type: "SET_THREAD_BRANCH", + threadId: activeThread.id, + branch: result.worktree.branch, + worktreePath: result.worktree.path, + }); const setupScript = setupProjectScript(activeProject.scripts); if (setupScript) { - void runProjectScript(setupScript, { + await runProjectScript(setupScript, { cwd: result.worktree.path, worktreePath: result.worktree.path, + preferNewTerminal: true, rememberAsLastInvoked: false, }); } -- 2.54.0