From 2160d5bbb810e1595cd37cef7dea9f0e09959cbf Mon Sep 17 00:00:00 2001 From: Rob McGregor <38837341+exitcode0@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:49:23 +1100 Subject: [PATCH] fix(ui): preserve working directory when creating new chat Track the current working directory in module-level state so that creating a new chat uses the user's most recent directory choice, not the original directory from window creation. Known limitation: hard refresh resets to the original directory. Co-Authored-By: Claude Opus 4.5 --- ui/desktop/src/components/bottom_menu/DirSwitcher.tsx | 2 ++ ui/desktop/src/utils/workingDir.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx b/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx index 26c8dc399eae..481141b13acb 100644 --- a/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx +++ b/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx @@ -3,6 +3,7 @@ import { FolderDot } from 'lucide-react'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/Tooltip'; import { updateWorkingDir } from '../../api'; import { toast } from 'react-toastify'; +import { setCurrentWorkingDir } from '../../utils/workingDir'; interface DirSwitcherProps { className: string; @@ -42,6 +43,7 @@ export const DirSwitcher: React.FC = ({ const newDir = result.filePaths[0]; window.electron.addRecentDir(newDir); + setCurrentWorkingDir(newDir); if (sessionId) { onWorkingDirChange?.(newDir); diff --git a/ui/desktop/src/utils/workingDir.ts b/ui/desktop/src/utils/workingDir.ts index 413e38f6cc87..d99c448fe971 100644 --- a/ui/desktop/src/utils/workingDir.ts +++ b/ui/desktop/src/utils/workingDir.ts @@ -1,3 +1,11 @@ +// Track the current working dir for this window (updated when user changes it) +let currentWorkingDir: string | null = null; + +export const setCurrentWorkingDir = (dir: string): void => { + currentWorkingDir = dir; +}; + export const getInitialWorkingDir = (): string => { - return (window.appConfig?.get('GOOSE_WORKING_DIR') as string) || ''; + // Use the current dir if set, otherwise fall back to initial config + return currentWorkingDir ?? (window.appConfig?.get('GOOSE_WORKING_DIR') as string) ?? ''; };