singularity-forge/src/claude-cli-check.ts
Jeremy ea456d4cdb fix(providers): route Anthropic subscription users through Claude Code CLI (#3772)
Anthropic now blocks third-party apps from using Pro/Max subscription
quotas via direct API calls. This change makes the claude-code provider
(which delegates to the local claude CLI binary) the default path for
Anthropic subscription users — TOS-compliant because requests flow
through Anthropic's own infrastructure.

Changes:
- Enhanced readiness check to verify CLI auth status (not just binary)
- Startup migration: auto-switch anthropic → claude-code when CLI ready
- Error recovery: auto-switch on third-party 400 block error
- Onboarding: removed Anthropic from OAuth, added Claude CLI option
- Added claude-code to flat-rate providers (no dynamic routing benefit)

Closes #3772
2026-04-08 07:20:20 -05:00

37 lines
1 KiB
TypeScript

// GSD2 — Claude CLI binary detection for onboarding
// Lightweight check used at onboarding time (before extensions load).
// The full readiness check with caching lives in the claude-code-cli extension.
import { execFileSync } from 'node:child_process'
/**
* Check if the `claude` binary is installed (regardless of auth state).
*/
export function isClaudeBinaryInstalled(): boolean {
try {
execFileSync('claude', ['--version'], { timeout: 5_000, stdio: 'pipe' })
return true
} catch {
return false
}
}
/**
* Check if the `claude` CLI is installed AND authenticated.
*/
export function isClaudeCliReady(): boolean {
try {
execFileSync('claude', ['--version'], { timeout: 5_000, stdio: 'pipe' })
} catch {
return false
}
try {
const output = execFileSync('claude', ['auth', 'status'], { timeout: 5_000, stdio: 'pipe' })
.toString()
.toLowerCase()
return !(/not logged in|no credentials|unauthenticated|not authenticated/i.test(output))
} catch {
return false
}
}