◉ANTIGRAVITY LABJP
Articles/Tips & Best Practices
✦ Tips & Best Practices/2026-08-25Beginner

What I Line Up in PowerShell Before Letting Antigravity Agents Run Commands on Windows

Bash-shaped commands from Antigravity agents break in Windows PowerShell. I measured four gaps (&&, the curl alias, exit codes, output encoding), then built a symptom-first triage table, a preflight script that tells 5.1 from 7, and the rules file I keep so agents stop repeating the same mistakes.

Antigravity421WindowsPowerShellSetup6

You paste the command an agent just handed you into a Windows terminal, and it dies on the first &&. If you work across platforms as an indie developer, that one line has probably cost you an afternoon at some point.

Antigravity is not the problem here. The destination is simply different. On macOS and Linux the command lands in bash or zsh. On Windows it lands in PowerShell, and most of the one-liners a model has absorbed were written for the first group.

Hub 2.9.1 on August 20 added syntax highlighting for .ps1, .psm1, .psd1, and for pwsh / ps1 code fences. I read that as a sign that writing PowerShell is becoming a first-class expectation rather than an afterthought. So I installed PowerShell 7.6.5 locally and pushed the shapes an agent typically produces through it, one at a time.

The thing that surprised me was not &&. It was the exit codes.

For a while, every time an error came back I simply told the agent "this is Windows, please fix it." The fix would hold for one task, and the same shape would reappear in the next. It took me three rounds of that before I realized the problem was not the agent's memory. I had only ever put the assumption in the conversation, and conversations do not last.

The measurements below were taken in August 2026 on PowerShell 7.6.5 (the linux-x64 build). Checking the official sources as of November 2026, the 7.6 line shipped as LTS in March 2026 and has since received servicing releases up to 7.6.10. None of the four behaviors covered here has changed within 7.6.

Whether && works depends on which PowerShell you have

Start by finding out which one you are running. It takes one line.

$PSVersionTable.PSVersion
$PSVersionTable.PSEdition

My environment returned 7.6.5 and Core. Core means the PowerShell 7 line. Desktop means Windows PowerShell 5.1, the one that ships with Windows. If you have not installed anything, you are almost certainly on the latter.

That generation gap collides directly with what agents produce.

BehaviorWindows PowerShell 5.1PowerShell 7.x
&& / || chainingReserved, rejected as a syntax errorSupported
curl / wgetAliases for Invoke-WebRequestNo alias; the real binary runs
Out-File default encodingUTF-16LE with BOMUTF-8 without BOM
How you get itBundled with WindowsInstalled separately

I ran the chaining case on 7.6.5 to be sure.

pwsh -NoProfile -c 'true && echo "chained-ok"'
# chained-ok

It works. Hand the same string to 5.1 and it never executes at all, because parsing fails first. The agent then receives something that is not "the command failed" but "the command was never understood," so it rewrites and gets rejected again. That loop burns turns.

I also measured startup cost while I was there. Five runs of pwsh -NoProfile -c '1' came in at 228, 211, 217, 217, and 232 milliseconds. On the same machine, bash -c 'true' took 3 milliseconds every time. If an agent fires dozens of shell commands per task, that difference alone adds ten seconds or more. -NoProfile is still worth keeping, since it skips profile loading on top of that baseline.

When an agent writes curl, 5.1 runs something else entirely

I checked the alias table on 7.6.5.

Get-Alias curl -ErrorAction SilentlyContinue   # nothing
Get-Alias wget -ErrorAction SilentlyContinue   # nothing

The 7 line dropped both aliases, so curl -s https://example.com reaches the actual curl binary.

On 5.1 those aliases are still defined and point at Invoke-WebRequest. Flags like -s and -H are not parameters that cmdlet knows, so what comes back is a parameter-binding error, not a network error. Nothing in the message mentions HTTP at all, which sends you looking in entirely the wrong place.

The fix is boring and reliable: write external commands with their extension.

