@echo off REM AI Development Tools Installer for Windows REM Installs: Node.js, npm, Claude Code, Codex CLI REM Platform: Windows 10/11 REM Version: 3.4.0 (Simplified, No Redundant Checks) setlocal enabledelayedexpansion REM Script Configuration set "SCRIPT_VERSION=3.4.0" set "NODE_VERSION=24" set "MIN_NODE_VERSION=18.0.0" set "MIN_NPM_VERSION=9.0.0" REM npm Package Configuration set "CLAUDE_NPM_PACKAGE=@anthropic-ai/claude-code" set "CLAUDE_CMD=claude" set "CLAUDE_NAME=Claude Code" set "CODEX_NPM_PACKAGE=@openai/codex" set "CODEX_CMD=codex" set "CODEX_NAME=Codex CLI" REM Installation Choices (set by user) set "INSTALL_CLAUDE=false" set "INSTALL_CODEX=false" REM Jump to main function goto :main REM ============================================ REM Utility Functions REM ============================================ :print_banner cls echo. echo ============================================================ echo. echo AI Development Tools Installer v%SCRIPT_VERSION% echo. echo Installs: Node.js, Claude Code, Codex CLI echo Platform: Windows 10/11 echo. echo ============================================================ echo. goto :eof :print_info echo [INFO] %~1 goto :eof :print_success echo [ OK ] %~1 goto :eof :print_warning echo [WARN] %~1 goto :eof :print_error echo [FAIL] %~1 goto :eof :print_step echo [STEP] %~1 goto :eof :print_section echo. echo ============================================================ echo %~1 echo ============================================================ echo. goto :eof REM ============================================ REM User Selection Menu REM ============================================ :show_install_menu cls echo. echo ============================================================ echo. echo AI Development Tools Installer v%SCRIPT_VERSION% echo. echo ============================================================ echo. echo Select tools to install: echo. echo 1) Claude Code only echo 2) Codex CLI only echo 3) Install both (Recommended) echo q) Quit echo. set /p "INSTALL_CHOICE=Choose [1-3]: " if "%INSTALL_CHOICE%"=="1" ( set "INSTALL_CLAUDE=true" set "INSTALL_CODEX=false" call :print_success "Will install: Claude Code" goto :eof ) if "%INSTALL_CHOICE%"=="2" ( set "INSTALL_CLAUDE=false" set "INSTALL_CODEX=true" call :print_success "Will install: Codex CLI" goto :eof ) if "%INSTALL_CHOICE%"=="3" ( set "INSTALL_CLAUDE=true" set "INSTALL_CODEX=true" call :print_success "Will install: Claude Code + Codex CLI" goto :eof ) if /i "%INSTALL_CHOICE%"=="q" ( call :print_info "Installation cancelled" timeout /t 2 /nobreak >nul exit 0 ) call :print_error "Invalid selection" echo. pause goto :show_install_menu REM ============================================ REM Check Administrator Privileges REM ============================================ :check_admin net session >nul 2>&1 if %errorLevel% == 0 ( call :print_success "Administrator privileges detected" ) else ( call :print_warning "Not running as administrator" call :print_info "Some features may require admin privileges" ) goto :eof REM ============================================ REM Version Checks REM ============================================ :check_git_installed where git >nul 2>&1 if %errorLevel% neq 0 ( call :print_warning "Git not found" call :print_info "Git is recommended for development" echo. REM Try to install with winget where winget >nul 2>&1 if %errorLevel% equ 0 ( call :print_step "Installing Git using winget..." winget install --id Git.Git -e --source winget --silent --accept-package-agreements --accept-source-agreements if %errorLevel% equ 0 ( call :print_success "Git installed successfully" call :print_warning "Please close and reopen command prompt to use git" exit /b 0 ) else ( call :print_error "Git installation failed" ) ) else ( call :print_info "winget not found, skipping auto-install" ) call :print_info "You can manually download from: https://git-scm.com/download/win" exit /b 1 ) for /f "delims=" %%i in ('git --version') do set "GIT_VER=%%i" call :print_success "!GIT_VER!" exit /b 0 :check_node_installed where node >nul 2>&1 if %errorLevel% neq 0 ( exit /b 1 ) for /f "delims=" %%i in ('node -v') do set "NODE_VER=%%i" set "NODE_VER=%NODE_VER:v=%" call :print_info "Current Node.js version: v%NODE_VER%" call :print_success "Node.js is installed" exit /b 0 :check_npm_installed where npm >nul 2>&1 if %errorLevel% neq 0 ( call :print_error "npm not found" exit /b 1 ) for /f "delims=" %%i in ('npm -v') do set "NPM_VER=%%i" call :print_info "Current npm version: v%NPM_VER%" call :print_success "npm is available" exit /b 0 REM ============================================ REM Node.js Installation REM ============================================ :install_nodejs call :print_step "Checking Node.js installation..." echo. call :check_node_installed if %errorLevel% equ 0 ( call :print_success "Node.js already installed, skipping" goto :eof ) call :print_warning "Node.js not found" echo. REM Auto-detect installation method call :print_step "Auto-detecting installation method..." REM 1. Try winget (Windows 10+ recommended) where winget >nul 2>&1 if %errorLevel% equ 0 ( call :print_info "Detected winget, using winget to install" goto :install_with_winget ) REM 2. Try Chocolatey where choco >nul 2>&1 if %errorLevel% equ 0 ( call :print_info "Detected Chocolatey, using choco to install" goto :install_with_choco ) REM 3. Manual installation needed call :print_warning "Neither winget nor Chocolatey detected" goto :install_manual :install_with_winget call :print_step "Installing Node.js LTS with winget..." call :print_info "winget will automatically configure system PATH" echo. winget install OpenJS.NodeJS.LTS --silent --accept-package-agreements --accept-source-agreements if %errorLevel% equ 0 ( call :print_success "Node.js installation complete" echo. call :print_warning "IMPORTANT:" echo 1. Please close all command prompt windows echo 2. Open a new command prompt echo 3. Run this script again to continue echo. call :print_info "Environment variables configured, restart terminal to take effect" echo. pause exit /b 0 ) else ( call :print_error "Node.js installation failed" call :print_info "Please try manual installation: https://nodejs.org/" exit /b 1 ) :install_with_choco call :print_step "Installing Node.js LTS with Chocolatey..." call :print_info "Chocolatey will automatically configure system PATH" echo. choco install nodejs-lts -y if %errorLevel% equ 0 ( call :print_success "Node.js installation complete" call :print_info "Refreshing environment variables..." call refreshenv 2>nul echo. call :print_warning "If commands fail, please reopen command prompt" echo. exit /b 0 ) else ( call :print_error "Node.js installation failed" call :print_info "Please try manual installation: https://nodejs.org/" exit /b 1 ) :install_manual call :print_warning "Manual Node.js installation required" echo. call :print_info "Please follow these steps:" echo. echo 1. Visit: https://nodejs.org/ echo 2. Download LTS version installer echo 3. Run the installer echo 4. After installation, run this script again echo. call :print_info "Press any key to open Node.js website..." pause >nul start https://nodejs.org/ echo. call :print_info "After installation, please run this script again" pause exit /b 1 REM ============================================ REM npm Package Installation (Generic) REM ============================================ :install_npm_package set "PKG_NAME=%~1" set "CMD_NAME=%~2" set "DISPLAY_NAME=%~3" call :print_section "Installing %DISPLAY_NAME%" REM Check npm availability call :check_npm_installed if %errorLevel% neq 0 ( call :print_error "npm not available, cannot install %DISPLAY_NAME%" exit /b 1 ) REM Check if command already exists where %CMD_NAME% >nul 2>&1 if %errorLevel% equ 0 ( for /f "delims=" %%i in ('%CMD_NAME% --version 2^>nul') do set "PKG_VERSION=%%i" if "!PKG_VERSION!"=="" set "PKG_VERSION=unknown" call :print_success "%DISPLAY_NAME% already installed (version: !PKG_VERSION!)" call :print_info "Skipping installation" exit /b 0 ) REM Command not found, install directly call :print_step "Installing %DISPLAY_NAME%..." call :print_info "This may take a few minutes, please wait..." echo. REM Install with optimized settings call npm install -g %PKG_NAME% --loglevel=warn if %errorLevel% equ 0 ( timeout /t 2 /nobreak >nul REM Verify installation where %CMD_NAME% >nul 2>&1 if %errorLevel% equ 0 ( for /f "delims=" %%i in ('%CMD_NAME% --version 2^>nul') do set "PKG_VERSION=%%i" if "!PKG_VERSION!"=="" set "PKG_VERSION=installed" call :print_success "%DISPLAY_NAME% successfully installed (version: !PKG_VERSION!)" ) else ( call :print_warning "%DISPLAY_NAME% installed, but %CMD_NAME% command not found" call :show_path_help ) exit /b 0 ) else ( call :print_error "%DISPLAY_NAME% installation failed" call :print_info "You can try manually: npm install -g %PKG_NAME%" exit /b 1 ) REM ============================================ REM PATH Configuration Help REM ============================================ :check_path_contains set "SEARCH_PATH=%~1" echo %PATH% | findstr /C:"%SEARCH_PATH%" >nul 2>&1 exit /b %errorLevel% :show_path_help echo. REM Get npm global path for /f "delims=" %%i in ('npm config get prefix 2^>nul') do set "NPM_PREFIX=%%i" REM Check if PATH already contains npm path if defined NPM_PREFIX ( call :check_path_contains "%NPM_PREFIX%" if %errorLevel% equ 0 ( call :print_success "npm global path is already in system PATH" call :print_info "Please close and reopen command prompt to refresh environment" goto :eof ) ) call :print_warning "npm command not found, PATH configuration may be needed" echo. call :print_info "Please try these solutions:" echo. echo 1. Close and reopen command prompt (Recommended) echo 2. Log out and log back into Windows echo 3. Restart computer echo. if defined NPM_PREFIX ( call :print_info "npm global installation path: %NPM_PREFIX%" call :print_warning "If above methods don't work, manually check system PATH environment variable" ) else ( call :print_info "npm global installation path is usually:" echo %%AppData%%\npm or C:\Program Files\nodejs ) echo. call :print_info "To configure manually:" echo 1. Right-click "This PC" -^> Properties -^> Advanced system settings echo 2. Environment Variables -^> System variables -^> Path -^> Edit echo 3. Add npm global path echo. goto :eof REM ============================================ REM Environment Verification REM ============================================ :verify_installation call :print_banner echo ============================================================ echo Installation Complete echo ============================================================ echo. echo Installed tools: echo. REM Node.js where node >nul 2>&1 if %errorLevel% equ 0 ( for /f "delims=" %%i in ('node -v') do set "NODE_VER=%%i" call :print_success "Node.js: !NODE_VER!" ) else ( call :print_error "Node.js not installed" ) REM npm where npm >nul 2>&1 if %errorLevel% equ 0 ( for /f "delims=" %%i in ('npm -v') do set "NPM_VER=%%i" call :print_success "npm: v!NPM_VER!" ) else ( call :print_error "npm not installed" ) REM Git where git >nul 2>&1 if %errorLevel% equ 0 ( for /f "delims=" %%i in ('git --version') do set "GIT_VER=%%i" call :print_success "!GIT_VER!" ) else ( call :print_warning "Git not installed (recommended)" ) REM Claude Code where claude >nul 2>&1 if %errorLevel% equ 0 ( for /f "delims=" %%i in ('claude --version 2^>nul') do set "CLAUDE_VER=%%i" if "!CLAUDE_VER!"=="" set "CLAUDE_VER=installed" call :print_success "Claude Code: !CLAUDE_VER!" ) else ( call :print_warning "Claude Code not installed" ) REM Codex CLI where codex >nul 2>&1 if %errorLevel% equ 0 ( for /f "delims=" %%i in ('codex --version 2^>nul') do set "CODEX_VER=%%i" if "!CODEX_VER!"=="" set "CODEX_VER=installed" call :print_success "Codex CLI: !CODEX_VER!" ) else ( call :print_warning "Codex CLI not installed" ) echo. echo ============================================================ echo Usage Instructions echo ============================================================ echo. call :print_info "Claude Code usage:" echo ^> claude --help echo ^> claude "your question" echo. call :print_warning "IMPORTANT:" echo If commands don't work, close and reopen command prompt echo. goto :eof REM ============================================ REM Network Check REM ============================================ :check_network ping -n 1 -w 2000 www.baidu.com >nul 2>&1 if %errorLevel% equ 0 ( call :print_success "Network connection OK" exit /b 0 ) ping -n 1 -w 2000 8.8.8.8 >nul 2>&1 if %errorLevel% equ 0 ( call :print_success "Network connection OK" exit /b 0 ) call :print_warning "Network connection may have issues, continuing anyway..." exit /b 1 REM ============================================ REM Main Function REM ============================================ :main REM Show selection menu call :show_install_menu echo. timeout /t 1 /nobreak >nul call :print_banner REM Check admin privileges call :check_admin echo. REM Check network call :check_network echo. REM Check git (recommended) call :print_step "Checking Git..." call :check_git_installed echo. call :print_info "This script will install:" echo 1. Node.js (^>= %MIN_NODE_VERSION%) echo 2. npm (^>= %MIN_NPM_VERSION%) if "%INSTALL_CLAUDE%"=="true" ( echo 3. Claude Code ) if "%INSTALL_CODEX%"=="true" ( echo 4. Codex CLI ) echo. call :print_step "Starting installation..." echo. REM 1. Install Node.js and npm call :install_nodejs if %errorLevel% neq 0 ( call :print_error "Node.js installation failed, cannot continue" pause exit /b 1 ) REM Refresh environment variables call refreshenv 2>nul REM 2. Install tools based on user selection if "%INSTALL_CLAUDE%"=="true" ( call :install_npm_package "%CLAUDE_NPM_PACKAGE%" "%CLAUDE_CMD%" "%CLAUDE_NAME%" ) if "%INSTALL_CODEX%"=="true" ( call :install_npm_package "%CODEX_NPM_PACKAGE%" "%CODEX_CMD%" "%CODEX_NAME%" ) REM 3. Show installation results echo. timeout /t 1 /nobreak >nul call :verify_installation echo. echo Window will close in 3 seconds... timeout /t 3 /nobreak >nul exit /b 0