Skip to content

fix(windows): refresh terminal environment from registry on launch - #2605

Open
weiningwei wants to merge 2 commits into
sourcegit-scm:developfrom
weiningwei:fix/terminal-stale-env
Open

fix(windows): refresh terminal environment from registry on launch#2605
weiningwei wants to merge 2 commits into
sourcegit-scm:developfrom
weiningwei:fix/terminal-stale-env

Conversation

@weiningwei

@weiningwei weiningwei commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem

When SourceGit is running and the user installs new CLI tools (Node.js, Python, Rust, etc.) or modifies system/user environment variables, clicking "Open in Terminal" opens a terminal with the stale environment snapshot from when SourceGit was started. The new PATH entries are missing, so commands from newly installed tools are not found.

This affects all Windows terminal types: cmd, pwsh, git-bash, and Windows Terminal.

Root Cause

Process.Start with default UseShellExecute = false uses CreateProcess, which inherits the parent process's Environment Block — the snapshot from SourceGit's startup time. UseShellExecute = true also does not solve this, as ShellExecuteEx with NULL lpEnvironment also inherits the parent environment.

Solution

Add RefreshEnvFromRegistry method that re-reads the latest environment from the Windows registry each time "Open in Terminal" is clicked, and sets a custom ProcessStartInfo.Environment for the child process.

Algorithm

  1. Read Machine env from registry (HKLM\...\Environment)
  2. Read User env from registry (HKCU\Environment) — overrides Machine, PATH is appended not replaced
  3. Preserve dynamic process-only variables (TEMP, USERNAME, COMPUTERNAME, etc.) that are not in registry

Signed-off-by: weiningwei <weiningwei09@gmail.com>
Signed-off-by: weiningwei <weiningwei09@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant