alishahryar1--free-claude-code
d98a6b0ca0
## Problem Free Claude Code currently has to remain attached to a terminal, so closing that window stops the proxy and users have no native way to reopen Admin or control the background server. The contributed Windows wrapper also would have introduced a second bundled server lifecycle instead of reusing FCC's cleanup and restart ownership. Fixes #1147. ## Changes | Before | After | | --- | --- | | Users keep `fcc-server` running in a terminal. | Windows and macOS users can launch a console-free FCC Desktop host from a desktop/application shortcut and control it from the tray or menu bar. | | A wrapper would need to spawn and terminate a child server. | The terminal and desktop paths share one in-process supervisor, one graceful runtime shutdown path, and an OS-held singleton lock. | | Installers manage only command entry points. | Windows installs desktop and Start-menu shortcuts; macOS installs a per-user app bundle and owned desktop link; uninstallers remove only those FCC artifacts. | | Desktop behavior had no contract coverage. | Lifecycle, duplicate launch, restart/quit, GUI packaging, Windows shortcuts, macOS bundle creation, quoting, and ownership boundaries are covered alongside the full CI suite. | <!-- greptile_comment --> <details open><summary><h3>Greptile Summary</h3></summary> This PR adds a native FCC desktop launcher for Windows and macOS. The main changes are: - A shared server supervisor for terminal and desktop launches. - A singleton desktop host with tray or menu-bar controls. - Windows shortcuts and a per-user macOS app bundle. - Ownership checks for launcher installation and removal. - Tests for lifecycle, packaging, shortcuts, and uninstall behavior. </details> <h3>Confidence Score: 5/5</h3> This looks safe to merge. Startup restart requests are reserved before the worker starts. macOS bundle operations verify ownership before modifying or deleting files. Windows shortcut operations verify their targets before replacement or removal. No blocking issues were found in the updated code. <details><summary><h3><a href="https://www.greptile.com/trex"><img alt="T-Rex" src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg" height="20" align="absmiddle"></a> T-Rex Logs</h3></summary> **What T-Rex did** - Compared the pre-change contract test results against the parent commit f81af55630aa1adb518b748b9e6985c73c4c4775 and observed 3 failures and 4 passes, indicating the missing scheduled-startup lifecycle contract. - Executed the after-state contract validation with uv run pytest -n 0 tests/cli/test\_desktop.py -q and confirmed the run finished with 7 passes and an exit code of 0. - Verified that no real proxy or native GUI dependency was started during the after-state run. - Inspected the two log artifacts that accompany the proof to corroborate the test outcomes. <a href="https://app.greptile.com/trex/runs/15235588/artifacts"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifactsDark.svg?v=4"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=4"><img alt="View all artifacts" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=4"></picture></a> <sub><a href="https://www.greptile.com/trex"><img alt="T-Rex" src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg" height="14" align="absmiddle"></a> Ran code and verified through T-Rex</sub> </details> <details open><summary><h3>Important Files Changed</h3></summary> | Filename | Overview | |----------|----------| | src/free_claude_code/cli/commands.py | Adds the shared server supervisor and scheduled-run state for startup restart requests. | | src/free_claude_code/cli/desktop.py | Adds singleton locking and coordinates the tray loop with the server worker. | | scripts/install.sh | Creates the macOS app bundle only when an existing bundle is FCC-owned. | | scripts/uninstall.sh | Removes the macOS launcher only on macOS and only with the expected ownership marker. | | scripts/install.ps1 | Creates Windows shortcuts while preserving shortcuts with unrelated targets. | | scripts/uninstall.ps1 | Removes Windows shortcuts only when their targets match an FCC desktop entry point. | </details> <sub>Reviews (3): Last reviewed commit: ["fix: coalesce desktop startup restarts"](https://github.com/alishahryar1/free-claude-code/commit/b9554729770e08a58818d677de39757c751e760e) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=45925660)</sub> <!-- /greptile_comment -->
656 行
19 KiB
PowerShell
656 行
19 KiB
PowerShell
param(
|
|
[switch] $VoiceNim,
|
|
[switch] $VoiceLocal,
|
|
[switch] $VoiceAll,
|
|
[string] $TorchBackend = "",
|
|
[switch] $DryRun,
|
|
[switch] $Help,
|
|
[Parameter(ValueFromRemainingArguments = $true)]
|
|
[object[]] $RemainingArgs = @()
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
$ProgressPreference = "SilentlyContinue"
|
|
|
|
$RepoArchiveUrl = "https://github.com/Alishahryar1/free-claude-code/archive/refs/heads/main.zip"
|
|
$PythonVersion = "3.14.0"
|
|
$MinUvVersion = "0.11.16"
|
|
$ClaudeInstallUrl = "https://claude.ai/install.ps1"
|
|
$CodexInstallUrl = "https://chatgpt.com/codex/install.ps1"
|
|
$PiInstallUrl = "https://pi.dev/install.ps1"
|
|
$UvInstallUrl = "https://astral.sh/uv/install.ps1"
|
|
$FccCommands = @(
|
|
# Include retired entry points so updates reject older FCC processes before replacement.
|
|
"fcc-desktop",
|
|
"fcc-server",
|
|
"fcc-claude",
|
|
"fcc-codex",
|
|
"fcc-pi",
|
|
"fcc-init",
|
|
"free-claude-code"
|
|
)
|
|
|
|
function Show-Usage {
|
|
@"
|
|
Usage: install.ps1 [options]
|
|
|
|
Installs Claude Code, Codex, and Pi if missing, ensures a compatible uv, and installs or updates Free Claude Code.
|
|
|
|
Options:
|
|
-VoiceNim Install NVIDIA NIM voice transcription support.
|
|
-VoiceLocal Install local Whisper voice transcription support.
|
|
-VoiceAll Install all voice transcription backends.
|
|
-TorchBackend VALUE Use a uv PyTorch backend, such as cu130. Requires local voice.
|
|
-DryRun Print commands without running them.
|
|
-Help Show this help text.
|
|
"@
|
|
}
|
|
|
|
function Write-Step {
|
|
param([string] $Message)
|
|
|
|
Write-Host ""
|
|
Write-Host "==> $Message"
|
|
}
|
|
|
|
function Format-Argument {
|
|
param([string] $Value)
|
|
|
|
if ($Value -match '^[A-Za-z0-9_./:@%+=,\[\]\\-]+$') {
|
|
return $Value
|
|
}
|
|
|
|
return "'" + ($Value -replace "'", "''") + "'"
|
|
}
|
|
|
|
function Format-Command {
|
|
param(
|
|
[string] $FilePath,
|
|
[string[]] $Arguments = @()
|
|
)
|
|
|
|
$parts = @($FilePath) + $Arguments
|
|
return ($parts | ForEach-Object { Format-Argument ([string] $_) }) -join " "
|
|
}
|
|
|
|
function Invoke-NativeCommand {
|
|
param(
|
|
[string] $FilePath,
|
|
[string[]] $Arguments = @()
|
|
)
|
|
|
|
$commandText = Format-Command -FilePath $FilePath -Arguments $Arguments
|
|
Write-Host "+ $commandText"
|
|
if ($DryRun) {
|
|
return
|
|
}
|
|
|
|
$global:LASTEXITCODE = 0
|
|
& $FilePath @Arguments
|
|
$exitCode = $LASTEXITCODE
|
|
if ($exitCode -ne 0) {
|
|
throw "Command failed with exit code ${exitCode}: $commandText"
|
|
}
|
|
}
|
|
|
|
function Invoke-NativeCapture {
|
|
param(
|
|
[string] $FilePath,
|
|
[string[]] $Arguments = @()
|
|
)
|
|
|
|
$commandText = Format-Command -FilePath $FilePath -Arguments $Arguments
|
|
Write-Host "+ $commandText"
|
|
$global:LASTEXITCODE = 0
|
|
$output = & $FilePath @Arguments
|
|
$exitCode = $LASTEXITCODE
|
|
if ($exitCode -ne 0) {
|
|
throw "Command failed with exit code ${exitCode}: $commandText"
|
|
}
|
|
|
|
return ($output | Out-String).Trim()
|
|
}
|
|
|
|
function Get-ApplicationCommand {
|
|
param([string] $Name)
|
|
|
|
$commands = @(Get-Command $Name -CommandType Application -ErrorAction SilentlyContinue)
|
|
if ($commands.Count -eq 0) {
|
|
return $null
|
|
}
|
|
|
|
return $commands[0]
|
|
}
|
|
|
|
function Get-PowerShellExecutable {
|
|
param([string] $PowerShellHome = $PSHOME)
|
|
|
|
$executableName = if ($PSVersionTable.PSEdition -eq "Core") {
|
|
"pwsh.exe"
|
|
}
|
|
else {
|
|
"powershell.exe"
|
|
}
|
|
$bundledExecutable = Join-Path $PowerShellHome $executableName
|
|
if (Test-Path -LiteralPath $bundledExecutable -PathType Leaf) {
|
|
return $bundledExecutable
|
|
}
|
|
|
|
$pathCommand = Get-ApplicationCommand ([IO.Path]::GetFileNameWithoutExtension($executableName))
|
|
if ($pathCommand) {
|
|
return $pathCommand.Source
|
|
}
|
|
|
|
throw "Unable to locate a PowerShell executable for the downloaded installer."
|
|
}
|
|
|
|
function Add-PathEntry {
|
|
param([string] $PathEntry)
|
|
|
|
if ([string]::IsNullOrWhiteSpace($PathEntry)) {
|
|
return
|
|
}
|
|
|
|
$separator = [IO.Path]::PathSeparator
|
|
$entries = @()
|
|
if (-not [string]::IsNullOrEmpty($env:Path)) {
|
|
$entries = $env:Path -split [regex]::Escape([string] $separator)
|
|
}
|
|
|
|
if ($entries -notcontains $PathEntry) {
|
|
$env:Path = "$PathEntry$separator$env:Path"
|
|
}
|
|
}
|
|
|
|
function Add-KnownBinDirectories {
|
|
if (-not [string]::IsNullOrWhiteSpace($env:USERPROFILE)) {
|
|
Add-PathEntry (Join-Path $env:USERPROFILE ".local\bin")
|
|
}
|
|
if (-not [string]::IsNullOrWhiteSpace($env:LOCALAPPDATA)) {
|
|
Add-PathEntry (Join-Path $env:LOCALAPPDATA "Programs\OpenAI\Codex\bin")
|
|
Add-PathEntry (Join-Path $env:LOCALAPPDATA "pi-node\current")
|
|
}
|
|
if (-not [string]::IsNullOrWhiteSpace($env:APPDATA)) {
|
|
Add-PathEntry (Join-Path $env:APPDATA "npm")
|
|
}
|
|
}
|
|
|
|
function Add-PiBinDirectories {
|
|
if ($DryRun) {
|
|
return
|
|
}
|
|
|
|
Add-KnownBinDirectories
|
|
$npm = Get-ApplicationCommand "npm"
|
|
if (-not $npm) {
|
|
return
|
|
}
|
|
|
|
$prefix = (& $npm.Source prefix -g 2>$null | Out-String).Trim()
|
|
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($prefix)) {
|
|
$prefix = (& $npm.Source config get prefix 2>$null | Out-String).Trim()
|
|
}
|
|
if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($prefix)) {
|
|
Add-PathEntry $prefix
|
|
}
|
|
}
|
|
|
|
function Assert-NoFccProcessesRunning {
|
|
$running = @()
|
|
foreach ($commandName in $FccCommands) {
|
|
$processes = @(Get-Process -Name $commandName -ErrorAction SilentlyContinue)
|
|
foreach ($process in $processes) {
|
|
$running += "$commandName (PID $($process.Id))"
|
|
}
|
|
}
|
|
|
|
if ($running.Count -gt 0) {
|
|
throw "Free Claude Code is still running ($($running -join ', ')). Stop those processes, then rerun the installer."
|
|
}
|
|
}
|
|
|
|
function Invoke-DownloadedPowerShellInstaller {
|
|
param(
|
|
[string] $Url,
|
|
[string] $Name,
|
|
[switch] $NonInteractive
|
|
)
|
|
|
|
if ($DryRun) {
|
|
Write-Host "+ irm $Url -OutFile <temporary-script>"
|
|
$prefix = if ($NonInteractive) { "CODEX_NON_INTERACTIVE=1 " } else { "" }
|
|
Write-Host "+ ${prefix}powershell -NoProfile -ExecutionPolicy Bypass -File <temporary-script>"
|
|
return
|
|
}
|
|
|
|
$temporaryScript = Join-Path ([IO.Path]::GetTempPath()) ("fcc-install-" + [guid]::NewGuid().ToString("N") + ".ps1")
|
|
try {
|
|
Write-Host "+ irm $Url -OutFile $(Format-Argument $temporaryScript)"
|
|
Invoke-RestMethod -Uri $Url -OutFile $temporaryScript -ErrorAction Stop
|
|
if ((-not (Test-Path -LiteralPath $temporaryScript)) -or ((Get-Item -LiteralPath $temporaryScript).Length -eq 0)) {
|
|
throw "The downloaded $Name installer was empty."
|
|
}
|
|
|
|
$powerShellPath = Get-PowerShellExecutable
|
|
|
|
$hadNonInteractive = Test-Path Env:CODEX_NON_INTERACTIVE
|
|
$previousNonInteractive = $env:CODEX_NON_INTERACTIVE
|
|
try {
|
|
if ($NonInteractive) {
|
|
$env:CODEX_NON_INTERACTIVE = "1"
|
|
}
|
|
Invoke-NativeCommand -FilePath $powerShellPath -Arguments @(
|
|
"-NoProfile",
|
|
"-ExecutionPolicy",
|
|
"Bypass",
|
|
"-File",
|
|
$temporaryScript
|
|
)
|
|
}
|
|
finally {
|
|
if ($hadNonInteractive) {
|
|
$env:CODEX_NON_INTERACTIVE = $previousNonInteractive
|
|
}
|
|
else {
|
|
Remove-Item Env:CODEX_NON_INTERACTIVE -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
}
|
|
finally {
|
|
Remove-Item -LiteralPath $temporaryScript -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
function Confirm-Application {
|
|
param(
|
|
[string] $CommandName,
|
|
[string] $DisplayName
|
|
)
|
|
|
|
if ($DryRun) {
|
|
Write-Host "+ $CommandName --version"
|
|
return
|
|
}
|
|
|
|
$command = Get-ApplicationCommand $CommandName
|
|
if (-not $command) {
|
|
throw "$DisplayName was installed, but '$CommandName' is not available on PATH."
|
|
}
|
|
Invoke-NativeCommand -FilePath $command.Source -Arguments @("--version")
|
|
}
|
|
|
|
function Test-PiApplication {
|
|
param($Command)
|
|
|
|
try {
|
|
$helpOutput = (& $Command.Source --help 2>$null | Out-String)
|
|
}
|
|
catch {
|
|
return $false
|
|
}
|
|
return (
|
|
$LASTEXITCODE -eq 0 -and
|
|
$helpOutput.Contains("--extension") -and
|
|
$helpOutput.Contains("--models")
|
|
)
|
|
}
|
|
|
|
function Confirm-PiApplication {
|
|
if ($DryRun) {
|
|
Write-Host "+ pi --help (verify --extension and --models support)"
|
|
Write-Host "+ pi --version"
|
|
return
|
|
}
|
|
|
|
$command = Get-ApplicationCommand "pi"
|
|
if (-not $command) {
|
|
throw "Pi was installed, but 'pi' is not available on PATH."
|
|
}
|
|
if (-not (Test-PiApplication $command)) {
|
|
throw "The 'pi' command at '$($command.Source)' is not a compatible Pi Coding Agent."
|
|
}
|
|
Invoke-NativeCommand -FilePath $command.Source -Arguments @("--version")
|
|
}
|
|
|
|
function Ensure-ClaudeCode {
|
|
if (Get-ApplicationCommand "claude") {
|
|
Write-Host "Claude Code already found on PATH; verifying it."
|
|
}
|
|
else {
|
|
Invoke-DownloadedPowerShellInstaller -Url $ClaudeInstallUrl -Name "Claude Code"
|
|
Add-KnownBinDirectories
|
|
}
|
|
|
|
Confirm-Application -CommandName "claude" -DisplayName "Claude Code"
|
|
}
|
|
|
|
function Ensure-Codex {
|
|
if (Get-ApplicationCommand "codex") {
|
|
Write-Host "Codex already found on PATH; verifying it."
|
|
}
|
|
else {
|
|
Invoke-DownloadedPowerShellInstaller -Url $CodexInstallUrl -Name "Codex" -NonInteractive
|
|
Add-KnownBinDirectories
|
|
}
|
|
|
|
Confirm-Application -CommandName "codex" -DisplayName "Codex"
|
|
}
|
|
|
|
function Ensure-Pi {
|
|
$existingPi = Get-ApplicationCommand "pi"
|
|
if ($existingPi -and ($DryRun -or (Test-PiApplication $existingPi))) {
|
|
Write-Host "Pi already found on PATH; verifying it."
|
|
}
|
|
else {
|
|
if ($existingPi) {
|
|
Write-Host "The existing 'pi' command at '$($existingPi.Source)' is not Pi Coding Agent; installing Pi."
|
|
}
|
|
Invoke-DownloadedPowerShellInstaller -Url $PiInstallUrl -Name "Pi"
|
|
Add-PiBinDirectories
|
|
}
|
|
|
|
Confirm-PiApplication
|
|
}
|
|
|
|
function Convert-UvVersionOutput {
|
|
param([string] $Output)
|
|
|
|
if ([string]::IsNullOrWhiteSpace($Output)) {
|
|
return ""
|
|
}
|
|
|
|
if ($Output -match '(?m)(?:^|\s)(?:uv\s+)?(?<version>\d+\.\d+\.\d+(?:[-+][0-9A-Za-z][0-9A-Za-z.-]*)?)\b') {
|
|
return $Matches["version"]
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
function Get-UvVersion {
|
|
param([string] $UvPath)
|
|
|
|
$output = Invoke-NativeCapture -FilePath $UvPath -Arguments @("--version")
|
|
$version = Convert-UvVersionOutput $output
|
|
if ([string]::IsNullOrWhiteSpace($version)) {
|
|
throw "uv is present, but 'uv --version' did not return a valid version."
|
|
}
|
|
|
|
return $version
|
|
}
|
|
|
|
function Test-SupportedUvVersion {
|
|
param(
|
|
[string] $Version,
|
|
[string] $Minimum
|
|
)
|
|
|
|
$parsedVersion = Convert-UvVersionOutput $Version
|
|
$parsedMinimum = Convert-UvVersionOutput $Minimum
|
|
if ([string]::IsNullOrWhiteSpace($parsedVersion) -or [string]::IsNullOrWhiteSpace($parsedMinimum)) {
|
|
throw "Unable to compare uv versions."
|
|
}
|
|
if ($parsedVersion.Contains("-")) {
|
|
return $false
|
|
}
|
|
|
|
$normalizedVersion = $parsedVersion -replace '\+.*$', ''
|
|
$normalizedMinimum = $parsedMinimum -replace '\+.*$', ''
|
|
|
|
return ([version] $normalizedVersion) -ge ([version] $normalizedMinimum)
|
|
}
|
|
|
|
function Confirm-Uv {
|
|
if ($DryRun) {
|
|
Write-Host "+ uv --version"
|
|
return
|
|
}
|
|
|
|
$uvCommand = Get-ApplicationCommand "uv"
|
|
if (-not $uvCommand) {
|
|
throw "uv was installed, but it is not available on PATH."
|
|
}
|
|
|
|
$version = Get-UvVersion $uvCommand.Source
|
|
if (-not (Test-SupportedUvVersion -Version $version -Minimum $MinUvVersion)) {
|
|
throw "Stable uv $MinUvVersion or newer is required; found uv $version after installation."
|
|
}
|
|
Write-Host "Verified uv $version."
|
|
}
|
|
|
|
function Ensure-Uv {
|
|
if ($DryRun) {
|
|
if (Get-ApplicationCommand "uv") {
|
|
Write-Host "+ uv --version"
|
|
Write-Host "A compatible existing uv will be left unchanged; an obsolete one will be replaced by the standalone installer."
|
|
}
|
|
else {
|
|
Write-Host "uv is not installed; the current standalone uv would be installed."
|
|
Invoke-DownloadedPowerShellInstaller -Url $UvInstallUrl -Name "uv"
|
|
Confirm-Uv
|
|
}
|
|
return
|
|
}
|
|
|
|
$uvCommand = Get-ApplicationCommand "uv"
|
|
if ($uvCommand) {
|
|
$version = Get-UvVersion $uvCommand.Source
|
|
if (Test-SupportedUvVersion -Version $version -Minimum $MinUvVersion) {
|
|
Write-Host "uv $version already satisfies >=$MinUvVersion; leaving it unchanged."
|
|
return
|
|
}
|
|
Write-Host "uv $version does not satisfy stable >=$MinUvVersion; installing the current standalone uv."
|
|
}
|
|
else {
|
|
Write-Host "uv is not installed; installing the current standalone uv."
|
|
}
|
|
|
|
Invoke-DownloadedPowerShellInstaller -Url $UvInstallUrl -Name "uv"
|
|
Add-KnownBinDirectories
|
|
Confirm-Uv
|
|
}
|
|
|
|
function Get-PackageSpec {
|
|
$includeNim = $VoiceNim
|
|
$includeLocal = $VoiceLocal
|
|
|
|
if ($VoiceAll) {
|
|
$includeNim = $true
|
|
$includeLocal = $true
|
|
}
|
|
|
|
if ($includeNim -and $includeLocal) {
|
|
return "free-claude-code[voice,voice_local] @ $RepoArchiveUrl"
|
|
}
|
|
if ($includeNim) {
|
|
return "free-claude-code[voice] @ $RepoArchiveUrl"
|
|
}
|
|
if ($includeLocal) {
|
|
return "free-claude-code[voice_local] @ $RepoArchiveUrl"
|
|
}
|
|
return "free-claude-code @ $RepoArchiveUrl"
|
|
}
|
|
|
|
function Install-FreeClaudeCode {
|
|
Assert-NoFccProcessesRunning
|
|
$packageSpec = Get-PackageSpec
|
|
$arguments = @(
|
|
"tool",
|
|
"install",
|
|
"--force",
|
|
"--refresh-package",
|
|
"free-claude-code",
|
|
"--python",
|
|
$PythonVersion
|
|
)
|
|
if (-not [string]::IsNullOrWhiteSpace($TorchBackend)) {
|
|
$arguments += @("--torch-backend", $TorchBackend)
|
|
}
|
|
$arguments += $packageSpec
|
|
|
|
$uvPath = "uv"
|
|
if (-not $DryRun) {
|
|
$uvCommand = Get-ApplicationCommand "uv"
|
|
if (-not $uvCommand) {
|
|
throw "uv is not available for the Free Claude Code installation."
|
|
}
|
|
$uvPath = $uvCommand.Source
|
|
}
|
|
Invoke-NativeCommand -FilePath $uvPath -Arguments $arguments
|
|
}
|
|
|
|
function Configure-AndConfirmFreeClaudeCode {
|
|
if ($DryRun) {
|
|
Write-Host "+ uv tool update-shell"
|
|
Write-Host "+ uv tool dir --bin"
|
|
Write-Host "+ verify fcc-desktop, fcc-server, fcc-claude, fcc-codex, and fcc-pi in the uv tool bin directory"
|
|
Write-Host "+ fcc-server --version"
|
|
Install-FccDesktopShortcuts -DesktopCommand "<uv-tool-bin>\fcc-desktop.exe"
|
|
return
|
|
}
|
|
|
|
$uvCommand = Get-ApplicationCommand "uv"
|
|
if (-not $uvCommand) {
|
|
throw "uv is not available for PATH configuration."
|
|
}
|
|
Invoke-NativeCommand -FilePath $uvCommand.Source -Arguments @("tool", "update-shell")
|
|
$toolBin = Invoke-NativeCapture -FilePath $uvCommand.Source -Arguments @("tool", "dir", "--bin")
|
|
if ([string]::IsNullOrWhiteSpace($toolBin)) {
|
|
throw "uv returned an empty tool bin directory."
|
|
}
|
|
|
|
Add-PathEntry $toolBin
|
|
$toolBinPath = ([IO.Path]::GetFullPath($toolBin)).TrimEnd(
|
|
[IO.Path]::DirectorySeparatorChar,
|
|
[IO.Path]::AltDirectorySeparatorChar
|
|
)
|
|
$installedCommands = @{}
|
|
foreach ($commandName in @("fcc-desktop", "fcc-server", "fcc-claude", "fcc-codex", "fcc-pi")) {
|
|
$command = Get-ApplicationCommand $commandName
|
|
if (-not $command) {
|
|
throw "Free Claude Code installation did not create '$commandName'."
|
|
}
|
|
$commandDirectory = ([IO.Path]::GetFullPath((Split-Path -Parent $command.Source))).TrimEnd(
|
|
[IO.Path]::DirectorySeparatorChar,
|
|
[IO.Path]::AltDirectorySeparatorChar
|
|
)
|
|
if (-not $commandDirectory.Equals($toolBinPath, [StringComparison]::OrdinalIgnoreCase)) {
|
|
throw "'$commandName' resolved outside the uv tool bin directory: $($command.Source)"
|
|
}
|
|
$installedCommands[$commandName] = $command.Source
|
|
}
|
|
|
|
Invoke-NativeCommand -FilePath $installedCommands["fcc-server"] -Arguments @("--version")
|
|
Install-FccDesktopShortcuts -DesktopCommand $installedCommands["fcc-desktop"]
|
|
}
|
|
|
|
function Test-EquivalentPath {
|
|
param(
|
|
[string] $Left,
|
|
[string] $Right
|
|
)
|
|
|
|
if ([string]::IsNullOrWhiteSpace($Left) -or [string]::IsNullOrWhiteSpace($Right)) {
|
|
return $false
|
|
}
|
|
try {
|
|
return [string]::Equals(
|
|
[IO.Path]::GetFullPath($Left),
|
|
[IO.Path]::GetFullPath($Right),
|
|
[StringComparison]::OrdinalIgnoreCase
|
|
)
|
|
}
|
|
catch {
|
|
return $false
|
|
}
|
|
}
|
|
|
|
function Install-FccDesktopShortcuts {
|
|
param([string] $DesktopCommand)
|
|
|
|
$shortcutPaths = @(
|
|
(Join-Path $env:USERPROFILE "Desktop\Free Claude Code.lnk"),
|
|
(Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\Free Claude Code.lnk")
|
|
)
|
|
foreach ($shortcutPath in $shortcutPaths) {
|
|
Write-Host "+ create shortcut $(Format-Argument $shortcutPath) -> $(Format-Argument $DesktopCommand)"
|
|
}
|
|
if ($DryRun) {
|
|
return
|
|
}
|
|
|
|
$shell = New-Object -ComObject WScript.Shell
|
|
foreach ($shortcutPath in $shortcutPaths) {
|
|
if (Test-Path -LiteralPath $shortcutPath) {
|
|
try {
|
|
$existingShortcut = $shell.CreateShortcut($shortcutPath)
|
|
$isFccShortcut = Test-EquivalentPath -Left $existingShortcut.TargetPath -Right $DesktopCommand
|
|
}
|
|
catch {
|
|
$isFccShortcut = $false
|
|
}
|
|
if (-not $isFccShortcut) {
|
|
Write-Host "A shortcut not managed by Free Claude Code already exists at $shortcutPath; leaving it unchanged."
|
|
continue
|
|
}
|
|
}
|
|
$parent = Split-Path -Parent $shortcutPath
|
|
New-Item -ItemType Directory -Force -Path $parent | Out-Null
|
|
$shortcut = $shell.CreateShortcut($shortcutPath)
|
|
$shortcut.TargetPath = $DesktopCommand
|
|
$shortcut.WorkingDirectory = $env:USERPROFILE
|
|
$shortcut.IconLocation = "$DesktopCommand,0"
|
|
$shortcut.Description = "Run Free Claude Code in the background"
|
|
$shortcut.Save()
|
|
}
|
|
}
|
|
|
|
if ($Help) {
|
|
Show-Usage
|
|
return
|
|
}
|
|
|
|
if ($RemainingArgs.Count -gt 0) {
|
|
Show-Usage
|
|
throw "Unknown option: $($RemainingArgs -join ' ')"
|
|
}
|
|
|
|
if ((-not [string]::IsNullOrWhiteSpace($TorchBackend)) -and (-not ($VoiceLocal -or $VoiceAll))) {
|
|
throw "-TorchBackend requires -VoiceLocal or -VoiceAll."
|
|
}
|
|
|
|
Add-KnownBinDirectories
|
|
|
|
Write-Step "Checking for running Free Claude Code processes"
|
|
Assert-NoFccProcessesRunning
|
|
|
|
Write-Step "Ensuring Claude Code is installed"
|
|
Ensure-ClaudeCode
|
|
|
|
Write-Step "Ensuring Codex is installed"
|
|
Ensure-Codex
|
|
|
|
Write-Step "Ensuring Pi is installed"
|
|
Ensure-Pi
|
|
|
|
Write-Step "Ensuring uv $MinUvVersion or newer is installed"
|
|
Ensure-Uv
|
|
|
|
Write-Step "Installing or updating Free Claude Code"
|
|
Install-FreeClaudeCode
|
|
|
|
Write-Step "Configuring PATH and verifying Free Claude Code"
|
|
Configure-AndConfirmFreeClaudeCode
|
|
|
|
Write-Host ""
|
|
if ($DryRun) {
|
|
Write-Host "Dry run complete. No changes were made."
|
|
}
|
|
else {
|
|
Write-Host "Free Claude Code is installed and verified. Open the Free Claude Code desktop shortcut to run it in the background."
|
|
Write-Host "For terminal use, start the proxy with: fcc-server"
|
|
Write-Host "Run Claude Code with: fcc-claude"
|
|
Write-Host "Run Codex with: fcc-codex"
|
|
Write-Host "Run Pi with: fcc-pi"
|
|
}
|