Windows shortcuts can silently omit CONDA_PREFIX / env config vars from the activation script
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- operating-systems, tooling
Research direction
Start in menuinst/platforms/win.py at WindowsMenuItem._command() and inspect the .env-file branch and its logged_run() activation call. Reproduce shortcut generation from a clean shell and from an already activated target environment, then verify the generated .env consistently includes CONDA_PREFIX, CONDA_DEFAULT_ENV, and configured environment variables.
Written by the indexing model from the issue text.
Description
Checklist
- I added a descriptive title
- I searched open reports and couldn't find a duplicate
What happened?
Component: menuinst/platforms/win.py, WindowsMenuItem._command() (the .env-file branch used for conda >= 25.3.0)
Summary
When a package's post-install hook calls menuinst.api.install() from inside the environment it's creating a shortcut for (i.e. CONDA_SHLVL/CONDA_PREFIX/CONDA_DEFAULT_ENV already point at that same target prefix), the generated .bat shortcut is missing CONDA_PREFIX, CONDA_DEFAULT_ENV, and any custom variables set via conda env config vars set (from conda-meta/state). PATH and the activate.d/deactivate.d hook calls are present and correct, so the shortcut looks activated but isn't fully.
Root cause
_command() shells out to conda shell.cmd.exe activate <prefix> via logged_run(activator_cmd, check=True, log=False) with no explicit env=, so the subprocess inherits the calling process's environment as-is. conda's activator only emits SET lines for variables whose value differs from what's already in that inherited environment. If the builder process is already activated in the same target env, CONDA_PREFIX/CONDA_DEFAULT_ENV/config vars already match the target exactly, so conda considers them "unchanged" and omits them — even though the resulting script is meant to run standalone, later, in a fresh cmd.exe with none of that ambient state.
Reproduction
- Env
myenvhas a custom var set:conda env config vars set FOO=bar -n myenv. - From a clean shell:
conda shell.cmd.exe activate <prefix of myenv>→ resulting.envfile includesCONDA_PREFIX,CONDA_DEFAULT_ENV, andFOO=bar. - From a shell where
myenvis already active (conda activate myenvfirst): re-run the sameshell.cmd.exe activate <prefix>call → the.envfile now omitsCONDA_PREFIX,CONDA_DEFAULT_ENV, andFOOentirely, while still includingPATH,CONDA_SHLVL, and theactivate.d/deactivate.d_CONDA_SCRIPTlines. - Since
menuinst's post-install-triggered shortcut generation typically requires being run activated (to knowCONDA_PREFIXin the first place), any package following that pattern gets a shortcut baked from case 3, not case 2.
Expected
The generated shortcut should be self-contained and always include the full activation state (CONDA_PREFIX, CONDA_DEFAULT_ENV, and all conda-meta/state env_vars), regardless of the activation state of the process that built it.
Suggested fix
In _command(), pass a sanitized env= to the logged_run(activator_cmd, ...) call that strips CONDA_SHLVL, CONDA_PREFIX, CONDA_DEFAULT_ENV, CONDA_PROMPT_MODIFIER, _CE_M, _CE_CONDA before invoking conda shell.cmd.exe activate, so the subprocess always computes activation "from scratch" instead of diffing against whatever state the builder process happens to be in.
Environment
- conda: >= 25.3.0 (uses the
.env-file activation path inwin.py, not the older.batpath) - OS: Windows
Conda Info
Conda Config
Conda list
Additional Context
No response
- Dominant language
- Python
- Stars
- 50
- Forks
- 49
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 13
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from conda/menuinst
-
CMD shell activation changed in `conda 25.3.0`Possibly taken @marcoesters claimed this 78 days ago. Openstale::recovered type::bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
conda/menuinst#321 · 13 comments ·
Maintainers usually reply within 1 day
-
Limitations on Linux/Freedesktop platformsPossibly taken @haecker-felix claimed this 1 day ago. Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
conda/menuinst#586 · 4 comments ·
Maintainers usually reply within 1 day
-
Option to set Windows shortcut Minimized or Maximized propertyMay be free again @lrandersson claimed this 198 days ago, and no pull request is open. Opentype::feature
conda/menuinst#484 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Add --set-global-placeholder CLI flag for custom placeholdersMay be free again @lrandersson claimed this 202 days ago, and no pull request is open. Opentype::feature
conda/menuinst#479 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
Convoluted windows shortcut code causing security problemsPossibly taken @lrandersson claimed this 202 days ago. Opentype::bug
conda/menuinst#468 · 11 comments · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
plone/plone.observability#114 ·
Maintainers usually reply within 1 day
-
area:docs type:docs
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
jejjohnson/gauss_flows#246 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openvax/varcode#824 · 1 comment ·
Maintainers usually reply within 1 day
-
netbox status: needs triage type: feature
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
netbox-community/netbox#23868 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
emeryberger/CSrankings#15757 ·
Maintainers usually reply within 9 days