← ClaudeAtlas

windows-agent-automationlisted

Windows-specific traps when an agent or script drives CLIs, schedules jobs, or generates files on Windows — .cmd shims truncating multi-line input, PowerShell 5.1 missing operators, encoding defaults that corrupt output, Task Scheduler instead of cron, and path/credential locations. Use when writing any Python/Node script that shells out on Windows, scheduling a recurring job, debugging "it works when I type it but not from the script", seeing UnicodeEncodeError or garbled characters, or when a subprocess cannot find a command that is clearly on PATH. Every trap here has already cost real hours on this machine.
hellokianben-collab/vishal-agarwal-context · ★ 0 · AI & Automation · score 60
Install: claude install-skill hellokianben-collab/vishal-agarwal-context
# Windows automation traps Environment: **Windows 11**, PowerShell **5.1**, Git Bash available, Node + Python 3.14, no `gh` CLI. --- ## 1. `claude` and `vercel` on PATH are `.cmd` shims — this is the expensive one Two separate failures, both silent: **a) Multi-line input passed as an argv element is truncated at the first newline.** ```python # WRONG — cmd.exe cuts the prompt at the first \n. The model answers a question it never received. subprocess.run([claude, "-p", long_multiline_prompt]) # RIGHT — pipe through stdin subprocess.run([claude, "-p"], input=long_multiline_prompt, text=True, encoding="utf-8") ``` The output looks *plausible*, which is why this can survive for days. If a model's answer seems to ignore most of your prompt, check this before anything else. **b) `subprocess` cannot resolve the bare name.** ```python import shutil claude = shutil.which("claude") # → the full .cmd path if not claude: raise RuntimeError("claude not on PATH") ``` `shell=True` also "works" and brings quoting problems with it. Resolve the path instead. ## 2. PowerShell 5.1 is missing operators you will reach for | Not available | Use | |---|---| | `&&` | `A; if ($?) { B }` | | `\|\|` | `A; if (-not $?) { B }` | | ternary `? :` | `if/else` | | `??`, `?.` | explicit `if ($null -eq $x)` | | `ConvertFrom-Json -AsHashtable` | returns `PSCustomObject`; index accordingly | **Do not redirect a native executable's stderr with `2>&1`.** PowerShell 5.1 wraps each line in an Error