Get-ClaudeExecutable.ps1

function Get-ClaudeExecutable {
    <#
    .SYNOPSIS
        Resolves the claude executable from PATH.
    .DESCRIPTION
        Returns the first claude executable found on PATH, falling back to known
        install locations when PATH is stale.
    #>

    [CmdletBinding()]
    param()

    $exe = Get-Command claude -CommandType Application, ExternalScript -ErrorAction SilentlyContinue |
        Select-Object -First 1
    if ($exe) {
        Write-Verbose "Using claude from PATH: $($exe.Source)"
        return $exe
    }

    # PATH may be stale — probe known locations.
    $candidates = @(
        (Join-Path $HOME '.local/bin/claude'),
        (Join-Path $HOME '.claude/local/claude')
    )
    foreach ($c in $candidates) {
        if (Test-Path $c) {
            $sep = [System.IO.Path]::PathSeparator
            $binDir = Split-Path -Parent $c
            if (($env:PATH -split [regex]::Escape($sep)) -notcontains $binDir) {
                Write-Verbose "Adding $binDir to PATH for current session"
                $env:PATH = "$binDir$sep$env:PATH"
            }
            return (Get-Item $c)
        }
    }

    return $null
}