curl.exe -s https://example.com
node.exe --version

One honest caveat. Aliases such as ls and cat behave differently by platform even inside the 7 line, and what I verified was the linux-x64 build of 7.6.5. The only claims I am willing to base on my own measurement are curl and wget. For everything else, run Get-Alias once on your Windows box and look at the list yourself.

Failures collapse to 1, and that breaks automated success checks

This is the part that held my attention. When you pass a command with -c (-Command), the exit code from inside does not always reach the outside intact. Here is what I measured.

What I ranInner exit codeWhat the caller received
pwsh -NoProfile -c 'exit 3'33
pwsh -NoProfile -c 'exit 42'4242
External command inside -c exits 331
Same, plus ; exit $LASTEXITCODE33
ls on a missing path inside -c21
Same, plus ; exit $LASTEXITCODE22
pwsh -NoProfile -File ./t.ps1 containing exit 333
Failing command followed by || echo fallback20

When you write exit yourself, the value survives. When an external command fails, 3 and 2 are flattened to the same 1. You still learn that something failed; you lose how it failed. If anything downstream branches on the specific code, that distinction is gone.

The last row is the sneakiest. Once the right side of || succeeds, the whole invocation reports 0. Your log shows a failure while your caller records a success.

Reading $? has its own timing rule.

# read immediately: False
& ./somecommand ; $q = $?; "q=$q code=$LASTEXITCODE"   # q=False code=3
 
# put any statement in between and it flips back
& ./somecommand ; "anything" | Out-Null; "q=$? code=$LASTEXITCODE"   # q=True code=3

$? only remembers the single statement before it. $LASTEXITCODE keeps the external command's value, so that is the one to branch on.

My own rule is short: if you use -c, end it with exit $LASTEXITCODE; when you can, pass a script with -File instead. Something similar happens on the bash side for entirely different reasons, which I wrote up in the pipe in my wrapper was swallowing Antigravity CLI's exit code. Different cause, very familiar symptom.

Logs written through redirection change bytes between generations

Having an agent write its run log to a file, then reading it yourself later, is a common enough pattern. The generation gap shows up here too.

I wrote a file on 7.6.5 and looked at it byte by byte.

"日本語ログ" | Out-File -FilePath ./enc7.txt
(Get-Item ./enc7.txt).Length

The file came to 16 bytes for that five-character Japanese string, and the leading bytes were e6 97 a5 e6 9c ac e8 aa 9e e3 83 ad e3 82 b0 0a — UTF-8 with no BOM, plus one newline. grep reads it, Python reads it, nothing special required.

On 5.1, Out-File and > default to UTF-16LE with a BOM. The same five characters roughly double in size and gain a byte-order mark. Open the file and it looks correct to you; hand it to a parser or back to an agent and every character appears to have a null byte wedged next to it. Most of the times a log looked "empty" to me, this was why.

State it explicitly when you write.

"日本語ログ" | Out-File -FilePath ./log.txt -Encoding utf8

Note that utf8NoBOM only exists from 7 onward. If you are staying on 5.1 and want to avoid the BOM, [System.IO.File]::WriteAllText() is the dependable route.

That covers files you write. If the terminal display itself is garbled, the cause sits somewhere else entirely, so start with fixing Japanese mojibake in Antigravity's integrated terminal.

A triage table that starts from the symptom

Here is the same ground, reorganized from the side you actually see: the agent's reply or what lands in the terminal. Error strings are the English originals; localized Windows installs show translated text with the same meaning.

