How can I prevent cursor from making the same mistakes when executing PowerShell?

I am not sure if you figured it out, but I had the same issue. Here is how i resolved it. I did two things.

  1. I set the default terminal on within Preferences → VC Code Settings → “terminal.integrated.defaultProfile.windows”: “Command Prompt”

  1. I created a project rule specifically for this…

This is the rules i crafted using claude 3.7 based on my current configuration and enviroment… you can ask these types of questions in Ask in the Chat on Cursor.

Terminal Command Rules for Windows Environment

Description

These rules guide Cursor’s AI when generating terminal commands for a Windows-only environment. Due to execution problems with PowerShell, we need to ensure only CMD commands are used.

Rules

  1. NEVER use PowerShell commands in terminal suggestions.

  2. Always use Windows CMD commands (batch commands) for all operations.

  3. Use standard Windows CMD syntax with commands like “dir”, “type”, “copy”, “move”, “del”, etc.

  4. For package installation, use npm, yarn, or other package managers with their CMD-compatible syntax.

  5. Avoid commands that begin with “ps”, “pwsh”, or contain PowerShell syntax like “$_”, “-ErrorAction”, etc.

  6. Use Windows environment variables with %VARIABLE% syntax instead of PowerShell’s $env:VARIABLE.

  7. For file path references, use Windows-style paths with backslashes (C:\path\to\file).

  8. When suggesting command chaining, use “&” or “&&” instead of PowerShell’s pipe operator.

  9. For conditional operations, use “if” with CMD syntax instead of PowerShell conditionals.

  10. Use “for” loops with CMD syntax rather than PowerShell’s foreach.

  11. Use “findstr” instead of PowerShell’s Select-String for text searching.

  12. For redirecting output, use “>” and “>>” operators rather than PowerShell’s Out-File.

  13. When suggesting commands to manipulate JSON or perform complex operations, recommend using Node.js scripts or other command-line tools that work well in CMD.