Skip to content

Update-SessionEnvironment in package install script does not affect Powershell that started the choco install command #3865

@NyoTheNeko

Description

@NyoTheNeko

Checklist

  • I confirm there are no unresolved issues reported on the Chocolatey Status page.
  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my problem.
  • I have verified this is not an issue for a specific package.
  • I have verified this issue is not security related.
  • I confirm I am using official, and not unofficial, or modified, Chocolatey products.

What You Are Seeing?

When using a Powershell shell (both 5.1 and 7) and installing a package through "choco install", Update-SessionEnvironment that is found in the chocolateyInstall.ps1 does not refresh the environment variables (even Path).

PS C:\WINDOWS\system32> choco install custom-claude-code
Chocolatey v2.6.0 Business
Installing the following packages:
custom-claude-code
By installing, you accept licenses for the packages.
Downloading package from source 'https://chocopackages.custom.com/v3/chocoCustom/'
Progress: Downloading custom-claude-code 2.1.58... 100%

custom-claude-code v2.1.58
custom-claude-code package files install completed. Performing other installation steps.
Copying custom-claude-code
  from 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\files\claude.exe'
Virus checking skipped/turned off. Not verifying 'claude.exe'
C:\Users\xxx\.local\bin\claude.exe
PATH environment variable does not have C:\Users\xxx\.local\bin in it. Adding...

