@devries-cameron20 / t3code-1 / commits / 5b7af7b9f6
Fork 0

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

Fix session not restarting when switching to a worktree branch

When selecting a branch that lives in a different worktree, the store updated the thread's worktreePath but the running session kept its original cwd. The agent continued operating in the old directory. - SET_THREAD_BRANCH now clears the session when worktreePath changes - BranchToolbar stops the server-side session before dispatching the branch change, so the next message creates a fresh session with the correct cwd Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Julius Marminge committed Feb 11, 2026 at 15:33 UTC 5b7af7b9f641b8e8f1bdffabcdd423d3f09e9d80
2 files changed +20 -6
apps/web/src/components/BranchToolbar.tsx
+6
@@ -108,6 +108,12 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
108
109 const setThreadBranch = (branch: string | null, worktreePath: string | null) => {
110 if (!activeThreadId) return;
111 + // If the effective cwd is about to change, stop the running session so the
112 + // next message creates a new one with the correct cwd.
113 + const sessionId = activeThread?.session?.sessionId;
114 + if (sessionId && worktreePath !== activeWorktreePath) {
115 + void api?.providers.stopSession({ sessionId }).catch(() => undefined);
116 + }
117 dispatch({ type: "SET_THREAD_BRANCH", threadId: activeThreadId, branch, worktreePath });
118 };
119
apps/web/src/store.ts
+14 -6
@@ -376,15 +376,23 @@ export function reducer(state: AppState, action: Action): AppState {
376 })),
377 };
378
379 - case "SET_THREAD_BRANCH":
379 + case "SET_THREAD_BRANCH": {
380 return {
381 ...state,
382 - threads: updateThread(state.threads, action.threadId, (t) => ({
383 - ...t,
384 - branch: action.branch,
385 - worktreePath: action.worktreePath,
386 - })),
382 + threads: updateThread(state.threads, action.threadId, (t) => {
383 + // When the effective cwd changes (worktreePath differs), the old
384 + // session is no longer valid — clear it so ensureSession creates a
385 + // new one with the correct cwd on the next message.
386 + const cwdChanged = t.worktreePath !== action.worktreePath;
387 + return {
388 + ...t,
389 + branch: action.branch,
390 + worktreePath: action.worktreePath,
391 + ...(cwdChanged ? { session: null } : {}),
392 + };
393 + }),
394 };
395 + }
396
397 case "SET_RUNTIME_MODE":
398 return {