|
| 1 | +# ClaudeCodeNotification — Windows Remote Installer |
| 2 | +# One-line install: irm https://raw.githubusercontent.com/splazapp/claude-code-notification/main/windows/install-remote.ps1 | iex |
| 3 | +# |
| 4 | +# Environment variables: |
| 5 | +# $env:VERSION = "v2.3.0" — pin to a specific release (default: latest) |
| 6 | + |
| 7 | +Set-StrictMode -Version Latest |
| 8 | +$ErrorActionPreference = "Stop" |
| 9 | + |
| 10 | +$Repo = "splazapp/claude-code-notification" |
| 11 | +$ExeName = "claudecode-notification.exe" |
| 12 | +$ScriptName = "claudecode-notification.ps1" |
| 13 | +$InstallDir = "$env:APPDATA\claudecode-notification" |
| 14 | +$SettingsFile = "$HOME\.claude\settings.json" |
| 15 | +$AppId = "ClaudeCodeNotification" |
| 16 | + |
| 17 | +Write-Host "" |
| 18 | +Write-Host "=== ClaudeCodeNotification Windows Remote Installer ===" -ForegroundColor Cyan |
| 19 | +Write-Host "" |
| 20 | + |
| 21 | +# ─── Pre-flight checks ─── |
| 22 | + |
| 23 | +# Windows 10 1809+ (build 17763) |
| 24 | +$build = [System.Environment]::OSVersion.Version.Build |
| 25 | +if ($build -lt 17763) { |
| 26 | + Write-Host "Error: Windows 10 1809 (build 17763) or later required. Your build: $build" -ForegroundColor Red |
| 27 | + exit 1 |
| 28 | +} |
| 29 | + |
| 30 | +# PowerShell 5.1+ |
| 31 | +if ($PSVersionTable.PSVersion.Major -lt 5 -or |
| 32 | + ($PSVersionTable.PSVersion.Major -eq 5 -and $PSVersionTable.PSVersion.Minor -lt 1)) { |
| 33 | + Write-Host "Error: PowerShell 5.1+ required." -ForegroundColor Red |
| 34 | + exit 1 |
| 35 | +} |
| 36 | + |
| 37 | +# Claude Code installed |
| 38 | +if (-not (Test-Path "$HOME\.claude")) { |
| 39 | + Write-Host "Error: ~/.claude/ not found. Please install Claude Code first." -ForegroundColor Red |
| 40 | + exit 1 |
| 41 | +} |
| 42 | + |
| 43 | +# Node.js (needed for hooks setup) |
| 44 | +if (-not (Get-Command node -ErrorAction SilentlyContinue)) { |
| 45 | + Write-Host "Error: Node.js is required (included with Claude Code)." -ForegroundColor Red |
| 46 | + exit 1 |
| 47 | +} |
| 48 | + |
| 49 | +# ─── Determine version ─── |
| 50 | + |
| 51 | +$ReleaseTag = if ($env:VERSION) { $env:VERSION } else { "latest" } |
| 52 | + |
| 53 | +if ($ReleaseTag -ne "latest") { |
| 54 | + Write-Host "==> Using specified version: $ReleaseTag" |
| 55 | +} else { |
| 56 | + Write-Host "==> Downloading latest release ..." |
| 57 | +} |
| 58 | + |
| 59 | +# ─── Temporary directory with cleanup ─── |
| 60 | + |
| 61 | +$TmpDir = Join-Path $env:TEMP "claudecode-notification-install-$(Get-Random)" |
| 62 | +New-Item -ItemType Directory -Force -Path $TmpDir | Out-Null |
| 63 | + |
| 64 | +try { |
| 65 | + # ─── Download exe from GitHub Releases ─── |
| 66 | + |
| 67 | + if ($ReleaseTag -eq "latest") { |
| 68 | + $ExeUrl = "https://github.com/$Repo/releases/latest/download/$ExeName" |
| 69 | + } else { |
| 70 | + $ExeUrl = "https://github.com/$Repo/releases/download/$ReleaseTag/$ExeName" |
| 71 | + } |
| 72 | + |
| 73 | + Write-Host " Fetching $ExeName ..." |
| 74 | + try { |
| 75 | + Invoke-WebRequest -Uri $ExeUrl -OutFile (Join-Path $TmpDir $ExeName) -UseBasicParsing |
| 76 | + } catch { |
| 77 | + Write-Host "Error: Failed to download $ExeName from $ExeUrl" -ForegroundColor Red |
| 78 | + Write-Host " $_" -ForegroundColor Red |
| 79 | + exit 1 |
| 80 | + } |
| 81 | + |
| 82 | + # ─── Download hook script from raw.githubusercontent.com ─── |
| 83 | + |
| 84 | + if ($ReleaseTag -eq "latest") { |
| 85 | + $ScriptUrl = "https://raw.githubusercontent.com/$Repo/main/windows/$ScriptName" |
| 86 | + } else { |
| 87 | + $ScriptUrl = "https://raw.githubusercontent.com/$Repo/$ReleaseTag/windows/$ScriptName" |
| 88 | + } |
| 89 | + |
| 90 | + Write-Host " Fetching $ScriptName ..." |
| 91 | + try { |
| 92 | + Invoke-WebRequest -Uri $ScriptUrl -OutFile (Join-Path $TmpDir $ScriptName) -UseBasicParsing |
| 93 | + } catch { |
| 94 | + Write-Host "Error: Failed to download $ScriptName from $ScriptUrl" -ForegroundColor Red |
| 95 | + Write-Host " $_" -ForegroundColor Red |
| 96 | + exit 1 |
| 97 | + } |
| 98 | + |
| 99 | + # ─── Install files ─── |
| 100 | + |
| 101 | + Write-Host "==> Installing to $InstallDir ..." |
| 102 | + if (Test-Path $InstallDir) { Remove-Item $InstallDir -Recurse -Force } |
| 103 | + New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null |
| 104 | + |
| 105 | + Copy-Item (Join-Path $TmpDir $ScriptName) (Join-Path $InstallDir $ScriptName) |
| 106 | + Copy-Item (Join-Path $TmpDir $ExeName) (Join-Path $InstallDir $ExeName) |
| 107 | + |
| 108 | + Write-Host " Copied $ScriptName" |
| 109 | + Write-Host " Copied $ExeName" |
| 110 | + |
| 111 | + # ─── Register Toast AUMID ─── |
| 112 | + |
| 113 | + Write-Host "==> Registering Toast AppUserModelId ..." |
| 114 | + $RegPath = "HKCU:\SOFTWARE\Classes\AppUserModelId\$AppId" |
| 115 | + if (-not (Test-Path $RegPath)) { New-Item -Path $RegPath -Force | Out-Null } |
| 116 | + Set-ItemProperty -Path $RegPath -Name "DisplayName" -Value $AppId |
| 117 | + Write-Host " Registered: $AppId" |
| 118 | + |
| 119 | + # ─── Configure Claude Code hooks ─── |
| 120 | + |
| 121 | + Write-Host "==> Configuring Claude Code hooks ..." |
| 122 | + |
| 123 | + $SettingsDir = Split-Path $SettingsFile |
| 124 | + if (-not (Test-Path $SettingsDir)) { New-Item -ItemType Directory -Force -Path $SettingsDir | Out-Null } |
| 125 | + if (-not (Test-Path $SettingsFile)) { '{}' | Set-Content $SettingsFile -Encoding UTF8 } |
| 126 | + |
| 127 | + $HookScript = Join-Path $InstallDir $ScriptName |
| 128 | + |
| 129 | + $TmpJs = Join-Path $env:TEMP "claudecode-notification-setup.js" |
| 130 | + @' |
| 131 | +const fs = require('fs'); |
| 132 | +const settingsPath = process.argv[2]; |
| 133 | +const hookScript = process.argv[3]; |
| 134 | +const psPrefix = 'powershell.exe -ExecutionPolicy Bypass -NonInteractive -File'; |
| 135 | +
|
| 136 | +let settings = {}; |
| 137 | +try { settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch {} |
| 138 | +settings.hooks = settings.hooks || {}; |
| 139 | +
|
| 140 | +for (const event of ['UserPromptSubmit', 'Stop', 'Notification']) { |
| 141 | + const fullCmd = psPrefix + ' "' + hookScript + '" ' + event; |
| 142 | + const hookEntry = { hooks: [{ type: 'command', command: fullCmd }] }; |
| 143 | + const existing = settings.hooks[event] || []; |
| 144 | + const already = existing.some(e => |
| 145 | + e.hooks && e.hooks.some(h => h.command && h.command.includes('claudecode-notification.ps1')) |
| 146 | + ); |
| 147 | + if (!already) existing.push(hookEntry); |
| 148 | + settings.hooks[event] = existing; |
| 149 | +} |
| 150 | +
|
| 151 | +fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n', 'utf8'); |
| 152 | +console.log(' settings.json updated.'); |
| 153 | +'@ | Set-Content $TmpJs -Encoding UTF8 |
| 154 | + |
| 155 | + node $TmpJs $SettingsFile $HookScript |
| 156 | + Remove-Item $TmpJs -Force -ErrorAction SilentlyContinue |
| 157 | + |
| 158 | + # ─── Done ─── |
| 159 | + |
| 160 | + Write-Host "" |
| 161 | + Write-Host "==> Installation complete!" -ForegroundColor Green |
| 162 | + Write-Host "" |
| 163 | + Write-Host "Hooks registered for: UserPromptSubmit, Stop, Notification" |
| 164 | + Write-Host "Install dir: $InstallDir" |
| 165 | + Write-Host "" |
| 166 | + Write-Host "On first notification, Windows may ask for notification permission." -ForegroundColor Yellow |
| 167 | + Write-Host "If notifications don't appear: Settings -> System -> Notifications -> ClaudeCodeNotification -> On" |
| 168 | + |
| 169 | +} finally { |
| 170 | + # ─── Cleanup temp directory ─── |
| 171 | + Remove-Item $TmpDir -Recurse -Force -ErrorAction SilentlyContinue |
| 172 | +} |
0 commit comments