fix(terminal): restore configured cwd after login profile scripts (salvage #14796)#17205
Merged
Conversation
init_session() runs a login shell bootstrap that sources profile scripts (.bashrc, .bash_profile, etc.) before capturing pwd. If any profile script changes the working directory, the captured cwd overwrites the configured terminal.cwd value — so terminal commands run in the wrong directory despite the TUI banner showing the configured path. Add an explicit 'builtin cd' to the configured cwd in the bootstrap script, after profile sourcing but before pwd capture, ensuring the configured terminal.cwd is always what gets recorded. Fixes #14044
Collaborator
This was referenced Apr 29, 2026
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvages #14796 from @Tranquil-Flow.
Closes #14044.
Summary
Terminal commands now run in the configured
terminal.cwdeven when the user's.bashrc/.bash_profileissues acdduring login.Root cause
init_session()runs abash -l -cbootstrap to snapshot the login environment, then capturespwd -Pintoself.cwd. When a profile script doescd ~(common with version managers like nvm, pyenv, frum), the captured cwd silently overwrites the configuredterminal.cwd. The v0.11.0 fix (#12983) passedcwd=self.cwdtoPopen, which fixed the default case but not this one — bash stillcd'd during login beforepwdran.Fix
Add an explicit
builtin cd $cwdinside the bootstrap script, after profile sourcing but beforepwd -Pcapture. Applies to all backends viabase.py, not just local.Validation
tests/tools/test_init_session_cwd_respect.py— 4/4 pass (contributor tests)tests/tools/test_base_environment.py tests/tools/test_local_shell_init.py— 31/31 passcd $HOME, launched from a third directory, config'dterminal.cwd: /some/project→pwd -Preturns/some/projectas expected.Credit
@Tranquil-Flow authored the fix and tests in #14796. Cherry-picked onto current main with authorship preserved.