SymptomLikely causeHow to confirmFix
The token '&&' is not a valid statement separator in this version.&& used in Windows PowerShell 5.1$PSVersionTable.PSEdition returns DesktopInstall PowerShell 7. If you must stay on 5.1, split with ; and if ($LASTEXITCODE -eq 0)
A parameter cannot be found that matches parameter name 's'.The 5.1 curl alias is calling Invoke-WebRequestGet-Alias curl returns somethingWrite curl.exe with the extension
The log looks fine when you open it, but downstream tools see it as empty or garbled5.1 Out-File / > wrote UTF-16LEFormat-Hex ./log.txt starts with FF FEPass -Encoding utf8; move to 7 if you also want no BOM
The exit code is 1 no matter how it failedAn external command failed inside -cRun the same thing with -File and the real code appearsEnd -c with exit $LASTEXITCODE, or pass a script with -File
The log shows a failure but the caller gets 0The right side of || succeeded and overwrote the resultRe-run without the ||Never put a || fallback on a command whose success you are judging
... cannot be loaded because running scripts is disabled on this system.Execution policy is Restricted (the Windows client default)Get-ExecutionPolicy -ListSet-ExecutionPolicy -Scope CurrentUser RemoteSigned, unless your organization manages the machine
pwsh is not foundPowerShell 7 is not installed, or not on PATHGet-Command pwsh -ErrorAction SilentlyContinuewinget install --id Microsoft.PowerShell --source winget, then reopen the terminal

The exit-code and encoding rows come from my own runs on 7.6.5; the 5.1 error strings, execution policy, and install rows are taken from Microsoft's documentation. What they share is that each one looks like the agent made a mistake, when really the command landed somewhere other than where it was written for.

Three misunderstandings worth clearing up

"Installing PowerShell 7 replaces 5.1." It does not. 7 installs as pwsh.exe and 5.1 stays as powershell.exe, side by side, which is how Microsoft documents it. It is entirely normal to install 7 and still have your agent's commands running in 5.1. This line tells you which one you are actually in:

(Get-Process -Id $PID).Path

"Setting $ErrorActionPreference = 'Stop' makes external command failures stop the script." Not by default. A non-zero exit from a native command is not treated as a PowerShell error. From PowerShell 7.4 onward, also setting $PSNativeCommandUseErrorActionPreference = $true brings native failures under Stop. The default is $false, and 5.1 does not have the variable at all.

"-Encoding utf8 gives you a BOM-free file on 5.1 too." It does not. In 5.1, utf8 means UTF-8 with a BOM. That is far easier to work with than UTF-16LE, but any parser that chokes on the leading EF BB BF will still choke. If you need no BOM, use utf8NoBOM on 7 (where plain utf8 is also BOM-free), or [System.IO.File]::WriteAllText().

A preflight script to run before handing the shell to an agent

Looking things up in a triage table every time gets old, so I run this once at the start of a Windows session. It is written to run on both 5.1 and 7.

# preflight.ps1 — shell assumptions check before agent work (5.1 / 7)
$r = [ordered]@{}
$r.Edition    = $PSVersionTable.PSEdition
$r.Version    = $PSVersionTable.PSVersion.ToString()
$r.HostPath   = (Get-Process -Id $PID).Path
$r.CurlAlias  = [bool](Get-Alias curl -ErrorAction SilentlyContinue)
$r.ExecPolicy = (Get-ExecutionPolicy).ToString()
$r.HasPwsh    = [bool](Get-Command pwsh -ErrorAction SilentlyContinue)
 
# Probe Out-File's default encoding by writing a file and reading the first two bytes
$tmp = Join-Path $env:TEMP 'enc-probe.txt'
'a' | Out-File -FilePath $tmp
$b = [System.IO.File]::ReadAllBytes($tmp)
$r.OutFileHead = '{0:X2} {1:X2}' -f $b[0], $b[1]
Remove-Item $tmp
 
# Exists only on 7.4+; shows n/a on 5.1
$r.NativeErrPref = if (Test-Path variable:PSNativeCommandUseErrorActionPreference) {
  $PSNativeCommandUseErrorActionPreference } else { 'n/a' }
 
$r.GetEnumerator() | ForEach-Object { '{0,-14} {1}' -f $_.Key, $_.Value }

It relies on $env:TEMP, so it is meant for Windows. I have not kept output from a real Windows machine, so rather than show expected output I would invent, here is how to read each line.

