OpenCode 2 is the open-source programming agent for the terminal. In Windows, installing it with npm causes problems: the documentation indicates that Windows package managers are not supported, and it usually appears with the error "The executable specified is not a valid application for this operating system". The way it works is to download the binary directly.
If you had v1 or a v2 attempt installed with npm, remove it to avoid conflicts:
npm uninstall -g @opencode/cli opencode-ai Remove-Item "$env:APPDATA\npm\opencode", "$env:APPDATA\npm\opencode.cmd", "$env:APPDATA\npm\opencode.ps1" -ErrorAction SilentlyContinue Remove-Item -Recurse -Force "$env:APPDATA\npm\node_modules\@opencode" -ErrorAction SilentlyContinue
Step 2: Download the OpenCode 2 Binary
Replace $ver with the latest version available (check opencode.ai/v2/docs):
$ver = "2.0.18" $dir = "$env:USERPROFILE\.opencode\bin" New-Item -ItemType Directory -Force $dir | Out-Null Invoke-WebRequest "https://opencode.ai/files/bin/$ver/opencode-windows-x64.zip" -OutFile "$env:TEMP\opencode.zip" Expand-Archive "$env:TEMP\opencode.zip" -DestinationPath $dir -Force
Step 3: Add it to PATH
$dir = "$env:USERPROFILE\.opencode\bin" # For the current terminal $env:Path = "$dir;$env:Path" # For future terminals $userPath = [Environment]::GetEnvironmentVariable("Path","User") if ($userPath -notlike "*$dir*") { [Environment]::SetEnvironmentVariable("Path", "$dir;$userPath", "User") }
Step 4: Check the installation
opencode --version
It should show something like opencode v2.0.18.
cd C:\ruta\a\tu\proyecto opencode
Update to future versions
Do not use opencode upgrade or /update in Windows: there are open issues where the upgrade always fails because it passes to bash a route with backslashes. The manual update works like this: rename the executable in use to opencode.exe.old, copy the new one and restart.
# Close OpenCode before $ver = "2.0.19" # the new version $dir = "$env:USERPROFILE\.opencode\bin" Rename-Item "$dir\opencode.exe" "opencode.exe.old" -Force Invoke-WebRequest "https://opencode.ai/files/bin/$ver/opencode-windows-x64.zip" -OutFile "$env:TEMP\opencode.zip" Expand-Archive "$env:TEMP\opencode.zip" -DestinationPath $dir -Force opencode --version
Troubleshooting
| Problem | Solution |
|---|---|
opencode not recognized as a command |
Close and open a new terminal. If you use VS Code, restart it entirely. |
| The v1 is opened instead of v2 | Run Get-Command opencode -All and remove the ones not in .opencode\bin. |
The .exe gives a platform not valid error |
Check your architecture with $env:PROCESSOR_ARCHITECTURE and download the ARM64 or x64 baseline from the downloads page. |
| You prefer not to use PowerShell | The v2 installer works manually executed in Git Bash, so curl -fsSL https://opencode.ai/v2/install | bash in Git Bash or WSL is an alternative. |
Save the path permanently:
$dir = "$env:USERPROFILE\.opencode\bin"$userPath = [Environment]::GetEnvironmentVariable("Path","User")[Environment]::SetEnvironmentVariable("Path", ($userPath.TrimEnd(';') + ";" + $dir), "User")# Refresh this terminal without restarting$env:Path = [Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [Environment]::GetEnvironmentVariable("Path","User") opencode --versionSet-ExecutionPolicy -Scope CurrentUser RemoteSigned
