Test-CorePowerShell.ps1

function Test-CorePowerShell {
    param(
        [string]$ScriptPath,
        [hashtable]$BoundParameters,
        [string[]]$RemainingArgs = @(),
        [switch]$Verbose
    )

    if ($PSVersionTable.PSEdition -ne 'Desktop') { return }

    $markerFile = Join-Path ([System.Environment]::GetFolderPath('UserProfile')) '.pwrclaude-no-pwsh-prompt'
    if (Test-Path $markerFile) { return }

    Write-Host ""
    Write-Host "You are running Windows PowerShell 5.x. PowerShell 7+ (pwsh) is recommended." -ForegroundColor Yellow
    Write-Host "Install with: winget install Microsoft.PowerShell" -ForegroundColor Cyan
    Write-Host ""
    $choice = Read-Host "Install pwsh now? [Y]es / [N]o / [D]on't ask again"

    switch ($choice.Trim().ToUpper()[0]) {
        'Y' {
            Write-Host "Installing PowerShell 7+..." -ForegroundColor Cyan
            winget install --id Microsoft.PowerShell --source winget
        }
        'D' {
            New-Item -ItemType File -Path $markerFile -Force | Out-Null
            Write-Host "Won't ask again. Delete '$markerFile' to re-enable this prompt." -ForegroundColor Gray
        }
    }

    # After install: if pwsh is now available, restart the caller under it.
    if ($choice.Trim().ToUpper()[0] -eq 'Y') {
        $pwshExe = (Get-Command pwsh -ErrorAction SilentlyContinue)?.Source
        if (-not $pwshExe) {
            $pwshExe = Join-Path $env:ProgramFiles 'PowerShell\7\pwsh.exe'
        }
        if (Test-Path $pwshExe) {
            Write-Host "Restarting with pwsh..." -ForegroundColor Cyan
            $relaunchArgs = [System.Collections.Generic.List[string]]::new()
            foreach ($kv in $BoundParameters.GetEnumerator()) {
                if ($kv.Key -eq 'ClaudeArgs') { continue }
                if ($kv.Value -is [switch]) {
                    if ($kv.Value) { $relaunchArgs.Add("-$($kv.Key)") }
                } else {
                    $relaunchArgs.Add("-$($kv.Key)")
                    $relaunchArgs.Add("$($kv.Value)")
                }
            }
            if ($Verbose) { $relaunchArgs.Add('-Verbose') }
            $relaunchArgs.AddRange([string[]]$RemainingArgs)
            & $pwshExe -NoProfile -ExecutionPolicy Bypass -File $ScriptPath @relaunchArgs
            exit $LASTEXITCODE
        } else {
            Write-Host "pwsh not found after install — please restart your shell and run again." -ForegroundColor Yellow
        }
    }

    Write-Host ""
}