Skip to content

fix(terminal): restore configured cwd after login profile scripts (salvage #14796)#17205

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-9d57430b
Apr 29, 2026
Merged

fix(terminal): restore configured cwd after login profile scripts (salvage #14796)#17205
teknium1 merged 1 commit into
mainfrom
hermes/hermes-9d57430b

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvages #14796 from @Tranquil-Flow.

Closes #14044.

Summary

Terminal commands now run in the configured terminal.cwd even when the user's .bashrc / .bash_profile issues a cd during login.

Root cause

init_session() runs a bash -l -c bootstrap to snapshot the login environment, then captures pwd -P into self.cwd. When a profile script does cd ~ (common with version managers like nvm, pyenv, frum), the captured cwd silently overwrites the configured terminal.cwd. The v0.11.0 fix (#12983) passed cwd=self.cwd to Popen, which fixed the default case but not this one — bash still cd'd during login before pwd ran.

Fix

Add an explicit builtin cd $cwd inside the bootstrap script, after profile sourcing but before pwd -P capture. Applies to all backends via base.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 pass
  • E2E: real LocalEnvironment with a fake $HOME whose .bashrc does cd $HOME, launched from a third directory, config'd terminal.cwd: /some/projectpwd -P returns /some/project as expected.

Credit

@Tranquil-Flow authored the fix and tests in #14796. Cherry-picked onto current main with authorship preserved.

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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets tool/terminal Terminal execution and process management labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #14796 (salvaged from), #11708, #14828, #14831 — all address the same terminal.cwd login-profile override bug. This PR is the authoritative fix cherry-picked onto current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: terminal.cwd is not respected by terminal tool

3 participants