From 9f586cb1610c8290cdc752993f590d3423117532 Mon Sep 17 00:00:00 2001 From: Robert Mcgregor <38837341+exitcode0@users.noreply.github.com> Date: Sat, 31 Jan 2026 10:00:42 +1100 Subject: [PATCH] fix(ui): preserve working directory when creating new chat (#6789) Co-authored-by: Claude Opus 4.5 --- .../src/components/bottom_menu/DirSwitcher.tsx | 2 ++ ui/desktop/src/utils/workingDir.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx b/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx index 26c8dc39..481141b1 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 413e38f6..d99c448f 100644 --- a/ui/desktop/src/utils/workingDir.ts +++ b/ui/desktop/src/utils/workingDir.ts @@ -1,3 +1,11 @@ -export const getInitialWorkingDir = (): string => { - return (window.appConfig?.get('GOOSE_WORKING_DIR') as string) || ''; +// 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 => { + // Use the current dir if set, otherwise fall back to initial config + return currentWorkingDir ?? (window.appConfig?.get('GOOSE_WORKING_DIR') as string) ?? ''; };