All symptoms日本語

T02

The second value passed with -File disappears without an error

Symptom

You pass -Path a b to a [string[]] parameter, but the script only gets a. No error, exit code 0.

Check it in 30 seconds

Paste into Windows PowerShell 5.1. It only creates files under your %TEMP% folder. If the last line says REPRODUCED, it happens on your machine.

$d = Join-Path $env:TEMP ('cc-trap-' + (Get-Date -Format 'yyyyMMddHHmmss')); New-Item -ItemType Directory $d -Force | Out-Null
[IO.File]::WriteAllText("$d\arr.ps1", 'param([string[]]$Path) "count=$($Path.Count) first=$($Path[0])"')
$o = powershell -NoProfile -ExecutionPolicy Bypass -File "$d\arr.ps1" -Path a b; $e = $LASTEXITCODE
"$o  exit=$e"
if ($o -eq 'count=1 first=a' -and $e -eq 0) { 'REPRODUCED' } else { 'NOT REPRODUCED' }

Why it happens

With -File, arguments arrive as plain strings. -Path takes a; b matches no parameter, goes into $args and is dropped.

Fix

Add [CmdletBinding()] before param so an extra argument stops the script with an error. Take several values as one string and split it yourself (see T03).

[CmdletBinding()]
param([string]$Path)
$paths = $Path -split ','

On the author's machine

count=1 first=a, exit 0 (with [CmdletBinding()]: stopped with exit 1)

Author's machine: Windows 11 / Windows PowerShell 5.1.26100 / Python 3.13.7 / Claude Code 2.1.304, Japanese Windows (code page 932). Checked 2026-10-20 to 22.

If you searched for

Related

cc-win-kit bundles the parts that avoid these traps from the start: a write guard (with onFailure: block), an unattended runner, a doctor that scans your files and hook settings, CLAUDE.md templates and the full test suite.

cc-win-kit ($19 on Payhip)

Other symptoms