Skip to content

fix: rename $Args to $InstallArgs in install.ps1 for Windows#478

Open
vaibhavkumar779 wants to merge 1 commit into
JuliusBrussee:mainfrom
vaibhavkumar779:fix/windows-install-args-conflict
Open

fix: rename $Args to $InstallArgs in install.ps1 for Windows#478
vaibhavkumar779 wants to merge 1 commit into
JuliusBrussee:mainfrom
vaibhavkumar779:fix/windows-install-args-conflict

Conversation

@vaibhavkumar779

Copy link
Copy Markdown

Problem

install.ps1 uses $Args as a param() name, but $Args is a PowerShell automatic variable that cannot be overwritten inside Invoke-Expression. When users run the documented one-liner:

irm https://raw.githubusercontent.com/JuliusBrussee/caveman/main/install.ps1 | iex

PowerShell throws:

Invoke-Expression : Cannot overwrite variable Args because the variable has been optimized.
    + CategoryInfo          : WriteError: (Args:String) [Invoke-Expression], SessionStateUnauthorizedAccessException
    + FullyQualifiedErrorId : VariableNotWritableRare,Microsoft.PowerShell.Commands.InvokeExpressionCommand

This breaks the install on every Windows machine using PowerShell 5.1 (the default shell).

Why it happens

When a script is piped to Invoke-Expression, PowerShell compiles the script block in the caller's scope. The automatic $Args variable is marked as an optimized/read-only variable in that context, so param([string[]]$Args) fails because it tries to reassign it.

Running the script as a file (& .\install.ps1) works fine because it gets its own scope — but that defeats the purpose of the one-liner install.

Environment

  • OS: Windows 11
  • PowerShell: 5.1.26100.4061
  • Editor: VS Code with GitHub Copilot agent
  • Node: v22.x

Fix

1. install.ps1 — Rename parameter (3 occurrences)

Before After
[string[]]$Args [string[]]$InstallArgs
@Args (splat in local path) @InstallArgs
@Args (splat in npx path) @InstallArgs

Also updated the header comment to use the download-then-run pattern and added a NOTE block explaining why $Args cannot be used.

2. README.md — Updated Windows install command

-# Windows (PowerShell 5.1+)
-irm https://raw.githubusercontent.com/JuliusBrussee/caveman/main/install.ps1 | iex
+# Windows (PowerShell 5.1+)
+$f = "$env:TEMP\caveman-install.ps1"; irm https://raw.githubusercontent.com/JuliusBrussee/caveman/main/install.ps1 -OutFile $f; & $f; Remove-Item $f

3. INSTALL.md — Updated install command + troubleshooting

  • Updated the Windows install command to match README
  • Replaced the irm | iex troubleshooting bullet with an explicit warning and the correct command

Testing

  1. Before fix: irm ... | iex → crashes with VariableNotWritableRare
  2. After fix (download-then-run): Downloads to %TEMP%, runs in own scope, installs successfully, cleans up temp file
  3. After fix (local clone): & .\install.ps1 still works (no regression)
  4. Verified: All 7 skills installed successfully for GitHub Copilot on Windows 11

Checklist

  • $Args$InstallArgs in install.ps1 (all 3 occurrences)
  • README.md Windows command updated
  • INSTALL.md Windows command updated
  • INSTALL.md troubleshooting section updated
  • No breaking changes for macOS/Linux (install.sh untouched)
  • No breaking changes for local clone usage (& .\install.ps1 still works)

…ility

$Args is a PowerShell automatic variable that cannot be overwritten inside
Invoke-Expression. When users run irm ... | iex, PowerShell throws:

    Cannot overwrite variable Args because the variable has been optimized.

This rename to $InstallArgs fixes the parameter conflict. The README and
INSTALL.md are also updated to use the download-then-run pattern which avoids
Invoke-Expression scope issues entirely.

Tested on Windows 11 with PowerShell 5.1 and VS Code GitHub Copilot agent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant