ab2d3ed8cd
Windows tray "switch" that routes all Claude MSIX-app traffic through a SOCKS5/HTTP proxy or a VLESS+Reality tunnel (embedded Xray-core), with a fail-closed Windows Firewall lock. Runs de-elevated so it launches the user's normal Claude instance; elevates only for firewall changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
58 lines
2.3 KiB
PowerShell
58 lines
2.3 KiB
PowerShell
<#
|
|
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
|
|
}
|
|
}
|