<# claude-proxy.ps1 - CLI. See README.md. GUI is claude-proxy-gui.ps1. #> [CmdletBinding()] param( [ValidateSet('run', 'on', 'off', 'install-firewall', 'remove-firewall', 'status', 'verify')] [string]$Action = 'status', [switch]$NoRestart ) $ErrorActionPreference = 'Stop' . (Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) 'claude-proxy.lib.ps1') function Elevate([string]$action) { Start-Process -FilePath (Get-Process -Id $PID).Path -Verb RunAs -Wait -ArgumentList @( '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', "`"$PSCommandPath`"", '-Action', $action) } $restart = -not $NoRestart switch ($Action) { 'status' { $s = Get-ProxyState Write-Host "Claude proxy - status" -ForegroundColor Cyan Write-Host (" switch : {0}" -f ($(if ($s.On) { 'ON (locked to proxy)' } else { 'OFF' }))) Write-Host " proxy : $($s.Config.proxy)" Write-Host (" reachable : {0}" -f $s.Reachable) Write-Host " exe : $($s.App.Exe)" Write-Host " firewall : $($s.Firewall)" Write-Host (" claude : {0}" -f ($(if (-not $s.Running) { 'not running' } elseif ($s.Proxied) { 'running (proxied)' } else { 'running (direct)' }))) } { $_ -in 'on', 'run' } { if (-not (Test-Admin)) { Elevate 'on'; break } Write-Host "Turning proxy ON..." -ForegroundColor Cyan if ($restart) { Enable-Proxy -RestartClaude } else { Enable-Proxy } Write-Host "Done. Claude routed through proxy." -ForegroundColor Green } 'off' { if (-not (Test-Admin)) { Elevate 'off'; break } Write-Host "Turning proxy OFF..." -ForegroundColor Yellow if ($restart) { Disable-Proxy -RestartClaude } else { Disable-Proxy } Write-Host "Done. Firewall lock removed." -ForegroundColor Green } 'install-firewall' { if (-not (Test-Admin)) { Elevate 'install-firewall'; break } Enable-Proxy; Write-Host "Firewall lock installed." -ForegroundColor Green } 'remove-firewall' { if (-not (Test-Admin)) { Elevate 'remove-firewall'; break } Disable-Proxy; Write-Host "Firewall lock removed." -ForegroundColor Green } 'verify' { $r = Invoke-Verify $color = if ($r.Ok) { 'Green' } elseif ($r.Verdict -like 'ПРОВАЛ*') { 'Red' } else { 'Yellow' } $r.Lines | ForEach-Object { Write-Host $_ -ForegroundColor $color } Write-Host " лог : $($r.LogPath)" -ForegroundColor DarkGray } }