“Agent terminal wrapper: ‘An item with the same key has already been added’ when capturing env”

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

Here’s a workaround that helped other users:

  • Open Cursor Settings Ctrl+Shift+J
  • Go to Agents, find Legacy Terminal Tool
  • Enable it
  • Ctrl+Shift+P → Terminal: Kill All Terminals
  • Fully restart Cursor
  • Try running commands again

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

Another option is to install PowerShell 7 instead of the built-in Windows PowerShell 5.1. One user fixed it that way: Agent running commands is broken

Let me know if this doesn’t help.