Fix Git Bash conda activation when conda init bash was run (#1370)#1609
Merged
dmitrivMS merged 1 commit intoJun 25, 2026
Merged
Conversation
…s detected (microsoft#1370) When a user on Windows has run `conda init bash` and has `auto_activate_base = true`, re-sourcing `conda.sh` at terminal startup corrupts `CONDA_EXE`. The full Anaconda distribution ships its own Cygwin-style `cygpath` in `Library/usr/bin`, which gets prepended to PATH by base activation and shadows Git Bash's MSYS `cygpath`. `conda.sh`'s first line re-runs `cygpath` and emits a `/cygdrive/c/...` path, which Git Bash cannot resolve, so every subsequent `conda` command fails with `bash: /cygdrive/c/.../conda.exe: No such file or directory`. When `shellInitStatus.bash === true` (conda init detected in the user's .bash_profile/.bashrc), the `conda` shell function and `CONDA_EXE` are already loaded correctly when the terminal starts, so skip `source conda.sh` and emit only `conda activate <prefix>`. - Add optional `shellInitStatus` parameter to `windowsExceptionGenerateConfig`. - Pass `envManager.sourcingInformation.shellInitStatus` from caller (mirrors what the non-Windows path already does). - Tests cover bash=true skips source, bash=false / undefined preserve existing behavior, prefix quoting still works, and PowerShell/CMD activation unaffected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eleanorjboyd
approved these changes
Jun 25, 2026
dmitrivMS
approved these changes
Jun 25, 2026
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.
Closes #1370
Context
On Windows, when a user has run
conda init bashand hasauto_activate_baseenabled (conda default), opening a Git Bash terminal in VS Code with auto-activation enabled causes every subsequentcondacommand to fail with:The terminal still displays
(base)and appears active, but conda is silently broken until the user closes and reopens the terminal.Root cause
A chain of three independent systems creates the failure:
~/.bashrc(modified byconda init bash) initializes conda on shell startup — defines thecondashell function and setsCONDA_EXEcorrectly.auto_activate_base = trueactivates(base), which prependsanaconda3/Library/usr/bintoPATH. That directory ships Anaconda's own (Cygwin-style)cygpath, which now shadows Git Bash's MSYScygpath. The two emit different path formats:cygpath C:\foo→/c/foo✅ (Git Bash understands)cygpath C:\foo→/cygdrive/c/foo❌ (Git Bash does NOT understand)conda.shis:cygpath, producing/cygdrive/c/....CONDA_EXEis corrupted. Thecondashell function (which delegates to$CONDA_EXE) fails for every subsequent invocation.The corruption is entirely caused by re-sourcing
conda.shin a terminal that already initialized conda. If we skip the re-sourcing, the original (correct)CONDA_EXEremains intact and conda keeps working.Why the existing safeguards do not catch this
buildShellActivationMapForCondahas a P1 short-circuit that skips re-sourcing whenisActiveOnLaunchis true. That flag is derived fromprocess.env.CONDA_SHLVLat VS Code startup. The user launches VS Code normally (not from a conda-active shell), soCONDA_SHLVLis unset at the VS Code process level and the safeguard never fires — even though conda will be active inside every new terminal.The extension already has a separate signal that does fire in this scenario:
checkCondaInitInShellProfiles()reads the user's shell profiles and reportsshellInitStatus.bash = truewhenconda initializeis present. The non-Windows path already accepts this signal, but only uses it as a fallback when sourcing scripts are missing. The Windows path doesn't accept it at all.The fix
Pass
shellInitStatusthrough towindowsExceptionGenerateConfigand add an early branch in the Git Bash logic:The new branch is the first condition checked. When the user has run
conda init bash, we emit onlyconda activate <prefix>instead ofsource conda.sh && conda activate <prefix>.Why this fixes the issue
The bug is triggered by re-running
cygpath(in a shadowed PATH context) insideconda.sh. By skipping the redundantsource, we never re-execute that line, soCONDA_EXEretains the correct value set by the originalconda init bashhook in the user's shell profile. Theconda activatecall then uses the already-loadedcondashell function with the correctCONDA_EXE, and everything works.