-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathinstall-windows.ps1
More file actions
97 lines (81 loc) · 3.21 KB
/
install-windows.ps1
File metadata and controls
97 lines (81 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$Version = "2.1.81"
$Base = Split-Path -Parent $MyInvocation.MyCommand.Path
$NodeDir = Join-Path $Base "node"
$CliPath = Join-Path $NodeDir "node_modules/@anthropic-ai/claude-code/cli.js"
$CliBackup = "$CliPath.orig"
$PatchScript = Join-Path $Base "patches/apply-patches.py"
$WrapperDir = Join-Path $HOME ".local/bin"
$CmdWrapper = Join-Path $WrapperDir "claude-patched.cmd"
$PsWrapper = Join-Path $WrapperDir "claude-patched.ps1"
Write-Host "========================================"
Write-Host " Claude Code Cache Fix Installer"
Write-Host " Target: v$Version (Windows)"
Write-Host "========================================"
Write-Host ""
function Require-Command([string]$Name) {
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "$Name not found. Install it first and rerun."
}
}
Require-Command "node"
Require-Command "npm"
$PythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $PythonCmd) {
$PythonCmd = Get-Command py -ErrorAction SilentlyContinue
}
if (-not $PythonCmd) {
throw "python (or py launcher) not found. Install Python 3 first."
}
if (-not (Test-Path -Path $PatchScript)) {
throw "Patch script not found: $PatchScript"
}
if (-not (Test-Path -Path $CliPath)) {
Write-Host "[*] Installing @anthropic-ai/claude-code@$Version..."
npm install --prefix $NodeDir "@anthropic-ai/claude-code@$Version" | Out-Host
} else {
Write-Host "[*] cli.js already installed"
}
if (-not (Test-Path -Path $CliBackup)) {
Write-Host "[*] Backing up cli.js -> cli.js.orig"
Copy-Item -Path $CliPath -Destination $CliBackup
} else {
Write-Host "[*] Backup already exists"
}
Write-Host "[*] Restoring from backup..."
Copy-Item -Path $CliBackup -Destination $CliPath -Force
Write-Host "[*] Applying patches..."
& $PythonCmd.Source $PatchScript $CliPath | Out-Host
$PatchedVersion = (& node $CliPath --version 2>$null).Trim()
Write-Host "[*] Patched version: $PatchedVersion"
if ($PatchedVersion -ne "$Version (Claude Code)") {
Write-Host "[!] Version mismatch after patching. Restoring backup."
Copy-Item -Path $CliBackup -Destination $CliPath -Force
throw "Patch verification failed"
}
New-Item -ItemType Directory -Path $WrapperDir -Force | Out-Null
if (Test-Path $CmdWrapper) { Remove-Item $CmdWrapper -Force }
if (Test-Path $PsWrapper) { Remove-Item $PsWrapper -Force }
$cmdBody = @"
@echo off
node "$CliPath" %*
"@
Set-Content -Path $CmdWrapper -Value $cmdBody -Encoding ASCII
$psBody = @"
param([Parameter(ValueFromRemainingArguments=`$true)][string[]]`$Args)
& node "$CliPath" @Args
exit `$LASTEXITCODE
"@
Set-Content -Path $PsWrapper -Value $psBody -Encoding ASCII
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not $userPath) { $userPath = "" }
if (-not (($userPath -split ";") -contains $WrapperDir)) {
$newPath = if ([string]::IsNullOrWhiteSpace($userPath)) { $WrapperDir } else { "$userPath;$WrapperDir" }
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Host "[*] Added $WrapperDir to User PATH"
}
Write-Host ""
Write-Host "Done. Open a NEW terminal and run:"
Write-Host " claude-patched --version"
Write-Host "Stock 'claude' command is untouched."