FieldIf you seeWhat to do
EditionDesktopYou are in 5.1. If HasPwsh is True, switch the terminal's default profile to pwsh; if False, install 7
CurlAliasTrueYour rules must say "external commands with their extension"
OutFileHeadFF FEUTF-16LE. Make the agent pass -Encoding utf8. 61 0D or 61 0A means no BOM
ExecPolicyRestrictedPassing scripts with -File will not work yet; settle the policy first
NativeErrPrefFalseNative failures will not stop anything; judge results by $LASTEXITCODE

If you are torn between accommodating 5.1 and moving to 7, my rule is this: stay on 5.1 only when the machine is managed and you cannot install 7; otherwise install 7 and write your rules for 7. Writing every rule twice for 5.1 nearly doubles their length without catching noticeably more.

Put these assumptions in a rules file, not in the conversation

You could just say all of this in chat every time. It does not hold up. Long conversations bury it, and a new session forgets it.

Antigravity lets you keep rules as files. The Customizations panel in hub 2.9.1 lists skills, rules, plugins, and custom agents as separate collapsible sections, and from CLI 1.1.15 onward a markdown-defined agent can name rule files directly in its frontmatter with rules:. That is the shape you want when you would rather apply a few specific rules than inherit an entire tree. If you are unsure whether something belongs in a rule or a skill, I worked through that line in deciding whether an instruction goes in Rules or Skills.

Shell assumptions live in a file; success is read from the exit code. Once I stopped restating these in chat, the back-and-forth mostly went away.

What I keep for Windows is about this short.

---
name: windows-shell
description: Shell assumptions for commands issued on Windows
---
 
- Assume commands run under PowerShell 7 (pwsh)
- Write external commands with their extension (curl.exe / node.exe)
- Pass -Encoding utf8 explicitly when writing files
- End any -c script with exit $LASTEXITCODE
- Never add a || fallback to a command whose success is being judged

The agent picks it up by name.

---
name: release-helper
rules:
  - windows-shell.md
---

Whether a written assumption is actually in effect is a separate question. Configuration can be wrong in a way that gets silently ignored rather than rejected. I covered how to find settings that are quietly doing nothing in how silently ignored config keys slip through CI, and where to block them. Worth reading before you add more rules rather than after.

What to do next

Open your Windows machine and run $PSVersionTable.PSEdition once. If it returns Desktop, installing PowerShell 7 is your first step, and three of the four issues in this article disappear on their own. The exit-code behavior shows up on either generation, so run the preflight script above and keep that one line in your rules file.

If you run Antigravity inside WSL, commands land in bash again, but you trade this set of problems for a different one. When the server itself falls over there, I start with whether to suspect the CPU, WSL, or the version first when "Antigravity server crashed unexpectedly" appears.

I still stop at the same places every time I cross platforms. If the numbers I measured save someone else a little of that time, that is a good outcome.

Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

✦ Tips2026-08-15
When Antigravity Holds a Dozen Projects: How I Stopped Hunting for Yesterday's Conversation
As Antigravity projects pile up, the conversation sidebar turns into a morning scrolling ritual. Now that 2.8.0 remembers collapsed state, here is how I reworked project granularity, conversation naming, and launch flags.
✦ Tips2026-11-19
Before an Agent Clones Your Template Repo, Hand It a Trap Index: One Line per Fix, the Reasons Kept in One Place
When you copy a running site to start the next one, an agent carries the fixes over but leaves the reasons behind. A symptom-first trap index, a one-page porting plan written before the copy, and three small scripts that catch drift between the index, the source docs and their mirrors.
✦ Tips2026-11-17
Why a Small sizes Value Shrinks the Image Itself, and the CSS Line to Add When width and height Attributes Stretch It
The day I added responsive images, one artwork shrank and another stretched sideways. How sizes sets the displayed size, the one CSS line for width and height attributes, and how to work out sizes for tall art in a frame, with numbers and a check script.