? Installation complete!

Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The install of custom-claude-code was successful.
  Software install location not explicitly set, it could be in package or
  default install location of installer.

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\WINDOWS\system32> $env:DISABLE_PROMPT_CACHING
PS C:\WINDOWS\system32> claude
claude : The term 'claude' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ claude
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (claude:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\WINDOWS\system32> $env:Path
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\PowerShell\7\;C:\Program Files\Git\cmd;C:\Users\xxx\AppData\Local\Microsoft\WindowsApps
PS C:\WINDOWS\system32> Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 -force
PS C:\WINDOWS\system32> Update-SessionEnvironment
PS C:\WINDOWS\system32> $env:DISABLE_PROMPT_CACHING
1
PS C:\WINDOWS\system32> claude

 ▐▛███▜▌   Claude Code v2.1.58

When running the same choco install through cmd, it does indeed refresh the Path (but does not seem to have refreshed any other environment variables):

C:\Windows\System32>choco install custom-claude-code
Chocolatey v2.6.0 Business
Installing the following packages:
custom-claude-code
By installing, you accept licenses for the packages.
Downloading package from source 'https://chocopackages.custom.com/v3/chocoCustom/'
Progress: Downloading custom-claude-code 2.1.58... 100%

custom-claude-code v2.1.58
custom-claude-code package files install completed. Performing other installation steps.
Copying custom-claude-code
  from 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\files\claude.exe'
Virus checking skipped/turned off. Not verifying 'claude.exe'
C:\Users\xxx\.local\bin\claude.exe
PATH environment variable does not have C:\Users\xxx\.local\bin in it. Adding...

? Installation complete!

Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The install of custom-claude-code was successful.
  Software install location not explicitly set, it could be in package or
  default install location of installer.

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

C:\Windows\System32>set DISABLE_PROMPT_CACHING
Environment variable DISABLE_PROMPT_CACHING not defined

C:\Windows\System32>set path
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\PowerShell\7\;C:\Program Files\Git\cmd;C:\Users\xxx\AppData\Local\Microsoft\WindowsApps;C:\Users\xxx\.local\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

C:\Windows\System32>claude

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Accessing workspace:

Of course, calling Update-SessionEnvironment in the Powershell directly (after importing the module), does indeed refresh the environement, and we can do what we expect.

For reference, the chocolateyInstall.pd1 contains the following :

[...]
Get-ChocolateyWebFile @packageArgs
[...]

# PATH update
Install-ChocolateyPath "$localBinDir" -PathType 'User'

# Environment Variables
[...]
Install-ChocolateyEnvironmentVariable -variableName "DISABLE_PROMPT_CACHING" -variableValue "1" -variableType 'Machine'

Write-Output ""
Write-Output "$([char]0x2705) Installation complete!"
Write-Output ""

Update-SessionEnvironment

What is Expected?

Either for the documentation on Update-SessionEnvironment to be modified, or for the install script to actually affect the powershell/shell that "calls" it.

From what I could find by looking at how the choco install will run the ps1 file, it seems that we create a subprocess that will run the chocolateyInstall.ps1 (by calling it with &). Thus, Update-SessionEnvironment will indeed update the "current powershell session", which is the subprocess created by calling the ps1 with &. This is of course a problem with Windows itself (as any refresh of the environment on a subprocess is not propagated to the parent).

If it is what is expected to happen (as in, the way choco install was designed is the intended way we want it to work), we should have a mention in the documentation for Update-SessionEnvironment that if it is used in a package installation script, it will not affect the powershell calling the install through choco install.
If it is not what we expect, than that means that we expect Update-SessionEnvironment to affect the powershell that calls choco install, and thus would need to modify the way the ps1 script is run.

How Did You Get This To Happen?

  1. Create choco package that modifies path and an environment variable, then calls Update-SessionEnvironment in it's chocolateyInstall.ps1
  2. Open Powershell as Adminsitrator
  3. Run choco install package-name
  4. Check for Path + environment variable modification (with $env)

User Story

When a chocolateyInstall.ps1 script contains Update-SessionEnvironment, the powershell that is used to call choco isntall on that package should have it's environement refreshed.

System Details

  • Operating System: W11
  • Windows PowerShell version: %.1 and 7
  • Chocolatey CLI Version: 2.6.0
  • Chocolatey Licensed Extension version: 7.0.0
  • Chocolatey License type: Business
  • Terminal/Emulator:

Installed Packages

7zip 25.0.0
7zip.install 25.0.0
chocolatey 2.6.0
chocolatey.extension 6.1.3
chocolatey-agent 2.1.0
chocolatey-compatibility.extension 1.0.0
chocolatey-core.extension 1.4.0
chocolatey-dotnetfx.extension 1.0.1
chocolateygui 2.1.0
chocolateygui.extension 2.0.0
chocolatey-license 2026.8.10.1
chocolatey-windowsupdate.extension 1.0.5
chocopadv2 1.1.9
curl 8.19.0
dotnetfx 4.8.0.20220524
git 2.53.0.2
git.install 2.53.0.2
KB2919355 1.0.20160915
KB2919442 1.0.20160915
KB3118401 1.0.5
notepadplusplus 8.8.1
notepadplusplus.install 8.8.1
powershell-core 7.3.8
vscode 1.101.2
vscode.install 1.101.2
wsl2 2.4.13
26 packages installed.

Output Log

2026-03-18 08:56:02,530 4552 [DEBUG] - Running Install-ChocolateyEnvironmentVariable -variableName 'NODE_EXTRA_CA_CERTS' -variableValue 'C:\\Users\\xxx\\.claude\\proxy.pem' -variableType 'Machine' 
2026-03-18 08:56:02,532 4552 [DEBUG] - Running Test-ProcessAdminRights
2026-03-18 08:56:02,533 4552 [DEBUG] - Test-ProcessAdminRights: returning True
2026-03-18 08:56:02,533 4552 [DEBUG] - Finishing 'Test-ProcessAdminRights'
2026-03-18 08:56:02,533 4552 [DEBUG] - Running Set-EnvironmentVariable -Name 'NODE_EXTRA_CA_CERTS' -Value 'C:\\Users\\xxx\\.claude\\proxy.pem' -Scope 'Machine'
2026-03-18 08:56:02,535 4552 [DEBUG] - Registry type for NODE_EXTRA_CA_CERTS is/will be String
2026-03-18 08:56:02,753 4552 [DEBUG] - Finishing 'Set-EnvironmentVariable'
2026-03-18 08:56:02,757 4552 [DEBUG] - Running Update-SessionEnvironment
2026-03-18 08:56:02,757 4552 [INFO ] - VERBOSE: Refreshing environment variables from the registry.
2026-03-18 08:56:02,761 4552 [DEBUG] - Finishing 'Update-SessionEnvironment'
2026-03-18 08:56:02,761 4552 [INFO ] - 
2026-03-18 08:56:02,765 4552 [INFO ] - ? Installation complete!
2026-03-18 08:56:02,767 4552 [INFO ] - 
2026-03-18 08:56:02,771 4552 [DEBUG] - ----------------------------------------------------------------------
2026-03-18 08:56:02,776 4552 [DEBUG] - Built-in PowerShell host called with ['[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = '';[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::SystemDefault; & import-module -name 'C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1'; & 'C:\ProgramData\chocolatey\helpers\chocolateyScriptRunner.ps1' -packageScript 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\chocolateyinstall.ps1' -installArguments '' -packageParameters '' -preRunHookScripts $null -postRunHookScripts $null'] exited with '0'.
2026-03-18 08:56:02,782 4552 [DEBUG] - Calling command ['"C:\WINDOWS\System32\shutdown.exe" /a']
2026-03-18 08:56:02,832 4552 [DEBUG] - Command ['"C:\WINDOWS\System32\shutdown.exe" /a'] exited with '1116'
2026-03-18 08:56:02,850 4552 [WARN ] - Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
2026-03-18 08:56:02,852 4552 [DEBUG] - Logging of values is not turned on by default because it
 could potentially expose sensitive data. If you understand the risk,
 please see `choco feature --help` for information to turn it on.
2026-03-18 08:56:02,852 4552 [DEBUG] - The following values have been added/changed (may contain sensitive data):
2026-03-18 08:56:02,854 4552 [DEBUG] -   * Path='[REDACTED]' (User)
2026-03-18 08:56:02,854 4552 [DEBUG] -   * ChocolateyLastPathUpdate='[REDACTED]' (User)
2026-03-18 08:56:02,854 4552 [DEBUG] -   * CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS='[REDACTED]' (Machine)
2026-03-18 08:56:02,856 4552 [DEBUG] -   * CLAUDE_CODE_SKIP_CONNECTIVITY_CHECK='[REDACTED]' (Machine)
2026-03-18 08:56:02,856 4552 [DEBUG] -   * CLAUDE_CODE_DISABLE_TELEMETRY='[REDACTED]' (Machine)
2026-03-18 08:56:02,856 4552 [DEBUG] -   * CLAUDE_CODE_DISABLE_ANALYTICS='[REDACTED]' (Machine)
2026-03-18 08:56:02,856 4552 [DEBUG] -   * CLAUDE_CODE_OFFLINE_MODE='[REDACTED]' (Machine)
2026-03-18 08:56:02,858 4552 [DEBUG] -   * DISABLE_PROMPT_CACHING='[REDACTED]' (Machine)
2026-03-18 08:56:02,858 4552 [DEBUG] -   * NODE_EXTRA_CA_CERTS='[REDACTED]' (Machine)
2026-03-18 08:56:02,919 4552 [DEBUG] - Capturing package files in 'C:\ProgramData\chocolatey\lib\custom-claude-code'
2026-03-18 08:56:03,169 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\custom-claude-code.nupkg'
  with checksum 'DCA74E018E9B9884CB650BBF273DFAB9'
2026-03-18 08:56:03,171 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\custom-claude-code.nuspec'
  with checksum 'AAAC9ABFB3E4AFF0BCC9A42F414704EF'
2026-03-18 08:56:03,173 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\chocolateybeforemodify.ps1'
  with checksum '8BB95B6D4CD42F6681C61D834C042CEE'
2026-03-18 08:56:03,173 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\chocolateyinstall.ps1'
  with checksum '9938FEEF0834B7DFF0827183D1166205'
2026-03-18 08:56:03,175 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\chocolateyuninstall.ps1'
  with checksum '430B0DB9D624F18054A2DF5E0ED9BFDA'
2026-03-18 08:56:03,901 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\files\claude.exe'
  with checksum '509806395AAF63DC30955437747E88D1'
2026-03-18 08:56:03,903 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\files\claude.exe.ignore'
  with checksum 'ECAA88F7FA0BF610A5A26CF545DCD3AA'
2026-03-18 08:56:03,903 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\files\manifest.json'
  with checksum 'A7A8ED7A795BA43CB95A6C0FC55DB34C'
2026-03-18 08:56:03,905 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\files\proxy.pem'
  with checksum '1CB9B3F74706FDC2DE0FCBA1080784D0'
2026-03-18 08:56:03,905 4552 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\custom-claude-code\tools\files\settings.json'
  with checksum '9C80006A9F391BD82BA6205B79AF8911'
2026-03-18 08:56:03,923 4552 [INFO ] -  Reducing package size for 'custom-claude-code'...
2026-03-18 08:56:03,927 4552 [DEBUG] - Attempting to create directory "C:\Users\xxx\AppData\Local\Temp\ChocolateyScratch\ChocolateyPackageCache\PackageCache_20260318_085603_9238".
2026-03-18 08:56:03,929 4552 [DEBUG] - Attempting to copy "C:\ProgramData\chocolatey\lib\custom-claude-code\custom-claude-code.nuspec"
 to "C:\Users\xxx\AppData\Local\Temp\ChocolateyScratch\ChocolateyPackageCache\PackageCache_20260318_085603_9238\custom-claude-code.nuspec".
2026-03-18 08:56:04,124 4552 [INFO ] -  Reducing nupkg file size ('custom-claude-code').
2026-03-18 08:56:04,232 4552 [INFO ] -  Reducing extracted archives and installers ('custom-claude-code').
2026-03-18 08:56:04,240 4552 [DEBUG] - Attempting to detect type for 'claude.exe' with db 'C:\ProgramData\chocolatey\tools\detector\db'
2026-03-18 08:56:08,326 4552 [DEBUG] - fileTypeOutput='PE+(64): Nothing found'
2026-03-18 08:56:08,328 4552 [INFO ] -  Space reduced for 'custom-claude-code': 69,9 MB.
2026-03-18 08:56:08,330 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\lib\custom-claude-code\custom-claude-code.nupkg.bkp".
2026-03-18 08:56:08,361 4552 [DEBUG] - Attempting to replace "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.files"
 with "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.files.4552.update".
 Backup placed at "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.files.backup".
2026-03-18 08:56:08,365 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.files.backup".
2026-03-18 08:56:08,365 4552 [DEBUG] - Attempting to copy "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.files.4552.update"
 to "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.files".
2026-03-18 08:56:08,367 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.files.4552.update".
2026-03-18 08:56:08,367 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.arguments".
2026-03-18 08:56:08,370 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.extra".
2026-03-18 08:56:08,370 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.version".
2026-03-18 08:56:08,372 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.sxs".
2026-03-18 08:56:08,372 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.pin".
2026-03-18 08:56:08,372 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.deploymentLocation".
2026-03-18 08:56:08,372 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\custom-claude-code.2.1.58\.sourceInstalledFrom".
2026-03-18 08:56:08,376 4552 [DEBUG] - Sending message 'HandlePackageResultCompletedMessage' out if there are subscribers...
2026-03-18 08:56:08,378 4552 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\lib\custom-claude-code\.chocolateyPending".
2026-03-18 08:56:08,380 4552 [INFO ] -  The install of custom-claude-code was successful.
2026-03-18 08:56:08,394 4552 [WARN ] - 
Chocolatey installed 1/1 packages.

Additional Context

No response

Acceptance Criteria

  • [] Update-SessionEnvironment doc is modified, or choco install acts as expected

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pending ClosureThis issue has been marked as having no response or is stale and will soon be closed.QuestionIssues opened for asking questions. These should be converted to discussions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions