diff --git a/README-Windows.md b/README-Windows.md new file mode 100644 index 0000000..1e23a54 --- /dev/null +++ b/README-Windows.md @@ -0,0 +1,303 @@ +# Claude Code Installer for Windows + +A colorized, interactive PowerShell installer script that automates the installation of [Claude Code](https://docs.anthropic.com/en/docs/claude-code) on Windows systems. + +![License](https://img.shields.io/badge/license-MIT-blue.svg) +![Platform](https://img.shields.io/badge/platform-Windows-0078D6.svg) +![Node](https://img.shields.io/badge/node-%3E%3D18.0.0-green.svg) +![PowerShell](https://img.shields.io/badge/PowerShell-%3E%3D5.1-blue.svg) + +--- + +## Quick Install + +**One-line installation (Run in PowerShell as Administrator):** + +```powershell +irm https://git.bitmaster.cc/BitMaster/claude/raw/branch/main/claude-code-installer.ps1 | iex +``` + +**Or with full command:** + +```powershell +Invoke-RestMethod https://git.bitmaster.cc/BitMaster/claude/raw/branch/main/claude-code-installer.ps1 | Invoke-Expression +``` + +> ⚠️ **Note:** You may need to run PowerShell as Administrator for the installation to complete successfully. + +--- + +## Manual Installation + +**Step 1:** Download the installer script + +```powershell +Invoke-WebRequest -Uri "https://git.bitmaster.cc/BitMaster/claude/raw/branch/main/claude-code-installer.ps1" -OutFile "claude-code-installer.ps1" +``` + +**Step 2:** Allow script execution (if needed) + +```powershell +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser +``` + +**Step 3:** Run the installer + +```powershell +.\claude-code-installer.ps1 +``` + +--- + +## Features + +### 🔍 System Detection + +| Feature | Description | +|---------|-------------| +| **Windows Detection** | Identifies Windows version and build number | +| **Architecture** | Detects x64, x86, or ARM64 for correct Node.js download | +| **System Info** | Shows computer name, RAM, and PowerShell version | +| **Admin Check** | Verifies if running with Administrator privileges | + +### 📦 Node.js Management + +| Feature | Description | +|---------|-------------| +| **Version Check** | Checks if Node.js/npm are installed and their versions | +| **Compatibility** | Detects if the version is compatible (v18+ required) | +| **Clean Removal** | Uninstalls existing Node.js via Windows installer | +| **Fresh Install** | Downloads and installs Node.js 20 LTS from nodejs.org | +| **Verification** | Verifies installation after completion | + +### 🛡️ Permission Modes + +When the installation completes, you'll be prompted to choose how Claude Code runs: + +| Mode | Flag | Description | +|------|------|-------------| +| **1. Normal Mode** | *(default)* | Asks before each operation — **safest option** | +| **2. Auto-Accept Edits** | `--auto-accept-edits` | Auto-accepts file changes, confirms commands | +| **3. Full Auto Mode** | `--dangerously-skip-permissions` | Skips all prompts — **use with caution!** | +| **4. Exit** | — | Don't start Claude, just complete installation | + +--- + +## System Requirements + +| Requirement | Minimum | +|-------------|---------| +| **Operating System** | Windows 10 / Windows 11 / Windows Server 2016+ | +| **PowerShell** | Version 5.1 or later | +| **Architecture** | x64, x86, or ARM64 | +| **Permissions** | Administrator recommended | +| **Internet** | Required for downloading packages | + +--- + +## What Gets Installed + +1. **Node.js 20 LTS** — JavaScript runtime (if not already installed or outdated) +2. **npm** — Node package manager (comes with Node.js) +3. **Claude Code** — Anthropic's CLI tool for AI-assisted coding + +### Installation Paths + +| Component | Default Location | +|-----------|------------------| +| Node.js | `C:\Program Files\nodejs\` | +| npm global packages | `%APPDATA%\npm\` | +| npm cache | `%APPDATA%\npm-cache\` | +| Claude Code | `%APPDATA%\npm\claude.cmd` | + +--- + +## Post-Installation + +After installation, you can start Claude Code anytime: + +**Command Prompt or PowerShell:** + +```cmd +# Normal mode (recommended) +claude + +# Auto-accept file edits +claude --auto-accept-edits + +# Full auto mode (dangerous) +claude --dangerously-skip-permissions +``` + +If the `claude` command is not recognized, restart your terminal or open a new PowerShell/Command Prompt window. + +--- + +## Troubleshooting + +### "claude" is not recognized + +**Solution 1:** Restart your terminal (PowerShell/Command Prompt) + +**Solution 2:** Refresh environment variables + +```powershell +$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") +``` + +**Solution 3:** Manually add npm to PATH + +```powershell +$env:Path += ";$env:APPDATA\npm" +``` + +### Execution Policy Error + +If you see "cannot be loaded because running scripts is disabled": + +```powershell +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser +``` + +### Permission Denied / Access Denied + +Run PowerShell as Administrator: + +1. Right-click on PowerShell +2. Select "Run as administrator" +3. Run the installer again + +### Node.js Installation Fails + +**Option 1:** Download and install manually from [nodejs.org](https://nodejs.org/) + +**Option 2:** Use winget (Windows Package Manager): + +```powershell +winget install OpenJS.NodeJS.LTS +``` + +**Option 3:** Use Chocolatey: + +```powershell +choco install nodejs-lts +``` + +### npm Install Fails + +Clear npm cache and retry: + +```powershell +npm cache clean --force +npm install -g @anthropic-ai/claude-code +``` + +--- + +## Uninstallation + +### Remove Claude Code + +```powershell +npm uninstall -g @anthropic-ai/claude-code +``` + +### Remove Node.js + +**Option 1:** Via Windows Settings +1. Open Settings → Apps → Installed apps +2. Search for "Node.js" +3. Click Uninstall + +**Option 2:** Via Control Panel +1. Open Control Panel → Programs → Uninstall a program +2. Find "Node.js" +3. Click Uninstall + +**Option 3:** Via PowerShell + +```powershell +# Find and uninstall Node.js +Get-Package -Name "*Node*" | Uninstall-Package +``` + +### Clean Up Remaining Files + +```powershell +# Remove npm cache and global packages +Remove-Item -Recurse -Force "$env:APPDATA\npm" -ErrorAction SilentlyContinue +Remove-Item -Recurse -Force "$env:APPDATA\npm-cache" -ErrorAction SilentlyContinue +``` + +--- + +## Alternative Installation Methods + +### Using winget (Windows Package Manager) + +```powershell +# Install Node.js +winget install OpenJS.NodeJS.LTS + +# Install Claude Code +npm install -g @anthropic-ai/claude-code +``` + +### Using Chocolatey + +```powershell +# Install Chocolatey (if not installed) +Set-ExecutionPolicy Bypass -Scope Process -Force +[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 +iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + +# Install Node.js +choco install nodejs-lts + +# Install Claude Code +npm install -g @anthropic-ai/claude-code +``` + +### Using Scoop + +```powershell +# Install Scoop (if not installed) +irm get.scoop.sh | iex + +# Install Node.js +scoop install nodejs-lts + +# Install Claude Code +npm install -g @anthropic-ai/claude-code +``` + +--- + +## License + +This installer script is provided under the MIT License. + +Claude Code is a product of [Anthropic](https://www.anthropic.com/). + +--- + +## Links + +- [Claude Code Documentation](https://docs.anthropic.com/en/docs/claude-code) +- [Anthropic](https://www.anthropic.com/) +- [Node.js](https://nodejs.org/) +- [Node.js Downloads](https://nodejs.org/en/download/) + +--- + +## Contributing + +Issues and pull requests are welcome at: + +**https://git.bitmaster.cc/BitMaster/claude** + +--- + +

+ Made with ❤️ for the Claude community +

diff --git a/claude-code-installer.ps1 b/claude-code-installer.ps1 new file mode 100644 index 0000000..d155083 --- /dev/null +++ b/claude-code-installer.ps1 @@ -0,0 +1,915 @@ +#Requires -Version 5.1 +<# +.SYNOPSIS + Claude Code Installer for Windows + A colorized, interactive installer with full system detection + +.DESCRIPTION + This script automates the installation of Claude Code on Windows systems. + + Features: + - Detects Windows version and architecture + - Checks/removes existing Node.js and npm installations + - Installs Node.js 20 LTS + - Installs Claude Code + - Configures permissions interactively + +.NOTES + Author: BitMaster + Repository: https://git.bitmaster.cc/BitMaster/claude + License: MIT + +.EXAMPLE + .\claude-code-installer.ps1 + +.EXAMPLE + # Run directly from web + irm https://git.bitmaster.cc/BitMaster/claude/raw/branch/main/claude-code-installer.ps1 | iex +#> + +# Ensure we're running with proper execution +$ErrorActionPreference = "Stop" +$ProgressPreference = "SilentlyContinue" + +#------------------------------------------------------------------------------- +# Color and Display Functions +#------------------------------------------------------------------------------- + +function Write-ColorText { + param( + [string]$Text, + [ConsoleColor]$Color = "White", + [switch]$NoNewline + ) + if ($NoNewline) { + Write-Host $Text -ForegroundColor $Color -NoNewline + } else { + Write-Host $Text -ForegroundColor $Color + } +} + +function Write-Banner { + Clear-Host + Write-Host "" + Write-ColorText "╔═══════════════════════════════════════════════════════════════════════════╗" -Color Cyan + Write-ColorText "║ ║" -Color Cyan + Write-ColorText "║ ██████╗██╗ █████╗ ██╗ ██╗██████╗ ███████╗ ║" -Color Cyan + Write-ColorText "║ ██╔════╝██║ ██╔══██╗██║ ██║██╔══██╗██╔════╝ ║" -Color Cyan + Write-ColorText "║ ██║ ██║ ███████║██║ ██║██║ ██║█████╗ ║" -Color Cyan + Write-ColorText "║ ██║ ██║ ██╔══██║██║ ██║██║ ██║██╔══╝ ║" -Color Cyan + Write-ColorText "║ ╚██████╗███████╗██║ ██║╚██████╔╝██████╔╝███████╗ ║" -Color Cyan + Write-ColorText "║ ╚═════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ║" -Color Cyan + Write-ColorText "║ ║" -Color Cyan + Write-ColorText "║ " -Color Cyan -NoNewline + Write-ColorText "C O D E I N S T A L L E R" -Color White -NoNewline + Write-ColorText " ║" -Color Cyan + Write-ColorText "║ ║" -Color Cyan + Write-ColorText "║ " -Color Cyan -NoNewline + Write-ColorText "[ Windows Edition ]" -Color Yellow -NoNewline + Write-ColorText " ║" -Color Cyan + Write-ColorText "║ ║" -Color Cyan + Write-ColorText "╚═══════════════════════════════════════════════════════════════════════════╝" -Color Cyan + Write-Host "" +} + +function Write-Section { + param([string]$Title) + Write-Host "" + Write-ColorText "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -Color Blue + Write-ColorText " $Title" -Color White + Write-ColorText "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -Color Blue + Write-Host "" +} + +function Write-Step { + param([string]$Message) + Write-ColorText "→ " -Color Cyan -NoNewline + Write-ColorText $Message -Color White +} + +function Write-Success { + param([string]$Message) + Write-ColorText "✓ " -Color Green -NoNewline + Write-ColorText $Message -Color Green +} + +function Write-Error2 { + param([string]$Message) + Write-ColorText "✗ " -Color Red -NoNewline + Write-ColorText $Message -Color Red +} + +function Write-Warning2 { + param([string]$Message) + Write-ColorText "⚠ " -Color Yellow -NoNewline + Write-ColorText $Message -Color Yellow +} + +function Write-Info { + param([string]$Message) + Write-ColorText "ℹ " -Color Blue -NoNewline + Write-ColorText $Message -Color DarkGray +} + +function Confirm-Action { + param( + [string]$Prompt, + [bool]$DefaultYes = $true + ) + + if ($DefaultYes) { + $options = "[Y/n]" + } else { + $options = "[y/N]" + } + + Write-ColorText "? " -Color Yellow -NoNewline + Write-ColorText "$Prompt " -Color White -NoNewline + Write-ColorText $options -Color DarkGray -NoNewline + Write-ColorText ": " -Color White -NoNewline + + $response = Read-Host + + if ([string]::IsNullOrWhiteSpace($response)) { + return $DefaultYes + } + + return $response -match "^[Yy]" +} + +function Wait-ForKey { + Write-Host "" + Write-ColorText "Press any key to continue..." -Color DarkGray + $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") + Write-Host "" +} + +#------------------------------------------------------------------------------- +# System Detection Functions +#------------------------------------------------------------------------------- + +function Get-SystemInfo { + Write-Section "⚙ System Detection" + + Write-Step "Identifying your Windows system..." + Start-Sleep -Milliseconds 500 + + # Get Windows version info + $os = Get-CimInstance -ClassName Win32_OperatingSystem + $cs = Get-CimInstance -ClassName Win32_ComputerSystem + + $script:WindowsVersion = $os.Caption + $script:WindowsBuild = $os.BuildNumber + $script:WindowsArch = $cs.SystemType + $script:ComputerName = $cs.Name + $script:TotalRAM = [math]::Round($cs.TotalPhysicalMemory / 1GB, 2) + + # Determine architecture for Node.js download + if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64" -or $env:PROCESSOR_ARCHITEW6432 -eq "AMD64") { + $script:Arch = "x64" + $script:ArchDisplay = "64-bit (x64)" + } elseif ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { + $script:Arch = "arm64" + $script:ArchDisplay = "ARM64" + } else { + $script:Arch = "x86" + $script:ArchDisplay = "32-bit (x86)" + } + + # Check if running as Administrator + $script:IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) + + # Check PowerShell version + $script:PSVersion = $PSVersionTable.PSVersion.ToString() + + # Display detected information + Write-Host "" + Write-ColorText " ┌─────────────────────────────────────────────────────────┐" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "System Information" -Color White -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " ├─────────────────────────────────────────────────────────┤" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Windows: " -Color Cyan -NoNewline + Write-ColorText "$WindowsVersion" -Color Green + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Build: " -Color Cyan -NoNewline + Write-ColorText "$WindowsBuild" -Color Green + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Architecture: " -Color Cyan -NoNewline + Write-ColorText "$ArchDisplay" -Color Green + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Computer: " -Color Cyan -NoNewline + Write-ColorText "$ComputerName" -Color Green + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "RAM: " -Color Cyan -NoNewline + Write-ColorText "$TotalRAM GB" -Color Green + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "PowerShell: " -Color Cyan -NoNewline + Write-ColorText "v$PSVersion" -Color Green + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Admin Rights: " -Color Cyan -NoNewline + if ($IsAdmin) { + Write-ColorText "Yes" -Color Green + } else { + Write-ColorText "No" -Color Yellow + } + Write-ColorText " └─────────────────────────────────────────────────────────┘" -Color White + Write-Host "" + + Write-Success "System detected successfully!" + Start-Sleep -Seconds 1 +} + +#------------------------------------------------------------------------------- +# Node.js Detection and Installation +#------------------------------------------------------------------------------- + +function Test-NodeInstallation { + Write-Section "📦 Node.js & npm Detection" + + Write-Step "Checking for existing Node.js installation..." + Start-Sleep -Milliseconds 500 + + $script:NodeInstalled = $false + $script:NpmInstalled = $false + $script:NodeVersion = "" + $script:NpmVersion = "" + $script:NeedsUpgrade = $false + + # Check Node.js + try { + $nodeOutput = & node --version 2>$null + if ($nodeOutput) { + $script:NodeInstalled = $true + $script:NodeVersion = $nodeOutput + } + } catch { + $script:NodeInstalled = $false + } + + # Check npm + try { + $npmOutput = & npm --version 2>$null + if ($npmOutput) { + $script:NpmInstalled = $true + $script:NpmVersion = $npmOutput + } + } catch { + $script:NpmInstalled = $false + } + + # Display current status + Write-Host "" + Write-ColorText " ┌─────────────────────────────────────────────────────────┐" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Current Installation Status" -Color White -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " ├─────────────────────────────────────────────────────────┤" -Color White + + if ($NodeInstalled) { + # Check if version is sufficient (need v18+) + $versionNum = $NodeVersion -replace "v", "" + $majorVersion = [int]($versionNum.Split('.')[0]) + + if ($majorVersion -ge 18) { + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "✓" -Color Green -NoNewline + Write-ColorText " Node.js: " -Color White -NoNewline + Write-ColorText "$NodeVersion" -Color Green -NoNewline + Write-ColorText " (Compatible)" -Color Green + } else { + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "⚠" -Color Yellow -NoNewline + Write-ColorText " Node.js: " -Color White -NoNewline + Write-ColorText "$NodeVersion" -Color Yellow -NoNewline + Write-ColorText " (Needs upgrade to v18+)" -Color Yellow + $script:NeedsUpgrade = $true + } + } else { + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "✗" -Color Red -NoNewline + Write-ColorText " Node.js: " -Color White -NoNewline + Write-ColorText "Not installed" -Color Red + $script:NeedsUpgrade = $true + } + + if ($NpmInstalled) { + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "✓" -Color Green -NoNewline + Write-ColorText " npm: " -Color White -NoNewline + Write-ColorText "v$NpmVersion" -Color Green + } else { + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "✗" -Color Red -NoNewline + Write-ColorText " npm: " -Color White -NoNewline + Write-ColorText "Not installed" -Color Red + } + + Write-ColorText " └─────────────────────────────────────────────────────────┘" -Color White + Write-Host "" + + # Determine action needed + if ($NodeInstalled -and $NeedsUpgrade) { + Write-Warning2 "Your Node.js version is incompatible with Claude Code." + Write-Info "Claude Code requires Node.js version 18.0.0 or higher." + Write-Host "" + + if (Confirm-Action "Would you like to uninstall the existing version and install Node.js 20 LTS?") { + Uninstall-Node + Install-Node + } else { + Write-Error2 "Cannot proceed without Node.js 18+. Exiting." + exit 1 + } + } elseif (-not $NodeInstalled) { + Write-Info "Node.js is not installed on your system." + Write-Host "" + + if (Confirm-Action "Would you like to install Node.js 20 LTS?") { + Install-Node + } else { + Write-Error2 "Cannot proceed without Node.js. Exiting." + exit 1 + } + } else { + Write-Success "Node.js installation is compatible!" + Write-Host "" + + if (Confirm-Action "Would you like to reinstall Node.js anyway (fresh installation)?" -DefaultYes $false) { + Uninstall-Node + Install-Node + } + } +} + +function Uninstall-Node { + Write-Section "⚙ Removing Existing Node.js Installation" + + Write-Step "Searching for Node.js installations..." + Write-Host "" + + # Check for Node.js in common locations + $nodePaths = @( + "$env:ProgramFiles\nodejs", + "${env:ProgramFiles(x86)}\nodejs", + "$env:LOCALAPPDATA\Programs\nodejs" + ) + + # Try to uninstall via Windows installer + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Checking for installed Node.js package..." -Color White + + $uninstallKeys = @( + "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", + "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*", + "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" + ) + + $nodePackage = $null + foreach ($key in $uninstallKeys) { + $nodePackage = Get-ItemProperty $key -ErrorAction SilentlyContinue | + Where-Object { $_.DisplayName -like "*Node.js*" -or $_.DisplayName -like "*Node*" } | + Select-Object -First 1 + if ($nodePackage) { break } + } + + if ($nodePackage -and $nodePackage.UninstallString) { + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Found Node.js installation. Uninstalling..." -Color White + + try { + $uninstallCmd = $nodePackage.UninstallString + if ($uninstallCmd -match "msiexec") { + # MSI uninstall + $productCode = $uninstallCmd -replace ".*(\{[A-F0-9-]+\}).*", '$1' + if ($productCode -match "^\{") { + Start-Process "msiexec.exe" -ArgumentList "/x $productCode /qn" -Wait -NoNewWindow + } + } else { + Start-Process $uninstallCmd -ArgumentList "/S" -Wait -NoNewWindow -ErrorAction SilentlyContinue + } + Write-ColorText " done" -Color Green + } catch { + Write-ColorText " manual removal required" -Color Yellow + } + } + + # Remove Node.js directories + foreach ($path in $nodePaths) { + if (Test-Path $path) { + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Removing $path..." -Color White -NoNewline + try { + Remove-Item -Path $path -Recurse -Force -ErrorAction Stop + Write-ColorText " done" -Color Green + } catch { + Write-ColorText " failed (may need admin rights)" -Color Red + } + } + } + + # Remove npm cache and global packages + $npmPaths = @( + "$env:APPDATA\npm", + "$env:APPDATA\npm-cache", + "$env:LOCALAPPDATA\npm-cache" + ) + + foreach ($path in $npmPaths) { + if (Test-Path $path) { + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Removing $path..." -Color White -NoNewline + try { + Remove-Item -Path $path -Recurse -Force -ErrorAction Stop + Write-ColorText " done" -Color Green + } catch { + Write-ColorText " skipped" -Color Yellow + } + } + } + + # Remove from PATH (current session) + $env:Path = ($env:Path.Split(';') | Where-Object { $_ -notlike "*nodejs*" -and $_ -notlike "*npm*" }) -join ';' + + Write-Host "" + Write-Success "Node.js removal completed!" + Start-Sleep -Seconds 1 +} + +function Install-Node { + Write-Section "📦 Installing Node.js 20 LTS" + + Write-Step "Preparing to install Node.js 20 LTS..." + Write-Host "" + + # Determine download URL based on architecture + $nodeVersion = "20.19.0" # LTS version + + switch ($Arch) { + "x64" { $installerFile = "node-v$nodeVersion-x64.msi" } + "x86" { $installerFile = "node-v$nodeVersion-x86.msi" } + "arm64" { $installerFile = "node-v$nodeVersion-arm64.msi" } + default { $installerFile = "node-v$nodeVersion-x64.msi" } + } + + $downloadUrl = "https://nodejs.org/dist/v$nodeVersion/$installerFile" + $installerPath = "$env:TEMP\$installerFile" + + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Downloading Node.js v$nodeVersion ($Arch)..." -Color White + Write-Info " URL: $downloadUrl" + + try { + # Download with progress + $webClient = New-Object System.Net.WebClient + $webClient.DownloadFile($downloadUrl, $installerPath) + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Download complete!" -Color Green + } catch { + Write-Error2 "Failed to download Node.js installer." + Write-Info "Please check your internet connection and try again." + Write-Info "Or download manually from: https://nodejs.org/" + exit 1 + } + + # Install Node.js + Write-Host "" + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Installing Node.js (this may take a minute)..." -Color White + + try { + $installArgs = "/i `"$installerPath`" /qn /norestart" + $process = Start-Process "msiexec.exe" -ArgumentList $installArgs -Wait -PassThru -NoNewWindow + + if ($process.ExitCode -eq 0) { + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Installation successful!" -Color Green + } elseif ($process.ExitCode -eq 3010) { + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Installation successful (restart may be required)" -Color Yellow + } else { + throw "MSI installer returned code: $($process.ExitCode)" + } + } catch { + Write-Error2 "Installation failed: $_" + Write-Info "Try running the installer manually: $installerPath" + exit 1 + } + + # Refresh environment variables + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Refreshing environment variables..." -Color White + + # Add Node.js to PATH for current session + $nodePath = "$env:ProgramFiles\nodejs" + if (Test-Path $nodePath) { + $env:Path = "$nodePath;$env:APPDATA\npm;$env:Path" + } + + # Also try to refresh from registry + $machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine") + $userPath = [Environment]::GetEnvironmentVariable("Path", "User") + $env:Path = "$machinePath;$userPath" + + Write-ColorText " done" -Color Green + + # Cleanup + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Cleaning up installer..." -Color White -NoNewline + Remove-Item -Path $installerPath -Force -ErrorAction SilentlyContinue + Write-ColorText " done" -Color Green + + Write-Host "" + Write-Success "Node.js installation completed!" + Start-Sleep -Seconds 1 +} + +function Test-NodeVerification { + Write-Section "✓ Verifying Installation" + + Write-Step "Checking Node.js and npm versions..." + Write-Host "" + Start-Sleep -Milliseconds 500 + + # Refresh PATH + $nodePath = "$env:ProgramFiles\nodejs" + if (Test-Path $nodePath) { + $env:Path = "$nodePath;$env:APPDATA\npm;$env:Path" + } + + $nodeOk = $false + $npmOk = $false + + # Verify Node.js + try { + $newNodeVersion = & "$nodePath\node.exe" --version 2>$null + if (-not $newNodeVersion) { + $newNodeVersion = & node --version 2>$null + } + + if ($newNodeVersion) { + $versionNum = $newNodeVersion -replace "v", "" + $majorVersion = [int]($versionNum.Split('.')[0]) + + if ($majorVersion -ge 18) { + Write-ColorText " ✓ " -Color Green -NoNewline + Write-ColorText "Node.js: " -Color White -NoNewline + Write-ColorText "$newNodeVersion" -Color Green -NoNewline + Write-ColorText " (Compatible!)" -Color Green + $nodeOk = $true + } else { + Write-ColorText " ✗ " -Color Red -NoNewline + Write-ColorText "Node.js: " -Color White -NoNewline + Write-ColorText "$newNodeVersion (Too old - need v18+)" -Color Red + } + } else { + throw "No version output" + } + } catch { + Write-ColorText " ✗ " -Color Red -NoNewline + Write-ColorText "Node.js: " -Color White -NoNewline + Write-ColorText "Not found!" -Color Red + } + + # Verify npm + try { + $newNpmVersion = & "$nodePath\npm.cmd" --version 2>$null + if (-not $newNpmVersion) { + $newNpmVersion = & npm --version 2>$null + } + + if ($newNpmVersion) { + Write-ColorText " ✓ " -Color Green -NoNewline + Write-ColorText "npm: " -Color White -NoNewline + Write-ColorText "v$newNpmVersion" -Color Green + $npmOk = $true + } else { + throw "No version output" + } + } catch { + Write-ColorText " ✗ " -Color Red -NoNewline + Write-ColorText "npm: " -Color White -NoNewline + Write-ColorText "Not found!" -Color Red + } + + # Show paths + Write-Host "" + Write-Info "Node path: $nodePath\node.exe" + Write-Info "npm path: $nodePath\npm.cmd" + + Write-Host "" + + if ($nodeOk -and $npmOk) { + Write-Success "All requirements verified successfully!" + return $true + } else { + Write-Error2 "Verification failed! Please check the installation." + return $false + } +} + +#------------------------------------------------------------------------------- +# Claude Code Installation +#------------------------------------------------------------------------------- + +function Install-ClaudeCode { + Write-Section "🚀 Installing Claude Code" + + Write-Step "Installing Claude Code via npm..." + Write-Host "" + + # Ensure npm is in PATH + $nodePath = "$env:ProgramFiles\nodejs" + $npmPath = "$env:APPDATA\npm" + $env:Path = "$nodePath;$npmPath;$env:Path" + + Write-ColorText " → " -Color Yellow -NoNewline + Write-ColorText "Running npm install..." -Color White + Write-Host "" + + try { + # Install Claude Code globally + $npmCmd = if (Test-Path "$nodePath\npm.cmd") { "$nodePath\npm.cmd" } else { "npm" } + + $process = Start-Process -FilePath $npmCmd -ArgumentList "install", "-g", "@anthropic-ai/claude-code" -Wait -PassThru -NoNewWindow -RedirectStandardOutput "$env:TEMP\npm-out.txt" -RedirectStandardError "$env:TEMP\npm-err.txt" + + # Display output + if (Test-Path "$env:TEMP\npm-out.txt") { + $output = Get-Content "$env:TEMP\npm-out.txt" -Raw + if ($output) { + $output.Split("`n") | ForEach-Object { + if ($_ -match "added|packages") { + Write-ColorText " $_" -Color Green + } elseif ($_ -match "WARN") { + Write-ColorText " $_" -Color Yellow + } elseif ($_.Trim()) { + Write-ColorText " $_" -Color DarkGray + } + } + } + Remove-Item "$env:TEMP\npm-out.txt" -Force -ErrorAction SilentlyContinue + } + + if (Test-Path "$env:TEMP\npm-err.txt") { + $errOutput = Get-Content "$env:TEMP\npm-err.txt" -Raw + if ($errOutput -and $errOutput.Trim()) { + $errOutput.Split("`n") | ForEach-Object { + if ($_ -match "ERR|error") { + Write-ColorText " $_" -Color Red + } elseif ($_ -match "WARN") { + Write-ColorText " $_" -Color Yellow + } + } + } + Remove-Item "$env:TEMP\npm-err.txt" -Force -ErrorAction SilentlyContinue + } + + if ($process.ExitCode -ne 0) { + throw "npm install failed with exit code: $($process.ExitCode)" + } + } catch { + Write-Error2 "Failed to install Claude Code: $_" + Write-Info "Try running manually: npm install -g @anthropic-ai/claude-code" + return $false + } + + Write-Host "" + + # Verify installation + $claudePath = "$env:APPDATA\npm\claude.cmd" + if (Test-Path $claudePath) { + Write-Success "Claude Code installed successfully!" + Write-Info "Location: $claudePath" + return $true + } else { + # Check if claude is in PATH + $claudeInPath = Get-Command claude -ErrorAction SilentlyContinue + if ($claudeInPath) { + Write-Success "Claude Code installed successfully!" + Write-Info "Location: $($claudeInPath.Source)" + return $true + } else { + Write-Warning2 "Claude Code may have been installed but is not in PATH." + Write-Info "Try restarting your terminal or running: refreshenv" + return $true + } + } +} + +#------------------------------------------------------------------------------- +# Permission Configuration +#------------------------------------------------------------------------------- + +function Set-ClaudePermissions { + Write-Section "🛡 Permission Configuration" + + Write-Host " Claude Code can run with different permission levels:" + Write-Host "" + Write-ColorText " ┌─────────────────────────────────────────────────────────────────────┐" -Color White + Write-ColorText " │ │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "1." -Color Cyan -NoNewline + Write-ColorText " Normal Mode" -Color White -NoNewline + Write-ColorText " (Recommended for most users) │" -Color DarkGray + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Claude will ask permission before file edits and commands" -Color DarkGray -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "✓ Safe ✓ Interactive ✓ Full control" -Color Green -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "2." -Color Cyan -NoNewline + Write-ColorText " Auto-Accept Edits" -Color White -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Automatically accept file edits, ask for commands" -Color DarkGray -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "⚡ Faster editing ✓ Command safety" -Color Yellow -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "3." -Color Cyan -NoNewline + Write-ColorText " Full Auto Mode" -Color White -NoNewline + Write-ColorText " (--dangerously-skip-permissions) │" -Color DarkGray + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Skip all permission prompts (use with caution!)" -Color DarkGray -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "⚠ No confirmations ⚠ Full system access" -Color Red -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "4." -Color Cyan -NoNewline + Write-ColorText " Don't start Claude" -Color White -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ " -Color White -NoNewline + Write-ColorText "Exit installer without starting Claude" -Color DarkGray -NoNewline + Write-ColorText " │" -Color White + Write-ColorText " │ │" -Color White + Write-ColorText " └─────────────────────────────────────────────────────────────────────┘" -Color White + Write-Host "" + + while ($true) { + Write-ColorText "? " -Color Yellow -NoNewline + Write-ColorText "Select permission mode [" -Color White -NoNewline + Write-ColorText "1" -Color Green -NoNewline + Write-ColorText "/" -Color White -NoNewline + Write-ColorText "2" -Color Cyan -NoNewline + Write-ColorText "/" -Color White -NoNewline + Write-ColorText "3" -Color Red -NoNewline + Write-ColorText "/" -Color White -NoNewline + Write-ColorText "4" -Color White -NoNewline + Write-ColorText "]: " -Color White -NoNewline + + $choice = Read-Host + + switch ($choice) { + "1" { + $script:PermissionMode = "normal" + $script:ClaudeCmd = "claude" + Write-Success "Selected: Normal Mode" + return + } + "2" { + $script:PermissionMode = "auto-edit" + $script:ClaudeCmd = "claude --auto-accept-edits" + Write-Success "Selected: Auto-Accept Edits" + return + } + "3" { + $script:PermissionMode = "full-auto" + Write-Host "" + Write-Warning2 "⚠️ WARNING: Full Auto Mode gives Claude unrestricted access!" + Write-ColorText " " -Color White -NoNewline + Write-ColorText "This mode will:" -Color Red + Write-ColorText " • Execute commands without confirmation" -Color Red + Write-ColorText " • Modify files without asking" -Color Red + Write-ColorText " • Have full access to your system" -Color Red + Write-Host "" + + if (Confirm-Action "Are you sure you want to use Full Auto Mode?" -DefaultYes $false) { + $script:ClaudeCmd = "claude --dangerously-skip-permissions" + Write-Success "Selected: Full Auto Mode" + return + } else { + Write-Host "" + Write-Info "Please select a different mode." + Write-Host "" + } + } + "4" { + $script:PermissionMode = "exit" + $script:ClaudeCmd = "" + Write-Info "Installation complete. You can start Claude anytime with: claude" + return + } + default { + Write-Error2 "Invalid choice. Please enter 1, 2, 3, or 4." + } + } + } +} + +#------------------------------------------------------------------------------- +# Launch Claude Code +#------------------------------------------------------------------------------- + +function Start-Claude { + if ($PermissionMode -eq "exit") { + Write-Section "✓ Installation Complete!" + Write-ColorText " Claude Code has been successfully installed!" -Color Green + Write-Host "" + Write-ColorText " To start Claude Code, open a new terminal and run:" -Color White + Write-Host "" + Write-ColorText " claude" -Color Cyan -NoNewline + Write-ColorText " # Normal mode" -Color DarkGray + Write-ColorText " claude --auto-accept-edits" -Color Cyan -NoNewline + Write-ColorText " # Auto-accept file edits" -Color DarkGray + Write-ColorText " claude --dangerously-skip-permissions" -Color Cyan -NoNewline + Write-ColorText " # Full auto mode" -Color DarkGray + Write-Host "" + Write-Info "If 'claude' is not recognized, restart your terminal to refresh PATH." + Write-Host "" + Write-Success "Thank you for installing Claude Code!" + return + } + + Write-Section "🚀 Launching Claude Code" + + Write-ColorText " Starting Claude Code with: " -Color White -NoNewline + Write-ColorText $ClaudeCmd -Color Cyan + Write-Host "" + Write-ColorText " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -Color DarkGray + Write-Host "" + + Start-Sleep -Seconds 1 + + # Ensure PATH is set + $npmPath = "$env:APPDATA\npm" + $env:Path = "$npmPath;$env:Path" + + # Launch Claude + try { + if ($PermissionMode -eq "normal") { + & claude + } elseif ($PermissionMode -eq "auto-edit") { + & claude --auto-accept-edits + } else { + & claude --dangerously-skip-permissions + } + } catch { + Write-Error2 "Failed to start Claude Code." + Write-Info "Try opening a new terminal and running: $ClaudeCmd" + } +} + +#------------------------------------------------------------------------------- +# Main Script Execution +#------------------------------------------------------------------------------- + +function Main { + # Check Windows version + if ([Environment]::OSVersion.Platform -ne "Win32NT") { + Write-Error2 "This script is designed for Windows only." + exit 1 + } + + # Display banner + Write-Banner + + Write-ColorText " Welcome to the Claude Code Installer!" -Color White + Write-Host "" + Write-ColorText " This script will:" -Color DarkGray + Write-ColorText " 1. Detect your Windows system" -Color DarkGray + Write-ColorText " 2. Check/install Node.js 20 LTS" -Color DarkGray + Write-ColorText " 3. Install Claude Code" -Color DarkGray + Write-ColorText " 4. Configure permissions" -Color DarkGray + Write-Host "" + + if (-not (Confirm-Action "Ready to begin installation?")) { + Write-Host "" + Write-Info "Installation cancelled. Goodbye!" + exit 0 + } + + # Run installation steps + Get-SystemInfo + Test-NodeInstallation + + if (-not (Test-NodeVerification)) { + exit 1 + } + + if (-not (Install-ClaudeCode)) { + exit 1 + } + + Set-ClaudePermissions + Start-Claude +} + +# Run main function +Main