From 13e85b1549ae08c824a16cce57c194837d922cce Mon Sep 17 00:00:00 2001 From: Yuvraj Angad Singh <36276913+yuvrajangadsingh@users.noreply.github.com> Date: Sat, 31 Jan 2026 04:29:20 +0530 Subject: [PATCH] fix: update file search directory when session CWD changes (#9279) ## Summary Fixes #9041 - Adds update_search_dir() method to FileSearchManager to allow updating the search directory after initialization - Calls this method when the session CWD changes: new session, resume, or fork ## Problem The FileSearchManager was created once with the initial search_dir and never updated. When a user: 1. Starts Codex in a non-git directory (e.g., /tmp/random) 2. Resumes or forks a session from a different workspace 3. The @filename lookup still searched the original directory This caused no matches to be returned even when files existed in the current workspace. ## Solution Update FileSearchManager.search_dir whenever the session working directory changes: - AppEvent::NewSession: Use current config CWD - SessionSelection::Resume: Use resumed session CWD - SessionSelection::Fork: Use forked session CWD ## Test plan - [ ] Start Codex in /tmp/test-dir (non-git) - [ ] Resume a session from a project with actual files - [ ] Verify @filename returns matches from the resumed session directory --------- Co-authored-by: Eric Traut --- codex-rs/tui/src/app.rs | 5 +---- codex-rs/tui/src/file_search.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs index 7ed9d0b035..7bbbb2f997 100644 --- a/codex-rs/tui/src/app.rs +++ b/codex-rs/tui/src/app.rs @@ -1370,10 +1370,7 @@ impl App { self.shutdown_current_thread().await; self.config = resume_config; tui.set_notification_method(self.config.tui_notification_method); - self.file_search = FileSearchManager::new( - self.config.cwd.clone(), - self.app_event_tx.clone(), - ); + self.file_search.update_search_dir(self.config.cwd.clone()); let init = self.chatwidget_init_for_forked_or_resumed_thread( tui, self.config.clone(), diff --git a/codex-rs/tui/src/file_search.rs b/codex-rs/tui/src/file_search.rs index ff55ac1274..90e2f7f149 100644 --- a/codex-rs/tui/src/file_search.rs +++ b/codex-rs/tui/src/file_search.rs @@ -38,6 +38,17 @@ impl FileSearchManager { } } + /// Updates the directory used for file searches. + /// This should be called when the session's CWD changes on resume. + /// Drops the current session so it will be recreated with the new directory on next query. + pub fn update_search_dir(&mut self, new_dir: PathBuf) { + self.search_dir = new_dir; + #[expect(clippy::unwrap_used)] + let mut st = self.state.lock().unwrap(); + st.session.take(); + st.latest_query.clear(); + } + /// Call whenever the user edits the `@` token. pub fn on_user_query(&self, query: String) { #[expect(clippy::unwrap_used)]