diff --git a/ui/desktop/src/components/ChatInput.tsx b/ui/desktop/src/components/ChatInput.tsx
index 1f15d921a8db..13ab9b9de1e9 100644
--- a/ui/desktop/src/components/ChatInput.tsx
+++ b/ui/desktop/src/components/ChatInput.tsx
@@ -1239,7 +1239,7 @@ export default function ChatInput({
{/* Secondary actions and controls row below input */}
{/* Directory path */}
-
0} className="mr-0" />
+
{/* Attach button */}
diff --git a/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx b/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx
index c51bea91c9b7..4bf199988d39 100644
--- a/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx
+++ b/ui/desktop/src/components/bottom_menu/DirSwitcher.tsx
@@ -3,22 +3,14 @@ import { FolderDot } from 'lucide-react';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/Tooltip';
interface DirSwitcherProps {
- hasMessages?: boolean;
className?: string;
}
-export const DirSwitcher: React.FC = ({
- hasMessages = false,
- className = '',
-}) => {
+export const DirSwitcher: React.FC = ({ className = '' }) => {
const [isTooltipOpen, setIsTooltipOpen] = useState(false);
const handleDirectoryChange = async () => {
- if (hasMessages) {
- window.electron.directoryChooser();
- } else {
- window.electron.directoryChooser(true);
- }
+ window.electron.directoryChooser(true);
};
return (
diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts
index 81e828610df2..589acd2d4b64 100644
--- a/ui/desktop/src/main.ts
+++ b/ui/desktop/src/main.ts
@@ -944,8 +944,60 @@ const buildRecentFilesMenu = () => {
const openDirectoryDialog = async (
replaceWindow: boolean = false
): Promise => {
+ // Get the current working directory from the focused window
+ let defaultPath: string | undefined;
+ const currentWindow = BrowserWindow.getFocusedWindow();
+
+ if (currentWindow) {
+ try {
+ const currentWorkingDir = await currentWindow.webContents.executeJavaScript(
+ `window.appConfig ? window.appConfig.get('GOOSE_WORKING_DIR') : null`
+ );
+
+ if (currentWorkingDir && typeof currentWorkingDir === 'string') {
+ // Verify the directory exists before using it as default
+ try {
+ const stats = fsSync.lstatSync(currentWorkingDir);
+ if (stats.isDirectory()) {
+ defaultPath = currentWorkingDir;
+ }
+ } catch (error) {
+ if (error && typeof error === 'object' && 'code' in error) {
+ const fsError = error as { code?: string; message?: string };
+ if (
+ fsError.code === 'ENOENT' ||
+ fsError.code === 'EACCES' ||
+ fsError.code === 'EPERM'
+ ) {
+ console.warn(
+ `Current working directory not accessible (${fsError.code}): ${currentWorkingDir}, falling back to home directory`
+ );
+ defaultPath = os.homedir();
+ } else {
+ console.warn(
+ `Unexpected filesystem error (${fsError.code}) for directory ${currentWorkingDir}:`,
+ fsError.message
+ );
+ defaultPath = os.homedir();
+ }
+ } else {
+ console.warn(`Unexpected error checking directory ${currentWorkingDir}:`, error);
+ defaultPath = os.homedir();
+ }
+ }
+ }
+ } catch (error) {
+ console.warn('Failed to get current working directory from window:', error);
+ }
+ }
+
+ if (!defaultPath) {
+ defaultPath = os.homedir();
+ }
+
const result = (await dialog.showOpenDialog({
properties: ['openFile', 'openDirectory', 'createDirectory'],
+ defaultPath: defaultPath,
})) as unknown as OpenDialogReturnValue;
if (!result.canceled && result.filePaths.length > 0) {