π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(desktop): detect user-local Claude Code installs on lean PATH (#16585)
Arvin Xu0feda39d05c3
diff --git a/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.ts b/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.tsindex b4b99863f75..39dec0ef86b 100644--- a/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.ts+++ b/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.ts@@ -185,6 +185,60 @@ describe('cliAgentBinaries', () => {expect(status.resolvedPathEnv).toBeUndefined();});+ it('falls back to a user-local Claude install when `claude` is not on PATH', async () => {+ const originalPath = process.env.PATH;+ const originalShell = process.env.SHELL;+ process.env.PATH = '/usr/bin:/bin';+ delete process.env.SHELL;++ try {+ callExecFileError(new Error('not found')); // which claude+ callExecFile('2.1.196 (Claude Code)'); // ~/.local/bin/claude --version++ const { claudeCodeBinary } = await import('../cliAgentBinaries');+ const status = await claudeCodeBinary.detect();++ expect(status.available).toBe(true);+ expect(status.path).toBe(path.join(os.homedir(), '.local', 'bin', 'claude'));+ expect(status.version).toBe('2.1.196 (Claude Code)');++ expect(execFileMock).toHaveBeenCalledTimes(2);+ expect(execFileMock.mock.calls[0]![0]).toBe('which');+ expect(execFileMock.mock.calls[1]![0]).toBe(+ path.join(os.homedir(), '.local', 'bin', 'claude'),+ );+ } finally {+ process.env.PATH = originalPath;+ if (originalShell === undefined) delete process.env.SHELL;+ else process.env.SHELL = originalShell;+ }+ });++ it('does not fall back to well-known Claude paths for a custom command', async () => {+ const originalPath = process.env.PATH;+ const originalShell = process.env.SHELL;+ process.env.PATH = '/usr/bin:/bin';+ delete process.env.SHELL;++ try {+ callExecFileError(new Error('not found')); // which claude-beta++ const { detectHeterogeneousCliCommand } = await import('../cliAgentBinaries');+ const status = await detectHeterogeneousCliCommand('claude-code', 'claude-beta');++ expect(status.available).toBe(false);+ // Only the custom command's own `which` runs β the ~/.local/bin/claude+ // fallback must NOT, or a missing `claude-beta` would silently resolve+ // to stock `claude` instead of reporting the configured command missing.+ expect(execFileMock).toHaveBeenCalledTimes(1);+ expect(execFileMock.mock.calls[0]![0]).toBe('which');+ } finally {+ process.env.PATH = originalPath;+ if (originalShell === undefined) delete process.env.SHELL;+ else process.env.SHELL = originalShell;+ }+ });+it('falls back to the Codex.app bundled CLI when `codex` is not on any PATH', async () => {const originalPath = process.env.PATH;const originalShell = process.env.SHELL;diff --git a/apps/desktop/src/main/modules/binaries/cliAgentBinaries.ts b/apps/desktop/src/main/modules/binaries/cliAgentBinaries.tsindex 2770af1f38a..1b6c122b159 100644--- a/apps/desktop/src/main/modules/binaries/cliAgentBinaries.ts+++ b/apps/desktop/src/main/modules/binaries/cliAgentBinaries.ts@@ -214,15 +214,33 @@ const HETEROGENEOUS_CLI_AGENT_OPTIONS = {Pick<ValidatedDetectorOptions, 'validateKeywords'>>;+// The default (bare) command each agent type is shipped to run. The well-known+// fallback locations below hold *this* binary, so they may only be probed when+// the requested command is the default β never for a custom command.+const DEFAULT_COMMAND: Record<HeterogeneousCliAgentType, string> = {+ 'claude-code': 'claude',+ 'codex': 'codex',+};+// Well-known absolute install locations probed when a bare command isn't on-// PATH. The Codex desktop app bundles a fully functional CLI inside Codex.app-// (sharing ~/.codex auth/config) but never symlinks it into PATH, so-// `which codex` misses an otherwise working install.+// PATH. This covers GUI-launched apps with a lean launchd PATH: Claude's+// official installer can put `claude` under ~/.local/bin, while the Codex+// desktop app bundles a functional CLI inside Codex.app without symlinking it.const getWellKnownCommandPaths = (agentType: HeterogeneousCliAgentType): string[] => {- if (platform() !== 'darwin') return [];-switch (agentType) {+ case 'claude-code': {+ if (platform() !== 'darwin' && platform() !== 'linux') return [];++ return [+ path.join(homedir(), '.local', 'bin', 'claude'),+ path.join(homedir(), '.bun', 'bin', 'claude'),+ path.join(homedir(), '.npm-global', 'bin', 'claude'),+ path.join(homedir(), 'Library', 'pnpm', 'claude'),+ ];+ }case 'codex': {+ if (platform() !== 'darwin') return [];+const bundledCli = path.join('Codex.app', 'Contents', 'Resources', 'codex');return [path.join('/Applications', bundledCli),@@ -245,10 +263,12 @@ export const detectHeterogeneousCliCommand = async (const status = await detectValidatedCommand(command, validator);if (status.available) return status;- // A bare command missing from PATH may still live at a well-known install- // location (e.g. the Codex desktop app's bundled CLI). Don't second-guess- // an explicit user-configured path.- if (!command.trim().includes(path.sep)) {+ // The default command missing from PATH may still live at a well-known install+ // location (e.g. the Codex desktop app's bundled CLI). Only probe those for the+ // default command: the well-known paths hold the *default* binary, so applying+ // them to a custom command (e.g. `claude-beta`) would silently resolve it to+ // stock `claude` instead of reporting the configured command as missing.+ if (command.trim() === DEFAULT_COMMAND[agentType]) {for (const candidate of getWellKnownCommandPaths(agentType)) {const fallbackStatus = await detectValidatedCommand(candidate, validator);if (fallbackStatus.available) return fallbackStatus;@@ -288,14 +308,17 @@ const defineValidatedBinary = (/*** Claude Code CLI* @see https://docs.claude.com/en/docs/claude-code+ *+ * Goes through `detectHeterogeneousCliCommand` so Finder/launchd-started+ * desktop builds can still discover user-local installs such as+ * `~/.local/bin/claude` when that directory is absent from the inherited PATH.*/-export const claudeCodeBinary: BinarySpec = defineValidatedBinary({- candidates: ['claude'],+export const claudeCodeBinary: BinarySpec = {description: 'Claude Code - Anthropic official agentic coding CLI',+ detect: () => detectHeterogeneousCliCommand('claude-code', 'claude'),name: 'claude',priority: 1,- validateKeywords: ['claude code'],-});+};/*** OpenAI Codex CLI