Files
unlimitedcoding/codex/ucodex_uninstall.ps1
delta-cloud-208e 134606839a fix(uninstall): wildcard env cleanup + AUTH_TOKEN + npm + claude README (Item 18)
User asked: do per-tool READMEs document uninstall? Sub-agent audit
(gpt-5.5 sh + glm-5.1 ps1) found multiple BLOCKERs in uninstall scripts.

Fixes:

1. claude/README.md — added Uninstall section (was missing — other tools'
   READMEs already documented theirs).

2. All 4 ps1 uninstallers (claude/codex/gemini/qwen) — wildcard env-var
   cleanup by prefix. Was: hardcoded list missed *_AUTH_TOKEN, leaving
   stale token after uninstall → Auth conflict warning on reinstall
   (root cause user reported on Windows).
   Prefixes:
     claude → ANTHROPIC_*, CLAUDE_*, DISABLE_TELEMETRY, ...
     codex  → OPENAI_*
     gemini → GEMINI_*, GOOGLE_API_KEY, GOOGLE_CLOUD_PROJECT
     qwen   → QWEN_*, DASHSCOPE_*

3. codex/ucodex_uninstall.ps1 — added `npm uninstall -g @openai/codex`
   step (was missing — npm package would survive uninstall).

4. codex/ucodex_uninstall.ps1 — also clears npm registry override
   `@openai:registry`.

Audit also flagged (NOT applied — defer to next iteration):
- sh: overly broad `sed '/PATTERN/d'` deletes unrelated user lines
  (could damage user's .bashrc — use marker comments instead)
- sh: missing /var/root scan (macOS root user)
- sh: missing systemd/LaunchAgent cleanup
- sh: backup restore not implemented
- All: should preserve some user data (history, projects) — current
  behavior is destructive

Tests: tests/test_uninstall_completeness.py — 10 GREEN regression guards
(prefix wildcard works, README has section, sh uses portable sed,
codex npm uninstall present).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-25 18:03:41 +00:00

85 lines
3.3 KiB
PowerShell

# Codex CLI - Windows Uninstaller
# Usage: powershell -ExecutionPolicy Bypass -File codex\ucodex_uninstall.ps1
$ErrorActionPreference = "Continue"
Write-Host ""
Write-Host " +--------------------------------------+" -ForegroundColor Cyan
Write-Host " | Codex CLI -- Windows Uninstaller |" -ForegroundColor Cyan
Write-Host " +--------------------------------------+" -ForegroundColor Cyan
Write-Host ""
# ---- Optionally remove npm package (if codex was installed via @openai/codex) ----
if (Get-Command npm -ErrorAction SilentlyContinue) {
Write-Host " Removing @openai/codex npm package (if present)..." -ForegroundColor Cyan
npm uninstall -g @openai/codex 2>$null | Out-Null
npm config delete "@openai:registry" 2>$null | Out-Null
Write-Host " npm cleanup done (no-op if not installed via npm)" -ForegroundColor Green
}
# ---- Remove binary ----
$installDir = "$env:LOCALAPPDATA\Programs\codex"
if (Test-Path "$installDir\codex.exe") {
Write-Host " Stopping codex processes..." -ForegroundColor Cyan
Get-Process -Name "codex" -ErrorAction SilentlyContinue | Stop-Process -Force
Write-Host " Removing $installDir..." -ForegroundColor Cyan
Remove-Item -Recurse -Force $installDir
Write-Host " Binary removed" -ForegroundColor Green
# Remove from PATH
$userPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -like "*$installDir*") {
$newPath = ($userPath -split ";" | Where-Object { $_ -ne $installDir }) -join ";"
# >>> wildcard env cleanup (Item 18 audit) <<<
$prefixesToRemove = @("OPENAI_")
$userVars = [System.Environment]::GetEnvironmentVariables("User")
foreach ($name in @($userVars.Keys)) {
foreach ($p in $prefixesToRemove) {
if ($name -like "${p}*" -or $name -eq $p) {
[System.Environment]::SetEnvironmentVariable($name, $null, "User")
Remove-Item -Path "Env:\$name" -ErrorAction SilentlyContinue
Write-Host " Removed env: $name" -ForegroundColor Cyan
break
}
}
}
# <<< end wildcard cleanup >>>
[System.Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Host " Removed from PATH" -ForegroundColor Green
}
} else {
Write-Host " Codex binary not found at $installDir" -ForegroundColor Yellow
# Check other common locations
$altPath = (Get-Command codex -ErrorAction SilentlyContinue).Source
if ($altPath) {
Write-Host " Found at: $altPath - remove manually" -ForegroundColor Yellow
}
}
# ---- Remove config ----
$codexDir = "$env:USERPROFILE\.codex"
if (Test-Path $codexDir) {
Write-Host " Removing $codexDir..." -ForegroundColor Cyan
Remove-Item -Recurse -Force $codexDir
Write-Host " Config removed" -ForegroundColor Green
} else {
Write-Host " No config directory found" -ForegroundColor Yellow
}
# ---- Remove env vars ----
Write-Host " Removing environment variables..." -ForegroundColor Cyan
[System.Environment]::SetEnvironmentVariable("OPENAI_API_KEY", $null, "User")
[System.Environment]::SetEnvironmentVariable("OPENAI_BASE_URL", $null, "User")
Remove-Item Env:OPENAI_API_KEY -ErrorAction SilentlyContinue
Remove-Item Env:OPENAI_BASE_URL -ErrorAction SilentlyContinue
Write-Host " Env vars removed" -ForegroundColor Green
Write-Host ""
Write-Host " Codex CLI fully uninstalled!" -ForegroundColor Green
Write-Host ""