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.py2. 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/Bash | PowerShell | Notes |
|---|---|---|
cd dir && npm install | cd dir; npm install | Use semicolon for command chaining |
export VAR=value | $env:VAR="value" | Environment variables |
source .env | . .env.ps1 | Dot sourcing scripts |
grep "pattern" | Select-String "pattern" | Or use ripgrep: rg |
rm -rf dir/ | Remove-Item -Recurse -Force dir | Recursive 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
continueor?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:
- Tell Cursor: "I'm on Windows, use PowerShell syntax"
- Create
.ps1scripts instead of inline commands - Use
;not&&for chaining - Escape backslashes in paths or use forward slashes
- Run
ripgrepasrg, notgrep