"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveClaude = resolveClaude; exports._resetResolveClaudeCache = _resetResolveClaudeCache; const child_process_1 = require("child_process"); const util_1 = require("util"); const execFileAsync = (0, util_1.promisify)(child_process_1.execFile); /** Cached result after first successful resolution. */ let cachedPath = null; /** * Resolves the Claude CLI executable name or path. * * Resolution order: * 1. `CLAUDE_PATH` environment variable (absolute path or command name) * 2. PATH lookup via `where` (Windows) or `which` (Unix) * * The result is cached in-memory after the first successful call so * subsequent invocations are synchronous-cheap. * * On Windows, `claude` is installed as `claude.cmd`. `cross-spawn` handles * `.cmd` wrappers transparently, so returning the bare name `"claude"` is * correct — cross-spawn will find and invoke `claude.cmd` automatically. * * @throws {Error} with a clear installation hint if claude cannot be found. */ async function resolveClaude() { if (cachedPath !== null) { return cachedPath; } // 1. Explicit override via environment variable const envPath = process.env.CLAUDE_PATH; if (envPath && envPath.trim() !== "") { cachedPath = envPath.trim(); return cachedPath; } // 2. PATH lookup const isWindows = process.platform === "win32"; const lookupCmd = isWindows ? "where" : "which"; try { const { stdout } = await execFileAsync(lookupCmd, ["claude"], { timeout: 5_000, }); const firstLine = stdout.trim().split(/\r?\n/)[0].trim(); if (firstLine) { cachedPath = firstLine; return cachedPath; } } catch { // where/which returned non-zero or was not found — fall through to error } throw new Error(`Claude Code CLI not found. Install it with:\n` + ` npm install -g @anthropic-ai/claude-code\n` + `Or set CLAUDE_PATH in your .env file to the full path of the claude executable.`); } /** * Resets the in-memory cache. Intended for use in tests only. */ function _resetResolveClaudeCache() { cachedPath = null; } //# sourceMappingURL=resolve-claude.js.map