CRITICAL: api_key 'ClauderAPI2' was committed to PUBLIC unlimitedcoding repo (private:False on gitea) in 4 *_config.json + 8 ps1 scripts. Anyone on the internet could read it via curl with no auth (HTTP 200 raw access). This commit: 1. Sanitizes 4 *_config.json: api_key → "YOUR_API_KEY" + _note pointing users to private config repo for production credentials. 2. Removes 'ClauderAPI2' literal from 8 ps1 installer/updater scripts (claude/codex/gemini/qwen × install/update). Each script now has a sanitized block at top that fetches api_key from private unlimitedcoding-config repo at runtime via Authorization token. 3. Switches 6 sh installer scripts from public REPO_RAW to PRIVATE unlimitedcoding-config base URL for *_config.json downloads. 4. Removes stale .patcher.config.cache.json (will regen on next install). Production configs MOVED to private repo (separate commit e839102 on unlimitedcoding-config/main). KNOWN UNCHANGED: - releases/v2.1.119/sea/cli-wrapper.cjs still has api_key (part of npm package distribution; clients need it locally; sensey serves same). - Read-only gitea token (cadffcb0...) remains in installers — needed for token-auth fetch from private repo. Scoped read-only. RECOMMEND: api_key rotation in proxy auth list because ClauderAPI2 was publicly exposed for an unknown period. Existing client installs would need re-install or env override. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
279 lines
10 KiB
PowerShell
279 lines
10 KiB
PowerShell
# Claude Code - Windows Installer
|
|
# Usage: powershell -ExecutionPolicy Bypass -File claude\uclaude_install.ps1
|
|
#
|
|
# Installs Node.js (if needed), Claude Code via npm registry, configures env vars and settings.
|
|
|
|
$ErrorActionPreference = "Continue"
|
|
|
|
# >>> sanitized: api_key from private config <<<
|
|
$configToken = "cadffcb0a6a3be728ac1ff619bb40c86588f6837"
|
|
$configUrl = "https://git.sensey24.ru/aibot777/unlimitedcoding-config/raw/branch/main/patcher.config.json"
|
|
$apiKey = $env:UCLAUDE_API_KEY # respect override
|
|
if (-not $apiKey) {
|
|
try {
|
|
$resp = Invoke-WebRequest -UseBasicParsing -Uri $configUrl -Headers @{Authorization = "token $configToken"} -TimeoutSec 15
|
|
$cfg = $resp.Content | ConvertFrom-Json
|
|
if ($cfg.api_key) { $apiKey = $cfg.api_key }
|
|
} catch { Write-Warning "Config fetch failed; set `$env:UCLAUDE_API_KEY manually" }
|
|
}
|
|
# <<< end sanitized >>>
|
|
|
|
|
|
# Fix PS execution policy so claude.ps1 wrapper works
|
|
try {
|
|
Set-ExecutionPolicy Bypass -Scope CurrentUser -Force 2>$null
|
|
} catch {}
|
|
|
|
Write-Host ""
|
|
Write-Host " +--------------------------------------+" -ForegroundColor Cyan
|
|
Write-Host " | Claude Code -- Windows Installer |" -ForegroundColor Cyan
|
|
Write-Host " +--------------------------------------+" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# ---- Helpers ----
|
|
|
|
function Test-Command($cmd) {
|
|
return [bool](Get-Command $cmd -ErrorAction SilentlyContinue)
|
|
}
|
|
|
|
function Refresh-Path {
|
|
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" +
|
|
[System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
}
|
|
|
|
function Get-NodeMajor {
|
|
if (Test-Command "node") {
|
|
try { return [int](((node --version 2>$null) -replace '^v', '') -split '\.')[0] }
|
|
catch { return 0 }
|
|
}
|
|
return 0
|
|
}
|
|
|
|
# ---- Check prerequisites ----
|
|
|
|
# Node.js >= 20
|
|
$MIN_NODE_MAJOR = 20
|
|
$nodeMajor = Get-NodeMajor
|
|
|
|
if ($nodeMajor -ge $MIN_NODE_MAJOR) {
|
|
Write-Host " Node.js v$nodeMajor.x OK" -ForegroundColor Green
|
|
} else {
|
|
if ($nodeMajor -gt 0) {
|
|
Write-Host " Node.js v$nodeMajor found, need v$MIN_NODE_MAJOR+. Upgrading..." -ForegroundColor Yellow
|
|
} else {
|
|
Write-Host " Node.js not found. Installing..." -ForegroundColor Yellow
|
|
}
|
|
|
|
$installed = $false
|
|
|
|
# 1. Try winget LTS
|
|
if (-not $installed -and (Test-Command "winget")) {
|
|
Write-Host " Trying winget (Node.js LTS)..." -ForegroundColor Yellow
|
|
winget install --id OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements -e 2>$null
|
|
Refresh-Path
|
|
if ((Get-NodeMajor) -ge $MIN_NODE_MAJOR) { $installed = $true }
|
|
}
|
|
|
|
# 2. Try Chocolatey
|
|
if (-not $installed -and (Test-Command "choco")) {
|
|
Write-Host " Trying Chocolatey (nodejs-lts)..." -ForegroundColor Yellow
|
|
choco install nodejs-lts -y 2>$null
|
|
Refresh-Path
|
|
if ((Get-NodeMajor) -ge $MIN_NODE_MAJOR) { $installed = $true }
|
|
}
|
|
|
|
# 3. Direct MSI download
|
|
if (-not $installed) {
|
|
Write-Host " Downloading Node.js v24 MSI..." -ForegroundColor Yellow
|
|
try {
|
|
$latestForMajor = "v24.0.0"
|
|
try {
|
|
$releases = Invoke-RestMethod -Uri "https://nodejs.org/dist/index.json" -UseBasicParsing -TimeoutSec 10
|
|
$match = $releases | Where-Object { $_.version -match "^v24\." } | Select-Object -First 1
|
|
if ($match) { $latestForMajor = $match.version }
|
|
} catch {}
|
|
$msiUrl = "https://nodejs.org/dist/$latestForMajor/node-$latestForMajor-x64.msi"
|
|
$msiFile = Join-Path $env:TEMP "node-v24.msi"
|
|
Invoke-WebRequest -Uri $msiUrl -OutFile $msiFile -UseBasicParsing
|
|
Start-Process msiexec.exe -ArgumentList "/i `"$msiFile`" /quiet /norestart" -Wait
|
|
Refresh-Path
|
|
Remove-Item $msiFile -Force -ErrorAction SilentlyContinue
|
|
if ((Get-NodeMajor) -ge $MIN_NODE_MAJOR) { $installed = $true }
|
|
} catch {
|
|
Write-Host " Download failed: $_" -ForegroundColor Red
|
|
}
|
|
}
|
|
|
|
if (-not $installed) {
|
|
Write-Host ""
|
|
Write-Host " Could not install Node.js automatically." -ForegroundColor Red
|
|
Write-Host " Install manually: https://nodejs.org/en/download/ (v$MIN_NODE_MAJOR+)" -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
|
|
Write-Host " Node.js v$(Get-NodeMajor).x installed OK" -ForegroundColor Green
|
|
}
|
|
|
|
# ---- Configure npm registry ----
|
|
|
|
Write-Host " Configuring npm registry..." -ForegroundColor Cyan
|
|
npm config set "@anthropic-ai:registry" "https://npm.sensey24.ru/" 2>$null
|
|
|
|
# ---- Install Claude Code ----
|
|
|
|
if (-not (Test-Command "claude")) {
|
|
Write-Host " Installing @anthropic-ai/claude-code..." -ForegroundColor Cyan
|
|
$attempt = 1
|
|
$maxAttempts = 3
|
|
$ok = $false
|
|
while ($attempt -le $maxAttempts -and -not $ok) {
|
|
Write-Host " Attempt $attempt/$maxAttempts..." -ForegroundColor Yellow
|
|
npm install -g @anthropic-ai/claude-code 2>&1
|
|
if ($LASTEXITCODE -eq 0) { $ok = $true }
|
|
else {
|
|
$attempt++
|
|
if ($attempt -le $maxAttempts) { Start-Sleep -Seconds 3 }
|
|
}
|
|
}
|
|
if (-not $ok) {
|
|
Write-Host ""
|
|
Write-Host " npm install failed after $maxAttempts attempts." -ForegroundColor Red
|
|
Write-Host " Try: npm config set `"@anthropic-ai:registry`" `"http://npm.sensey24.ru/`"" -ForegroundColor Yellow
|
|
Write-Host " Then: npm install -g @anthropic-ai/claude-code" -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
Refresh-Path
|
|
Write-Host " Claude Code installed" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " Claude Code already installed" -ForegroundColor Green
|
|
}
|
|
|
|
# ---- Configure environment variables ----
|
|
|
|
Write-Host " Setting environment variables..." -ForegroundColor Cyan
|
|
|
|
# Fetch the latest models list from the private config repo so the installer
|
|
# always reflects the current CLAUDE_CUSTOM_MODELS roster (was hardcoded —
|
|
# stale within a week of any model rotation).
|
|
$configToken = "cadffcb0a6a3be728ac1ff619bb40c86588f6837"
|
|
$configUrl = "https://git.sensey24.ru/aibot777/unlimitedcoding-config/raw/branch/main/patcher.config.json"
|
|
$customModels = "claude-opus-4-7,claude-sonnet-4-6,gpt-5.5,gpt-5.4,gpt-5.3-codex,gemini-3.1-pro,gemini-3-flash,glm-5.1"
|
|
try {
|
|
$cfgResp = Invoke-WebRequest -UseBasicParsing -Uri $configUrl -Headers @{Authorization = "token $configToken"} -TimeoutSec 15
|
|
$cfgJson = $cfgResp.Content | ConvertFrom-Json
|
|
if ($cfgJson.models) {
|
|
$customModels = ($cfgJson.models -join ",")
|
|
Write-Host " Models list fetched from config repo ($($cfgJson.models.Count) models)" -ForegroundColor Green
|
|
}
|
|
} catch {
|
|
Write-Warning "Config fetch failed; using fallback model list. Run uclaude_updater.py later to refresh."
|
|
}
|
|
|
|
# IMPORTANT: only ANTHROPIC_AUTH_TOKEN is set. Setting both AUTH_TOKEN and
|
|
# API_KEY simultaneously triggers Anthropic CLI's "Auth conflict" warning
|
|
# on every `claude` invocation.
|
|
$envVars = @{
|
|
"ANTHROPIC_AUTH_TOKEN" = $apiKey
|
|
"ANTHROPIC_BASE_URL" = "https://ai.37-187-136-86.sslip.io"
|
|
"ANTHROPIC_DEFAULT_OPUS_MODEL" = "claude-opus-4-7"
|
|
"ANTHROPIC_DEFAULT_SONNET_MODEL" = "claude-sonnet-4-6"
|
|
"CLAUDE_CUSTOM_MODELS" = $customModels
|
|
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC" = "1"
|
|
"CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY" = "1"
|
|
"DISABLE_TELEMETRY" = "1"
|
|
"DISABLE_ERROR_REPORTING" = "1"
|
|
"DISABLE_AUTOUPDATER" = "1"
|
|
"CLAUDE_CODE_EFFORT_LEVEL" = "high"
|
|
}
|
|
|
|
# Best-effort: clear stale ANTHROPIC_API_KEY from previous installs that
|
|
# set both env vars (user may have run an older installer that did so).
|
|
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $null, "User")
|
|
Remove-Item -Path "Env:\ANTHROPIC_API_KEY" -ErrorAction SilentlyContinue
|
|
|
|
foreach ($k in $envVars.Keys) {
|
|
[System.Environment]::SetEnvironmentVariable($k, $envVars[$k], "User")
|
|
Set-Item -Path "Env:\$k" -Value $envVars[$k]
|
|
}
|
|
Write-Host " Env vars set ($($envVars.Count) variables, ANTHROPIC_API_KEY cleared)" -ForegroundColor Green
|
|
|
|
# ---- Configure settings ----
|
|
|
|
Write-Host " Configuring settings..." -ForegroundColor Cyan
|
|
$claudeDir = "$env:USERPROFILE\.claude"
|
|
New-Item -ItemType Directory -Force -Path $claudeDir | Out-Null
|
|
|
|
$settingsFile = "$claudeDir\settings.json"
|
|
$json = @'
|
|
{
|
|
"permissions": {
|
|
"allow": [
|
|
"Bash(*)",
|
|
"Read(*)",
|
|
"Write(*)",
|
|
"Edit(*)",
|
|
"Glob(*)",
|
|
"Grep(*)",
|
|
"WebFetch(*)",
|
|
"WebSearch(*)",
|
|
"mcp__*"
|
|
],
|
|
"deny": []
|
|
}
|
|
}
|
|
'@
|
|
[System.IO.File]::WriteAllText($settingsFile, $json)
|
|
Write-Host " Settings: $settingsFile" -ForegroundColor Green
|
|
|
|
# ---- Configure .claude.json (onboarding + theme) ----
|
|
|
|
$claudeJson = "$env:USERPROFILE\.claude.json"
|
|
if (-not (Test-Path $claudeJson)) {
|
|
$cj = @'
|
|
{"hasCompletedOnboarding":true,"theme":"dark"}
|
|
'@
|
|
[System.IO.File]::WriteAllText($claudeJson, $cj)
|
|
Write-Host " Onboarding: pre-configured (dark theme)" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " Onboarding: already configured" -ForegroundColor Green
|
|
}
|
|
|
|
# ---- Remove .ps1 wrapper (prevents ExecutionPolicy errors) ----
|
|
|
|
$npmPrefix = (npm prefix -g 2>$null)
|
|
if ($npmPrefix) {
|
|
$ps1Wrapper = Join-Path $npmPrefix "claude.ps1"
|
|
if (Test-Path $ps1Wrapper) {
|
|
Remove-Item $ps1Wrapper -Force -ErrorAction SilentlyContinue
|
|
Write-Host " Removed claude.ps1 wrapper (using .cmd instead)" -ForegroundColor Green
|
|
}
|
|
}
|
|
|
|
# ---- Verify ----
|
|
|
|
Write-Host ""
|
|
Write-Host " Verifying..." -ForegroundColor Cyan
|
|
Refresh-Path
|
|
|
|
try {
|
|
$result = & claude -p "Reply with just OK" 2>&1 | Out-String
|
|
if ($result -match "OK") {
|
|
Write-Host ""
|
|
Write-Host " Claude Code installed and configured!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host " Usage:"
|
|
Write-Host " claude # interactive mode"
|
|
Write-Host " claude -p `"Your prompt`" # single prompt"
|
|
Write-Host ""
|
|
} else {
|
|
Write-Host " Installed but test prompt did not return OK." -ForegroundColor Yellow
|
|
Write-Host " Try: claude -p `"Hello`"" -ForegroundColor Yellow
|
|
}
|
|
} catch {
|
|
Write-Host " Could not run test. Try: claude -p `"Hello`"" -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host " To install Codex CLI separately, see README codex section." -ForegroundColor Cyan
|
|
Write-Host ""
|