# Claude Code manager for Windows (claude.mad-gamer.com). # # irm https://claude.mad-gamer.com/win | iex # # Installs, updates, repairs or uninstalls Claude Code, with screen reader # mode on from the very first launch. Asks what to do; pressing Enter takes # the answer in brackets. No administrator rights are needed: everything # goes in the current user's folders and registry. # # Installing: # 1. Checks Windows (64-bit, Windows 10 1809 or later) and offers Git for # Windows, which Claude Code uses for its Bash tool (without it, Claude # Code uses PowerShell instead). Git is installed for the current user # only, from the latest official release on GitHub, after checking its # SHA-256 and digital signature. # 2. Turns on screen reader mode ("axScreenReader": true in # %USERPROFILE%\.claude\settings.json) before Claude Code first runs, so # even its sign-in screens are read well. Other settings are kept. # 3. Runs Anthropic's official installer, https://claude.ai/install.ps1, in # a separate PowerShell, so its own `exit` cannot close this window. # 4. Puts %USERPROFILE%\.local\bin on your user PATH, because the official # installer does not, and tells open programs about the change. # # Uninstalling removes Claude Code the way Anthropic's documentation # describes, and also copies installed with npm or WinGet, if there are # any. Your settings, sign-in and history stay unless you choose to remove # them too. # # Without questions (for scripts), name what to do: # # & ([scriptblock]::Create((irm https://claude.mad-gamer.com/win))) install [latest|stable|VERSION] [--no-git] [--no-screen-reader] # ... update | uninstall [--everything] | screen-reader on|off | status # # $LASTEXITCODE is 0 when that worked and 1 when it did not. # # Output is plain lines for screen readers: no colours, progress bars or # cursor movement. Plain ASCII, for Windows PowerShell 5.1 and PowerShell 7. # Served from /var/www/claude/win on mad-gamer.com (see # claude.mad-gamer.com.conf). & { Set-StrictMode -Version 2 $ErrorActionPreference = 'Stop' # Windows PowerShell's download progress bar is slow and visual only. $ProgressPreference = 'SilentlyContinue' # Older Windows PowerShell may not offer TLS 1.2 on its own. try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } $ManagerVersion = '1.0.0' $OfficialInstaller = 'https://claude.ai/install.ps1' $GitRelease = 'https://api.github.com/repos/git-for-windows/git/releases/latest' $BinDir = Join-Path $env:USERPROFILE '.local\bin' $ClaudeExe = Join-Path $BinDir 'claude.exe' $ShareDir = Join-Path $env:USERPROFILE '.local\share\claude' $StateDir = Join-Path $env:USERPROFILE '.local\state\claude' $CacheDir = Join-Path $env:USERPROFILE '.cache\claude' if ($env:CLAUDE_CONFIG_DIR) { $ConfigDir = $env:CLAUDE_CONFIG_DIR $StateFile = Join-Path $env:CLAUDE_CONFIG_DIR '.claude.json' } else { $ConfigDir = Join-Path $env:USERPROFILE '.claude' $StateFile = Join-Path $env:USERPROFILE '.claude.json' } $Settings = Join-Path $ConfigDir 'settings.json' # Remembers whether this script put the bin folder on the PATH. $MarkerKey = 'HKCU:\Software\MadGamer\ClaudeCodeManager' $State = @{ Interactive = $false } function Say([string]$Text = '') { Write-Host $Text } # Stops the current action with a reason (caught in Main). function Stop-Manager([string]$Why) { throw (New-Object System.InvalidOperationException $Why) } # --- questions --------------------------------------------------------- # A yes or no question; Enter takes the default. Without questions (an # action named on the command line), the default is the answer. function Ask-YesNo([string]$Question, [bool]$Default) { if (-not $State.Interactive) { return $Default } $hint = if ($Default) { 'Y/n' } else { 'y/N' } while ($true) { $answer = ([string](Read-Host "$Question ($hint)")).Trim().ToLowerInvariant() if ($answer -eq '') { return $Default } if ($answer -eq 'y' -or $answer -eq 'yes') { return $true } if ($answer -eq 'n' -or $answer -eq 'no') { return $false } Say 'Please answer y for yes or n for no.' } } # A numbered choice; Enter takes choice 1. Returns the number. function Ask-Choice([string]$Question, [string[]]$Choices) { Say $Question for ($i = 0; $i -lt $Choices.Count; $i++) { Say "$($i + 1). $($Choices[$i])" } while ($true) { $answer = ([string](Read-Host "Choice, 1 to $($Choices.Count) (1)")).Trim() if ($answer -eq '') { return 1 } $n = 0 if ([int]::TryParse($answer, [ref]$n) -and $n -ge 1 -and $n -le $Choices.Count) { return $n } Say "Please type a number from 1 to $($Choices.Count)." } } # --- Windows ----------------------------------------------------------- function Test-Windows { if (-not [Environment]::Is64BitOperatingSystem) { Stop-Manager 'Claude Code needs 64-bit Windows.' } $v = [Environment]::OSVersion.Version if ($v.Major -lt 10 -or $v.Build -lt 17763) { Stop-Manager "Claude Code needs Windows 10 version 1809 or later, or Windows Server 2019 or later. This is Windows $v." } } function Test-Elevated { $id = [Security.Principal.WindowsIdentity]::GetCurrent() return (New-Object Security.Principal.WindowsPrincipal $id).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } function Test-Arm64 { return ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64' -or "$env:PROCESSOR_ARCHITEW6432" -eq 'ARM64') } # A 64-bit PowerShell for the official installer, which refuses 32-bit. function Get-PowerShellExe { if (-not [Environment]::Is64BitProcess) { $native = Join-Path $env:windir 'sysnative\WindowsPowerShell\v1.0\powershell.exe' if (Test-Path -LiteralPath $native) { return $native } } foreach ($name in @('powershell.exe', 'pwsh.exe')) { $p = Join-Path $PSHOME $name if (Test-Path -LiteralPath $p) { return $p } } return (Join-Path $env:windir 'System32\WindowsPowerShell\v1.0\powershell.exe') } # Runs a program in this console (so it can show its own screens) and # returns its exit code. Waits for that program only: Start-Process -Wait # would also wait for anything it leaves running in the background. function Start-InConsole([string]$File, [string]$Arguments) { $p = Start-Process -FilePath $File -ArgumentList $Arguments -NoNewWindow -PassThru $null = $p.Handle # keeps the exit code readable after it ends $p.WaitForExit() return $p.ExitCode } # Runs a program and returns its output lines; errors and stderr are # ignored (with 'Stop', Windows PowerShell would treat stderr as an error). function Get-Output([string]$File, [string[]]$Arguments) { $ErrorActionPreference = 'Continue' try { return @(& $File @Arguments 2>$null) } catch { return @() } } function New-WorkFolder { $dir = Join-Path ([IO.Path]::GetTempPath()) ('mg-claude-' + [guid]::NewGuid().ToString('N').Substring(0, 8)) New-Item -ItemType Directory -Force -Path $dir | Out-Null return $dir } # --- Git for Windows --------------------------------------------------- function Find-GitBash { $candidates = @() if ($env:CLAUDE_CODE_GIT_BASH_PATH) { $candidates += $env:CLAUDE_CODE_GIT_BASH_PATH } if ($env:ProgramFiles) { $candidates += (Join-Path $env:ProgramFiles 'Git\bin\bash.exe') } if (${env:ProgramFiles(x86)}) { $candidates += (Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe') } if ($env:LOCALAPPDATA) { $candidates += (Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe') } $git = Get-Command git.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 if ($git) { $candidates += (Join-Path (Split-Path (Split-Path $git.Source)) 'bin\bash.exe') } foreach ($p in $candidates) { if ($p -and (Test-Path -LiteralPath $p)) { return $p } } return $null } function Install-Git { Say 'Finding the latest Git for Windows...' $release = Invoke-RestMethod -Uri $GitRelease -UseBasicParsing -Headers @{ 'User-Agent' = 'claude.mad-gamer.com'; 'Accept' = 'application/vnd.github+json' } $pattern = if (Test-Arm64) { '^Git-[0-9.]+-arm64\.exe$' } else { '^Git-[0-9.]+-64-bit\.exe$' } $asset = @($release.assets | Where-Object { $_.name -match $pattern }) | Select-Object -First 1 if (-not $asset) { Stop-Manager 'the latest Git for Windows release has no installer for this computer.' } $work = New-WorkFolder try { $file = Join-Path $work $asset.name Say "Downloading $($asset.name)..." Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $file -UseBasicParsing $digest = $asset.PSObject.Properties['digest'] if ($digest -and "$($digest.Value)" -match '^sha256:([0-9a-f]{64})$') { $actual = (Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash.ToLowerInvariant() if ($actual -ne $Matches[1]) { Stop-Manager 'the Git for Windows download did not match its SHA-256 checksum.' } } $signature = Get-AuthenticodeSignature -LiteralPath $file if ($signature.Status -ne 'Valid') { Stop-Manager "the Git for Windows installer's digital signature is not valid ($($signature.Status))." } # Git's installer goes to Program Files from an elevated PowerShell # and to the user's own folder otherwise; it never asks for rights. if (Test-Elevated) { Say 'Installing Git for Windows for all users (this PowerShell runs as administrator). This takes a minute or two...' } else { Say 'Installing Git for Windows for you only. This takes a minute or two...' } $code = Start-InConsole $file '/VERYSILENT /NORESTART /NOCANCEL /SP- /SUPPRESSMSGBOXES /CURRENTUSER' if ($code -ne 0) { Stop-Manager "the Git for Windows installer stopped with code $code." } } finally { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue } $bash = Find-GitBash if (-not $bash) { Stop-Manager 'Git for Windows was installed, but its bash.exe cannot be found.' } Say "Git for Windows is installed ($bash)." } # --- screen reader setting --------------------------------------------- function Read-Text([string]$Path) { if (-not (Test-Path -LiteralPath $Path)) { return '' } return [IO.File]::ReadAllText($Path) } function Write-Text([string]$Path, [string]$Text) { [IO.File]::WriteAllText($Path, $Text, (New-Object System.Text.UTF8Encoding $false)) } function Test-JsonObject([string]$Text) { try { $o = $Text | ConvertFrom-Json return ($null -ne $o -and $o -is [System.Management.Automation.PSCustomObject]) } catch { return $false } } # $true, $false or $null: the axScreenReader value in the settings. function Get-ScreenReader { $text = Read-Text $Settings $m = [regex]::Match($text, '"axScreenReader"\s*:\s*(true|false)') if (-not $m.Success) { return $null } return ($m.Groups[1].Value -eq 'true') } # Sets the value, keeping the rest of the file exactly as it is (no other # key is touched or reformatted). function Set-ScreenReader([bool]$On) { $value = if ($On) { 'true' } else { 'false' } New-Item -ItemType Directory -Force -Path $ConfigDir | Out-Null $text = Read-Text $Settings if ($text.Trim() -eq '') { Write-Text $Settings "{`n `"axScreenReader`": $value`n}`n" return } if (-not (Test-JsonObject $text)) { Stop-Manager "$Settings is not a valid settings file (it must be a JSON object). Fix or remove it, then run this again." } $rx = [regex]'("axScreenReader"\s*:\s*)(true|false)' if ($rx.IsMatch($text)) { $new = $rx.Replace($text, ('${1}' + $value), 1) } else { $open = [regex]::Match($text, '^\s*\{') $rest = $text.Substring($open.Length) $sep = if ($rest -match '^\s*\}') { "`n" } else { ',' } $new = $text.Substring(0, $open.Length) + "`n `"axScreenReader`": $value$sep" + $rest } if (-not (Test-JsonObject $new)) { Stop-Manager "could not change $Settings safely. Add `"axScreenReader`": $value to it yourself." } Write-Text $Settings $new } function Show-OverrideNote { $v = $env:CLAUDE_AX_SCREEN_READER if (-not $v) { $v = [Environment]::GetEnvironmentVariable('CLAUDE_AX_SCREEN_READER', 'User') } if ($v -eq '0' -or $v -eq 'false') { Say 'Note: the environment variable CLAUDE_AX_SCREEN_READER is set to 0, which turns screen reader mode off whatever the setting says. Remove it to use the setting.' } } # --- PATH ---------------------------------------------------------------- function Get-UserPathRaw { $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment') if (-not $key) { return '' } try { return [string]$key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) } finally { $key.Close() } } # Writes the user PATH as an expandable string (as Windows keeps it), then # tells open programs, such as Explorer, that the environment changed. function Set-UserPathRaw([string]$Value) { $key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment') try { $key.SetValue('Path', $Value, [Microsoft.Win32.RegistryValueKind]::ExpandString) } finally { $key.Close() } # Each change made this way broadcasts WM_SETTINGCHANGE. [Environment]::SetEnvironmentVariable('MG_CLAUDE_PATH_REFRESH', '1', 'User') [Environment]::SetEnvironmentVariable('MG_CLAUDE_PATH_REFRESH', $null, 'User') } function Test-PathListHas([string]$List, [string]$Dir) { $want = $Dir.TrimEnd('\') foreach ($entry in ($List -split ';')) { if (-not $entry) { continue } $have = [Environment]::ExpandEnvironmentVariables($entry.Trim('"')).TrimEnd('\') if ($have -ieq $want) { return $true } } return $false } function Test-OnPath { return ((Test-PathListHas (Get-UserPathRaw) $BinDir) -or (Test-PathListHas ([Environment]::GetEnvironmentVariable('Path', 'Machine')) $BinDir)) } function Add-ToPath { if (Test-OnPath) { Say "$BinDir is already on your PATH." } else { $raw = (Get-UserPathRaw).TrimEnd(';') $new = if ($raw) { "$raw;$BinDir" } else { $BinDir } Set-UserPathRaw $new New-Item -Path $MarkerKey -Force | Out-Null Set-ItemProperty -Path $MarkerKey -Name 'PathAdded' -Value $BinDir Say "Added $BinDir to your user PATH." } if (-not (Test-PathListHas $env:Path $BinDir)) { $env:Path = "$env:Path;$BinDir" } } # Takes the folder off the PATH only if this script put it there. function Remove-FromPath { $marker = Get-ItemProperty -Path $MarkerKey -Name 'PathAdded' -ErrorAction SilentlyContinue if (-not $marker) { return } $keep = @() foreach ($entry in ((Get-UserPathRaw) -split ';')) { if (-not $entry) { continue } if ([Environment]::ExpandEnvironmentVariables($entry.Trim('"')).TrimEnd('\') -ieq $BinDir.TrimEnd('\')) { continue } $keep += $entry } Set-UserPathRaw ($keep -join ';') Remove-Item -Path $MarkerKey -Recurse -Force -ErrorAction SilentlyContinue Say "Took $BinDir back off your user PATH." } # --- state ------------------------------------------------------------- function Get-InstalledVersion { if (-not (Test-Path -LiteralPath $ClaudeExe)) { return $null } $out = Get-Output $ClaudeExe @('--version') | Select-Object -First 1 if ("$out" -match '(\d+\.\d+\.\d+\S*)') { return $Matches[1] } return $null } # Claude Code processes running from the folders an uninstall removes. function Get-ClaudeProcesses { $dirs = @(($BinDir.TrimEnd('\') + '\'), ($ShareDir.TrimEnd('\') + '\')) return @(Get-Process -ErrorAction SilentlyContinue | Where-Object { $path = $null try { $path = $_.Path } catch { } if (-not $path) { return $false } foreach ($d in $dirs) { if ($path.StartsWith($d, [StringComparison]::OrdinalIgnoreCase) -and ($_.ProcessName -eq 'claude' -or $d -ne $dirs[0])) { return $true } } return $false }) } # Other copies of Claude Code: npm, winget, legacy. function Find-OtherInstalls { $found = @() $npm = Get-Command npm.cmd -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 if ($npm) { $out = Get-Output $npm.Source @('ls', '-g', '--depth=0', '@anthropic-ai/claude-code') if ("$out" -match '@anthropic-ai/claude-code@') { $found += 'npm' } } $winget = Get-Command winget.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 if ($winget) { $out = Get-Output $winget.Source @('list', '--id', 'Anthropic.ClaudeCode', '--exact', '--accept-source-agreements', '--disable-interactivity') if ("$out" -match 'Anthropic\.ClaudeCode') { $found += 'winget' } } if (Test-Path -LiteralPath (Join-Path $ConfigDir 'local')) { $found += 'legacy' } return $found } function Get-OtherDescription([string]$Kind) { switch ($Kind) { 'npm' { return 'a copy installed with npm (@anthropic-ai/claude-code)' } 'winget' { return 'a copy installed with WinGet (Anthropic.ClaudeCode)' } 'legacy' { return "an old local install in $(Join-Path $ConfigDir 'local')" } } return $Kind } function Remove-Other([string]$Kind) { switch ($Kind) { 'npm' { $null = Get-Output 'npm.cmd' @('uninstall', '-g', '@anthropic-ai/claude-code'); return ($LASTEXITCODE -eq 0) } 'winget' { $null = Get-Output 'winget.exe' @('uninstall', '--id', 'Anthropic.ClaudeCode', '--exact', '--silent', '--accept-source-agreements', '--disable-interactivity'); return ($LASTEXITCODE -eq 0) } 'legacy' { Remove-Item -LiteralPath (Join-Path $ConfigDir 'local') -Recurse -Force; return $true } } return $false } function Show-Status { $version = Get-InstalledVersion if ($version) { Say "Claude Code $version is installed, in $BinDir." } elseif (Test-Path -LiteralPath $ClaudeExe) { Say "Claude Code is in $BinDir, but it does not run." } else { Say 'Claude Code is not installed.' } $sr = Get-ScreenReader if ($sr -eq $true) { Say 'Screen reader mode is on.' } elseif ($sr -eq $false) { Say 'Screen reader mode is off.' } else { Say 'Screen reader mode is off (not set).' } Show-OverrideNote if (Test-OnPath) { Say "$BinDir is on your PATH." } else { Say "$BinDir is not on your PATH yet." } $bash = Find-GitBash if ($bash) { Say "Git for Windows is installed ($bash)." } else { Say 'Git for Windows is not installed, so Claude Code uses PowerShell for commands.' } foreach ($o in (Find-OtherInstalls)) { Say "Also found: $(Get-OtherDescription $o)." } } # --- actions ------------------------------------------------------------- function Invoke-Install([string]$Target, [bool]$ScreenReader, [bool]$WithGit) { Test-Windows Say '' Say 'Step 1 of 4: Git for Windows.' $bash = Find-GitBash if ($bash) { Say "Git for Windows is already installed ($bash)." } elseif (-not $WithGit) { Say 'Skipped. Claude Code will use PowerShell for commands.' } elseif (Ask-YesNo 'Git for Windows is not installed. Claude Code uses it to run commands with Bash; without it, Claude Code uses PowerShell. Install it now?' $true) { Install-Git } else { Say 'Skipped. Claude Code will use PowerShell for commands.' } Say '' Say 'Step 2 of 4: screen reader mode.' if ($ScreenReader) { Set-ScreenReader $true Say "Screen reader mode is on, in $Settings." Show-OverrideNote } else { Say 'Left as it is.' } Say '' Say 'Step 3 of 4: the official Claude Code installer.' $work = New-WorkFolder try { $script = Join-Path $work 'install.ps1' try { Invoke-WebRequest -Uri $OfficialInstaller -OutFile $script -UseBasicParsing } catch { Stop-Manager "could not download $OfficialInstaller. Check your internet connection." } if (-not ((Read-Text $script) -match 'claude-code-releases')) { Stop-Manager "$OfficialInstaller did not return the installer. Check your internet connection." } # A separate PowerShell, so the installer's `exit` ends only that # one. Run as a script block, so the execution policy does not apply. $quoted = $script.Replace("'", "''") $command = "& ([scriptblock]::Create([IO.File]::ReadAllText('$quoted'))) $Target" $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command)) $code = Start-InConsole (Get-PowerShellExe) "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded" if ($code -ne 0) { Stop-Manager 'the official installer did not finish (see its message above).' } } finally { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue } if (-not (Test-Path -LiteralPath $ClaudeExe)) { Stop-Manager "the official installer finished, but $ClaudeExe is not there." } Say '' Say 'Step 4 of 4: your PATH.' Add-ToPath $version = Get-InstalledVersion if (-not $version) { Stop-Manager "Claude Code was installed in $BinDir but does not run. Run `"$ClaudeExe`" doctor to see why." } Say '' Say "Done. Claude Code $version is installed." Say 'To start it, open a new PowerShell or Command Prompt window and type: claude' } function Invoke-Update { if (-not (Test-Path -LiteralPath $ClaudeExe)) { Stop-Manager 'Claude Code is not installed here, so there is nothing to update. Choose Install instead.' } Say 'Checking for an update...' if ((Start-InConsole $ClaudeExe 'update') -ne 0) { Stop-Manager 'the update did not finish (see the message above).' } Add-ToPath Say "Claude Code is now $(Get-InstalledVersion)." } function Invoke-Uninstall([bool]$Everything) { $others = @(Find-OtherInstalls) $present = (Test-Path -LiteralPath $ClaudeExe) -or (Test-Path -LiteralPath $ShareDir) if (-not $present -and $others.Count -eq 0) { Say 'Claude Code is not installed.' } else { $running = @(Get-ClaudeProcesses) if ($running.Count -gt 0) { Say "Claude Code is running ($($running.Count) process(es)). It has to be closed to be removed." if (-not (Ask-YesNo 'Close it now? Unsaved work in Claude Code is lost.' $true)) { Stop-Manager 'Claude Code is still running. Close it, then run this again.' } $running | Stop-Process -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 } Say 'Removing Claude Code...' foreach ($item in @($ClaudeExe, $ShareDir, $StateDir, $CacheDir, (Join-Path $ConfigDir 'downloads'))) { if (Test-Path -LiteralPath $item) { try { Remove-Item -LiteralPath $item -Recurse -Force } catch { Stop-Manager "could not remove $item ($($_.Exception.Message)). Close Claude Code and run this again." } } } foreach ($o in $others) { if (Ask-YesNo "Also remove $(Get-OtherDescription $o)?" $true) { if (Remove-Other $o) { Say 'Removed.' } else { Say "Could not remove $(Get-OtherDescription $o); remove it yourself." } } } } # The PATH entry comes out only if this script added it and nothing # else is in the folder. $leftover = @(Get-ChildItem -LiteralPath $BinDir -Force -ErrorAction SilentlyContinue) if ($leftover.Count -eq 0) { Remove-FromPath } elseif (Get-ItemProperty -Path $MarkerKey -Name 'PathAdded' -ErrorAction SilentlyContinue) { Say "Other programs are in $BinDir, so it stays on your PATH." } if ($Everything) { foreach ($item in @($ConfigDir, $StateFile)) { if (Test-Path -LiteralPath $item) { Remove-Item -LiteralPath $item -Recurse -Force } } Say "Also removed your settings, sign-in and history ($ConfigDir and $StateFile)." } else { Say "Your settings, sign-in and history are kept, in $ConfigDir, so installing again picks up where you left off." } $still = Get-Command claude -ErrorAction SilentlyContinue | Select-Object -First 1 if ($still) { Say "Note: another claude is still on your PATH, at $($still.Source)." } Say 'Claude Code is uninstalled.' } function Show-Usage { Say 'Usage: install [latest|stable|VERSION] [--no-git] [--no-screen-reader] | update | uninstall [--everything] | screen-reader on|off | status' Say 'With nothing named, it asks what to do.' } function Invoke-Menu { Show-Status Say '' $installed = Test-Path -LiteralPath $ClaudeExe $sr = Get-ScreenReader $toggle = if ($sr -eq $true) { 'Turn screen reader mode off' } else { 'Turn screen reader mode on' } if (-not $installed) { $choice = @('install', 'toggle', 'uninstall', 'quit')[(Ask-Choice 'What would you like to do?' @('Install Claude Code', $toggle, 'Uninstall leftovers', 'Quit')) - 1] } else { $choice = @('update', 'install', 'toggle', 'uninstall', 'quit')[(Ask-Choice 'What would you like to do?' @('Update Claude Code', 'Repair: install again, and check screen reader mode and the PATH', $toggle, 'Uninstall Claude Code', 'Quit')) - 1] } switch ($choice) { 'install' { $on = Ask-YesNo 'Turn on screen reader mode?' $true Invoke-Install '' $on $true } 'update' { Invoke-Update } 'toggle' { if ($sr -eq $true) { Set-ScreenReader $false; Say 'Screen reader mode is off.' } else { Set-ScreenReader $true; Say 'Screen reader mode is on.'; Show-OverrideNote } } 'uninstall' { if (-not (Ask-YesNo 'Uninstall Claude Code?' $false)) { Say 'Nothing was changed.'; return } $all = Ask-YesNo 'Also remove your Claude Code settings, sign-in and history?' $false Invoke-Uninstall $all } default { Say 'Nothing was changed.' } } } function Main([string[]]$Arguments) { Say "Claude Code manager $ManagerVersion, from claude.mad-gamer.com." $action = '' $target = '' $screenReader = $true $withGit = $true $everything = $false $onOff = '' if ($Arguments.Count -gt 0) { $action = [string]$Arguments[0] } foreach ($arg in @($Arguments | Select-Object -Skip 1)) { $a = [string]$arg if ($a -match '^(latest|stable|\d+\.\d+\.\d+(-\S+)?)$') { $target = $a } elseif ($a -eq '--no-screen-reader') { $screenReader = $false } elseif ($a -eq '--no-git') { $withGit = $false } elseif ($a -eq '--everything') { $everything = $true } elseif ($a -eq 'on' -or $a -eq 'off') { $onOff = $a } else { Show-Usage; Stop-Manager "unknown option: $a" } } switch ($action) { '' { if ([Console]::IsInputRedirected) { Show-Usage; Stop-Manager 'there is no console to ask questions in, so name what to do.' } $State.Interactive = $true Invoke-Menu } { $_ -eq 'install' -or $_ -eq 'repair' } { Invoke-Install $target $screenReader $withGit } { $_ -eq 'update' -or $_ -eq 'upgrade' } { Invoke-Update } { $_ -eq 'uninstall' -or $_ -eq 'remove' } { Invoke-Uninstall $everything } 'status' { Show-Status } 'screen-reader' { if ($onOff -eq 'on') { Set-ScreenReader $true; Say 'Screen reader mode is on.'; Show-OverrideNote } elseif ($onOff -eq 'off') { Set-ScreenReader $false; Say 'Screen reader mode is off.' } else { Show-Usage; Stop-Manager 'say on or off after screen-reader.' } } { $_ -eq 'help' -or $_ -eq '-h' -or $_ -eq '--help' } { Show-Usage } default { Show-Usage; Stop-Manager "unknown action: $action" } } } try { Main -Arguments ([string[]]@($args)) $global:LASTEXITCODE = 0 } catch { Say '' if ($_.Exception -is [System.InvalidOperationException]) { Say "Stopped: $($_.Exception.Message)" } else { Say "Stopped by an error: $($_.Exception.Message)" } $global:LASTEXITCODE = 1 } } @args