Windows Terminal & PowerShell Patterns

Essential patterns for Windows development with Cursor AI to avoid OS-specific pitfalls.

⚠️ Critical Windows Issues

Cursor AI has OS detection issues and defaults to Unix-style commands even on Windows. This causes:

  • Commands chained with && (fails in PowerShell)
  • Unix paths instead of Windows paths
  • Bash syntax instead of PowerShell
  • Context window exhaustion from retry loops

πŸ›‘οΈ Defensive Patterns

1. Script-Based Execution (Recommended)

Instead of direct terminal commands, create PowerShell scripts in scripts/:

# scripts/run-worker.ps1
<#
.SYNOPSIS
    Starts the Python worker for card processing
.DESCRIPTION
    Activates virtual environment and starts the worker process
#>

# Navigate to project root
$ProjectRoot = Split-Path -Parent $PSScriptRoot
Set-Location $ProjectRoot

# Activate virtual environment if exists
if (Test-Path ".venv\Scripts\Activate.ps1") {
    & .venv\Scripts\Activate.ps1
}

# Start worker
python worker/worker.py

2. Always Specify PowerShell Syntax

In your Cursor rules or when prompting:

# Add to .cursorrules or prompt
"I'm on Windows. Use PowerShell syntax:
- Use ; to chain commands, not &&
- Use $env:VAR not $VAR
- Use \ for paths, not /
- Wrap complex commands in .ps1 scripts"

3. Common Command Translations

Unix/BashPowerShellNotes
cd dir && npm installcd dir; npm installUse semicolon for command chaining
export VAR=value$env:VAR="value"Environment variables
source .env. .env.ps1Dot sourcing scripts
grep "pattern"Select-String "pattern"Or use ripgrep: rg
rm -rf dir/Remove-Item -Recurse -Force dirRecursive deletion

πŸ“ Project Script Structure

scripts/
β”œβ”€β”€ setup/
β”‚   β”œβ”€β”€ install-dependencies.ps1    # npm install + pip install
β”‚   β”œβ”€β”€ configure-environment.ps1    # Set up .env files
β”‚   └── init-database.ps1           # Run migrations
β”œβ”€β”€ dev/
β”‚   β”œβ”€β”€ start-frontend.ps1          # npm run dev
β”‚   β”œβ”€β”€ start-worker.ps1            # python worker/worker.py
β”‚   └── start-all.ps1               # Starts everything
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ run-frontend-tests.ps1     # Jest/Playwright
β”‚   β”œβ”€β”€ run-python-tests.ps1       # PyTest
β”‚   └── run-all-tests.ps1          # Full test suite
└── README.md                       # Script documentation

πŸ”§ Worker-Specific Issues

The Python worker requires special handling on Windows:

Virtual Environment Activation

# Current (complex) way:
.venv\Scripts\Activate.ps1; cd worker; python worker.py

# Better: Use a script
./scripts/dev/start-worker.ps1

Path Issues

Always use raw strings or escape backslashes in Python:

# Bad
path = "C:\Users\user\project"  # Double escaping issues

# Good
path = r"C:\Users\user\project"  # Raw string
path = Path("C:/Users/user/project")  # Forward slashes work

🚨 Troubleshooting

Cursor Hangs on "Generating..."

  • Type continue or ? to nudge it
  • Check if it's stuck on Unix commands
  • Create new session if context is corrupted

Commands Fail Silently

  • Check terminal output for && errors
  • Verify PowerShell is the active shell
  • Use $ErrorActionPreference = "Stop" in scripts

Database Connection Issues

# Windows often needs explicit UTF-8 encoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$env:PYTHONUTF8 = "1"

πŸ“Œ Quick Reference Card

Every Windows Session Checklist:

  1. Tell Cursor: "I'm on Windows, use PowerShell syntax"
  2. Create .ps1 scripts instead of inline commands
  3. Use ; not && for chaining
  4. Escape backslashes in paths or use forward slashes
  5. Run ripgrep as rg, not grep