fix(ui): preserve working directory when creating new chat#6789
fix(ui): preserve working directory when creating new chat#6789zanesq merged 1 commit intoblock:mainfrom
Conversation
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 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where creating a new chat window would use the original working directory from window creation instead of the user's most recent directory choice. The fix introduces module-level state to track the current working directory, which is updated when users change directories and consulted when creating new sessions.
Changes:
- Added module-level state tracking for the current working directory
- Modified
getInitialWorkingDir()to return the tracked directory when available - Integrated directory tracking into the
DirSwitchercomponent
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ui/desktop/src/utils/workingDir.ts | Added module-level state and setter function to track current working directory; modified getInitialWorkingDir() to prioritize tracked state |
| ui/desktop/src/components/bottom_menu/DirSwitcher.tsx | Imported and called setCurrentWorkingDir() when user selects a new directory to update module state |
| const newDir = result.filePaths[0]; | ||
|
|
||
| window.electron.addRecentDir(newDir); | ||
| setCurrentWorkingDir(newDir); |
There was a problem hiding this comment.
The Hub component (ui/desktop/src/components/Hub.tsx:40) maintains its own workingDir state initialized from getInitialWorkingDir(). When a user changes the directory in the Hub view, the module-level state is updated, but Hub's local state is not. This means if a user changes the directory while in Hub view, then creates a new chat, the new chat will get the updated directory from getInitialWorkingDir(), but Hub's ChatInput will still display the old directory. Consider calling onWorkingDirChange?.(newDir) unconditionally before the if (sessionId) check to ensure all components stay in sync.
* main: fix: fixed the broken release (#6887) feat: Streamable HTTP transport for ACP + goose-acp usage (#6741) Add Laminar for Observability (#6514) Missed a couple of places that hard code J for the newline key (#6853) fix(ui): preserve working directory when creating new chat (#6789) blog: add 5 tips for building MCP Apps that work (#6855) docs: session isolation (#6846) upgrade react and electron to latest (#6845) Fix: Small update UI settings prompt injection (#6830) Remove autogenerated .gooseignore files that don't belong in repo (#6824) Fix case-insensitive matching for builtin extension names (#6825) docs: cli newline keybinding (#6823) Update version to 1.22.0 (#6821) Refactor: move persisting extension to session outside of route (#6685) acp: load configured extensions and refactor tests (#6803)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Summary
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
hard refresh (command + shift + R) still causes a reset to the original directory
Type of Change
AI Assistance
Testing
These changes were tested manually by running the application locally using
just run-uiRelated Issues
Relates to #ISSUE_ID
Discussion: LINK (if any)
Screenshots/Demos (for UX changes)
Before:
After: