Bug Report: PowerShell Commands Fail with “Duplicate Key” Error in Wrapper Script

Hey, thanks for the report.

This is a new bug with the PowerShell wrapper script that Cursor uses to run commands through the agent. The issue is that the script tries to collect environment variables via Get-ChildItem Env:, and on Windows the same variable (Path, TEMP, etc.) can exist in multiple scopes (Process, User, Machine), and the script can’t handle that.

There isn’t an official fix yet, but there’s a workaround that has helped with other PowerShell issues caused by the same wrapper script:

  1. Open Cursor Settings (Ctrl+Shift+J)
  2. Go to Agents, then find Legacy Terminal Tool
  3. Turn it on
  4. Press Ctrl+Shift+P then run Terminal: Kill All Terminals
  5. Fully restart Cursor
  6. Try the commands again

Legacy Terminal Tool uses the older implementation, which may avoid this wrapper script issue.

If it doesn’t help, let me know.

Related issues with the same wrapper script: