Where does the bug appear (feature/product)?
Cursor IDE
Describe the Bug
Summary
PowerShell commands executed through Cursor agents fail with an “An item with the same key has already been added” error, even though the actual PowerShell commands execute successfully. The issue is in Cursor’s wrapper script that processes command output.
Steps to Reproduce
Steps to Reproduce
- Run any PowerShell command through a Cursor agent (e.g.,
powershell -Command "Write-Host 'test'") - Command executes successfully
- Cursor’s wrapper script fails during post-processing
Error Message
Get-ChildItem : An item with the same key has already been added.
At C:\Users\[USER]\AppData\Local\Temp\ps-script-[ID].ps1:40 char:16
+ $envVars = Get-ChildItem Env: | Sort-Object Name
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetChildItemCommand
Root Cause
The error occurs at line 40 of Cursor’s temporary PowerShell wrapper script when it attempts to enumerate all environment variables using Get-ChildItem Env:.
Windows allows the same environment variable key to exist in multiple scopes (Process, User, and Machine), which is normal behavior. When Cursor’s script tries to collect these into a collection (likely a hashtable or dictionary), it fails because duplicate keys cannot be added.
Affected Environment Variables
The following environment variables have duplicate keys across scopes:
PathPSModulePathTEMPTMPOneDriveOneDriveConsumerComSpecOSwindirUSERNAMEPROCESSOR_ARCHITECTUREPROCESSOR_IDENTIFIERPROCESSOR_LEVELPROCESSOR_REVISIONNUMBER_OF_PROCESSORSPATHEXTDriverDataAMDRMSDKPATHplatformcodeRegionCodeOnlineServices
Expected Behavior
Expected Behavior
Cursor’s wrapper script should handle duplicate environment variable keys gracefully, either by:
- Using a method that doesn’t fail on duplicates (e.g.,
[System.Environment]::GetEnvironmentVariables()with proper deduplication) - Filtering duplicates before processing
- Using a collection type that allows or handles duplicates appropriately
Actual Behavior
The wrapper script crashes when encountering duplicate environment variable keys, even though the actual user command executed successfully.
Workaround
- Run PowerShell commands directly in terminal instead of through Cursor agents
- Use CMD (
cmd /c) for simple commands when possible - Use
-NoProfileflag to reduce environment variable conflicts (partial workaround)
Operating System
Windows 10/11
Version Information
System Information
- OS: Windows
- Cursor Version: 2.4.21
- PowerShell Version: Windows PowerShell 5.1 (or PowerShell Core if applicable)
Additional Notes
- The actual PowerShell commands work correctly when run directly
- This appears to be a bug in Cursor’s post-processing/wrapper script, not in PowerShell itself
- The issue may have been exposed or worsened by recent Windows updates that modified environment variable handling
Does this stop you from using Cursor
Yes - Cursor is unusable