From a9eab51277ba8cc37788e64124d4706cebac94db Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:52:37 -0500 Subject: [PATCH 1/8] fix(install): find package managers and ccstatusline on PATH without which The TUI asked `which` whether npm, npx, bun and bunx are installed and where ccstatusline resolves. `which` is a separate package that minimal Linux images (Fedora, RHEL/UBI) and a base Arch install leave out. Without it every lookup failed the way a missing tool does: the Install screen marked all four package managers "not installed" and disabled every option, update actions were disabled too, and Manage Installation said ccstatusline is not resolvable on PATH. When `which` can't be started, the lookup now searches PATH itself and lists what `which -a` would: each file the user can run, in PATH order. `command -v` could answer "is npm installed" but can't list every match, which the multiple-binaries warning needs, so both checks share this one search. The availability check now goes through the same lookup as the ccstatusline resolution, so the two can't disagree. Where `which` exists nothing changes, and Windows still uses `where`. --- src/utils/__tests__/claude-settings.test.ts | 29 +++++++++ src/utils/__tests__/executable-path.test.ts | 62 ++++++++++++++++++- .../global-command-resolution.test.ts | 36 ++++++++++- src/utils/claude-settings.ts | 8 ++- src/utils/executable-path.ts | 50 +++++++++++++++ src/utils/global-command-resolution.ts | 8 ++- 6 files changed, 187 insertions(+), 6 deletions(-) diff --git a/src/utils/__tests__/claude-settings.test.ts b/src/utils/__tests__/claude-settings.test.ts index dc70cea2f..67fa932d8 100644 --- a/src/utils/__tests__/claude-settings.test.ts +++ b/src/utils/__tests__/claude-settings.test.ts @@ -21,6 +21,7 @@ import { getClaudeJsonPath, getClaudeSettingsPath, getExistingStatusLine, + getPackageCommandAvailability, getRefreshInterval, getRemoteControlStatus, getSandboxConfig, @@ -765,6 +766,34 @@ describe('isClaudeCodeVersionAtLeast', () => { }); }); +describe('getPackageCommandAvailability', () => { + const originalPath = process.env.PATH; + + afterEach(() => { + process.env.PATH = originalPath; + }); + + // Minimal Linux images (Fedora, UBI, Arch without the which package) have no `which` + it.skipIf(process.platform === 'win32')('finds package managers on PATH when there is no which command', () => { + const binDir = path.join(testClaudeConfigDir, 'bin'); + fs.mkdirSync(path.join(binDir, 'bunx'), { recursive: true }); + fs.writeFileSync(path.join(binDir, 'npm'), '#!/bin/sh\n', { mode: 0o755 }); + fs.writeFileSync(path.join(binDir, 'npx'), '#!/bin/sh\n', { mode: 0o755 }); + fs.writeFileSync(path.join(binDir, 'bun'), '#!/bin/sh\n', { mode: 0o644 }); + process.env.PATH = binDir; + vi.spyOn(childProcess, 'execFileSync').mockImplementation((command) => { + throw Object.assign(new Error(`spawnSync ${command} ENOENT`), { code: 'ENOENT' }); + }); + + expect(getPackageCommandAvailability()).toEqual({ + npm: true, + npx: true, + bun: false, + bunx: false + }); + }); +}); + describe('getVoiceConfig', () => { let testProjectDir = ''; diff --git a/src/utils/__tests__/executable-path.test.ts b/src/utils/__tests__/executable-path.test.ts index dfe18e63d..118e619b4 100644 --- a/src/utils/__tests__/executable-path.test.ts +++ b/src/utils/__tests__/executable-path.test.ts @@ -1,10 +1,16 @@ +import * as fs from 'node:fs'; +import * as os from 'node:os'; +import * as path from 'node:path'; import { describe, expect, it } from 'vitest'; -import { resolveExecutable } from '../executable-path'; +import { + findAllOnPosixPath, + resolveExecutable +} from '../executable-path'; function windows(files: string[], env: NodeJS.ProcessEnv = { Path: 'C:\\Windows\\System32;C:\\Program Files\\Git\\cmd' }) { const present = new Set(files.map(file => file.toLowerCase())); @@ -59,3 +65,57 @@ describe('resolveExecutable', () => { expect(resolveExecutable('C:\\tools\\git.exe', windows([]))).toBe('C:\\tools\\git.exe'); }); }); + +function posix(executables: string[], pathValue: string) { + const present = new Set(executables); + return { + env: { PATH: pathValue }, + isExecutableFile: (candidate: string) => present.has(candidate) + }; +} + +describe('findAllOnPosixPath', () => { + it('lists every match in PATH order, as which -a does', () => { + const search = posix( + ['/usr/local/bin/ccstatusline', '/home/alice/.bun/bin/ccstatusline'], + '/home/alice/.bun/bin:/usr/bin:/usr/local/bin' + ); + + expect(findAllOnPosixPath('ccstatusline', search)).toEqual([ + '/home/alice/.bun/bin/ccstatusline', + '/usr/local/bin/ccstatusline' + ]); + }); + + it('lists a directory that PATH repeats once', () => { + expect(findAllOnPosixPath('npm', posix(['/usr/bin/npm'], '/usr/bin:/bin:/usr/bin'))).toEqual(['/usr/bin/npm']); + }); + + it('skips empty and relative PATH entries', () => { + expect(findAllOnPosixPath('npm', posix(['./npm', 'node_modules/.bin/npm', '/bin/npm'], '/usr/bin::node_modules/.bin:/bin'))).toEqual(['/bin/npm']); + }); + + it('finds nothing without a PATH', () => { + expect(findAllOnPosixPath('npm', { env: {}, isExecutableFile: () => true })).toEqual([]); + }); + + it.skipIf(process.platform === 'win32')('only lists files the user can run', () => { + const binDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-path-scan-')); + const originalPath = process.env.PATH; + try { + fs.writeFileSync(path.join(binDir, 'npm'), '#!/bin/sh\n', { mode: 0o755 }); + fs.writeFileSync(path.join(binDir, 'bun'), '#!/bin/sh\n', { mode: 0o644 }); + fs.mkdirSync(path.join(binDir, 'bunx')); + fs.symlinkSync('npm', path.join(binDir, 'npx')); + process.env.PATH = binDir; + + expect(findAllOnPosixPath('npm')).toEqual([path.join(binDir, 'npm')]); + expect(findAllOnPosixPath('npx')).toEqual([path.join(binDir, 'npx')]); + expect(findAllOnPosixPath('bun')).toEqual([]); + expect(findAllOnPosixPath('bunx')).toEqual([]); + } finally { + process.env.PATH = originalPath; + fs.rmSync(binDir, { recursive: true, force: true }); + } + }); +}); diff --git a/src/utils/__tests__/global-command-resolution.test.ts b/src/utils/__tests__/global-command-resolution.test.ts index e81198813..4abe6ad8f 100644 --- a/src/utils/__tests__/global-command-resolution.test.ts +++ b/src/utils/__tests__/global-command-resolution.test.ts @@ -1,4 +1,7 @@ import * as childProcess from 'node:child_process'; +import * as fs from 'node:fs'; +import * as os from 'node:os'; +import * as path from 'node:path'; import { afterEach, describe, @@ -16,7 +19,7 @@ import { getPackageManagerShellOptions } from '../package-manager-executable'; -function mockExecFileSync(responses: Record) { +function mockExecFileSync(responses: Record) { const spy = vi.spyOn(childProcess, 'execFileSync').mockImplementation((command, args) => { const key = `${command} ${(args as string[]).join(' ')}`; const response = responses[key]; @@ -25,6 +28,10 @@ function mockExecFileSync(responses: Record) { throw new Error(`Unexpected command: ${key}`); } + if (response instanceof Error) { + throw response; + } + return response; }); @@ -37,6 +44,11 @@ function mockExecFileSync(responses: Record) { return spy; } +// What running a program that isn't installed throws +function missingProgramError(command: string): Error { + return Object.assign(new Error(`spawnSync ${command} ENOENT`), { code: 'ENOENT' }); +} + describe('global command resolution', () => { afterEach(() => { vi.restoreAllMocks(); @@ -79,6 +91,28 @@ describe('global command resolution', () => { ]); }); + // Minimal Linux images (Fedora, UBI, Arch without the which package) have no `which` + it.skipIf(process.platform === 'win32')('looks through PATH itself when there is no which command', () => { + const binDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-path-')); + const originalPath = process.env.PATH; + try { + fs.writeFileSync(path.join(binDir, 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + process.env.PATH = `${path.join(binDir, 'missing')}:${binDir}`; + mockExecFileSync({ + 'which -a ccstatusline': missingProgramError('which'), + 'bun pm bin -g': `${binDir}\n` + }); + + const resolution = inspectGlobalCommandResolution('bun', { platform: 'linux' }); + + expect(resolution.resolvedPaths).toEqual([path.join(binDir, 'ccstatusline')]); + expect(resolution.warning).toBeNull(); + } finally { + process.env.PATH = originalPath; + fs.rmSync(binDir, { recursive: true, force: true }); + } + }); + it('silences child stderr on best-effort probes so failures cannot leak to the terminal', () => { const execFileSyncSpy = mockExecFileSync({ 'which -a ccstatusline': '/home/alice/.bun/bin/ccstatusline\n', diff --git a/src/utils/claude-settings.ts b/src/utils/claude-settings.ts index 5e9fb79e6..502282ecd 100644 --- a/src/utils/claude-settings.ts +++ b/src/utils/claude-settings.ts @@ -17,6 +17,7 @@ import { isCustomConfigPath, saveInstallationMetadata } from './config'; +import { getCommandResolutionPaths } from './global-command-resolution'; // Re-export for backward compatibility export type { ClaudeSettings }; @@ -249,9 +250,12 @@ export async function isInstalled(): Promise { } function isExecutableAvailable(executable: string): boolean { + if (process.platform !== 'win32') { + return getCommandResolutionPaths(executable).length > 0; + } + try { - const command = process.platform === 'win32' ? `where ${executable}` : `which ${executable}`; - execSync(command, { stdio: 'ignore', windowsHide: true }); + execSync(`where ${executable}`, { stdio: 'ignore', windowsHide: true }); return true; } catch { return false; diff --git a/src/utils/executable-path.ts b/src/utils/executable-path.ts index c5d0c6491..7533c1537 100644 --- a/src/utils/executable-path.ts +++ b/src/utils/executable-path.ts @@ -85,3 +85,53 @@ export function resolveExecutable(name: string, lookup: ExecutableLookup = DEFAU } return resolved; } + +// Outside Windows, the shell searches PATH and `which` lists what it finds. +// Minimal Linux images (Fedora, UBI, Arch without the which package) have no +// `which`, so lookups that ask it fall back to searching PATH here. + +export interface PosixPathSearch { + env: NodeJS.ProcessEnv; + isExecutableFile: (candidate: string) => boolean; +} + +function isExecutableFile(candidate: string): boolean { + try { + fs.accessSync(candidate, fs.constants.X_OK); + return fs.statSync(candidate).isFile(); + } catch { + return false; + } +} + +const DEFAULT_POSIX_SEARCH: PosixPathSearch = { + env: process.env, + isExecutableFile +}; + +/** + * Every file named `name` on PATH that the user can run, in PATH order: what + * `which -a` lists. + */ +export function findAllOnPosixPath(name: string, search: PosixPathSearch = DEFAULT_POSIX_SEARCH): string[] { + const pathValue = search.env.PATH; + if (!pathValue) { + return []; + } + + const matches = new Set(); + for (const entry of pathValue.split(':')) { + // An empty or relative entry names a directory relative to wherever the + // TUI runs, which says nothing about what Claude Code runs; like the + // Windows lookup above, only absolute entries count + if (!path.posix.isAbsolute(entry)) { + continue; + } + const candidate = `${entry}/${name}`; + if (search.isExecutableFile(candidate)) { + matches.add(candidate); + } + } + + return Array.from(matches); +} diff --git a/src/utils/global-command-resolution.ts b/src/utils/global-command-resolution.ts index c90b6db5f..96926398c 100644 --- a/src/utils/global-command-resolution.ts +++ b/src/utils/global-command-resolution.ts @@ -1,6 +1,7 @@ import { execFileSync } from 'node:child_process'; import * as path from 'node:path'; +import { findAllOnPosixPath } from './executable-path'; import { getPackageManagerExecutable, getPackageManagerShellOptions @@ -66,8 +67,11 @@ export function getCommandResolutionPaths( }); return splitCommandOutput(output); - } catch { - return []; + } catch (error) { + // No `which` to ask: list what it would from PATH + return platform !== 'win32' && (error as NodeJS.ErrnoException).code === 'ENOENT' + ? findAllOnPosixPath(command) + : []; } } From c92c8d3ce307a37f287e817c1ffe231775c85ed7 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:57:32 -0500 Subject: [PATCH 2/8] fix(install): count a PATH directory reached through a symlink once The "Multiple ccstatusline binaries are on PATH" warning counts the directories `which -a` lists ccstatusline in, comparing them as text. On merged-/usr Linux (Ubuntu 22.04+, Debian 12) /bin is a symlink to usr/bin and the default PATH lists both, so with npm's global prefix at /usr one installed binary shows up as /usr/bin/ccstatusline and /bin/ccstatusline. Manage Installation and the install and update notices then warned about a second install that doesn't exist. Both duplicate checks now compare each directory with its symlinks resolved, and fall back to the path as listed when it can't be resolved. The warning still shows the paths as PATH spells them. --- .../global-command-resolution.test.ts | 21 ++++++++++ .../__tests__/global-package-manager.test.ts | 42 +++++++++++++++++++ src/utils/global-command-resolution.ts | 14 ++++++- src/utils/global-package-manager.ts | 3 +- 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/utils/__tests__/global-command-resolution.test.ts b/src/utils/__tests__/global-command-resolution.test.ts index 4abe6ad8f..ef2d0e524 100644 --- a/src/utils/__tests__/global-command-resolution.test.ts +++ b/src/utils/__tests__/global-command-resolution.test.ts @@ -152,6 +152,27 @@ describe('global command resolution', () => { expect(resolution.warning).toContain('/usr/local/bin/ccstatusline'); }); + // Merged /usr (Ubuntu 22.04+, Debian 12): /bin links to usr/bin and PATH lists both + it.skipIf(process.platform === 'win32')('counts a PATH directory reached through a symlink once', () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-merged-usr-')); + try { + fs.mkdirSync(path.join(root, 'usr', 'bin'), { recursive: true }); + fs.writeFileSync(path.join(root, 'usr', 'bin', 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + fs.symlinkSync('usr/bin', path.join(root, 'bin')); + mockExecFileSync({ + 'which -a ccstatusline': `${root}/usr/bin/ccstatusline\n${root}/bin/ccstatusline\n`, + 'npm prefix -g': `${root}/usr\n` + }); + + const resolution = inspectGlobalCommandResolution('npm', { platform: 'linux' }); + + expect(resolution.resolvedPaths).toEqual([`${root}/usr/bin/ccstatusline`, `${root}/bin/ccstatusline`]); + expect(resolution.warning).toBeNull(); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it('ignores transient bunx status line shims when resolving global commands', () => { mockExecFileSync({ 'which -a ccstatusline': '/var/folders/demo/T/bunx-501-ccstatusline@latest/node_modules/.bin/ccstatusline\n/Users/alice/.bun/bin/ccstatusline\n', diff --git a/src/utils/__tests__/global-package-manager.test.ts b/src/utils/__tests__/global-package-manager.test.ts index 492e27502..0871f089e 100644 --- a/src/utils/__tests__/global-package-manager.test.ts +++ b/src/utils/__tests__/global-package-manager.test.ts @@ -1,5 +1,7 @@ import * as childProcess from 'node:child_process'; import * as fs from 'node:fs'; +import * as os from 'node:os'; +import * as path from 'node:path'; import { afterEach, describe, @@ -103,6 +105,46 @@ describe('global package manager inspection', () => { }); }); + // Merged /usr (Ubuntu 22.04+, Debian 12): /bin links to usr/bin and PATH lists both + it.skipIf(process.platform === 'win32')('counts a PATH directory reached through a symlink once', () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-merged-usr-')); + try { + const packageDir = path.join(root, 'usr', 'lib', 'node_modules', 'ccstatusline'); + fs.mkdirSync(path.join(root, 'usr', 'bin'), { recursive: true }); + fs.mkdirSync(packageDir, { recursive: true }); + fs.writeFileSync(path.join(root, 'usr', 'bin', 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + fs.writeFileSync(path.join(packageDir, 'package.json'), '{"version":"2.2.13"}'); + fs.symlinkSync('usr/bin', path.join(root, 'bin')); + mockExecFileSync({ + 'which -a ccstatusline': `${root}/usr/bin/ccstatusline\n${root}/bin/ccstatusline\n`, + 'npm prefix -g': `${root}/usr\n`, + 'npm root -g': `${root}/usr/lib/node_modules\n` + }); + + const activeCommand = inspectActiveGlobalCommand({ + commandAvailability: { + npm: true, + bun: false + }, + platform: 'linux' + }); + + expect(activeCommand).toEqual({ + packageManager: 'npm', + resolvedPath: `${root}/usr/bin/ccstatusline`, + resolvedPaths: [ + `${root}/usr/bin/ccstatusline`, + `${root}/bin/ccstatusline` + ], + binDir: `${root}/usr/bin`, + version: '2.2.13', + warning: null + }); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it('ignores transient bunx status line shims when identifying the active global command', () => { mockExecFileSync({ 'which -a ccstatusline': '/var/folders/demo/T/bunx-501-ccstatusline@latest/node_modules/.bin/ccstatusline\n/Users/alice/.bun/bin/ccstatusline\n', diff --git a/src/utils/global-command-resolution.ts b/src/utils/global-command-resolution.ts index 96926398c..e34c6761a 100644 --- a/src/utils/global-command-resolution.ts +++ b/src/utils/global-command-resolution.ts @@ -1,4 +1,5 @@ import { execFileSync } from 'node:child_process'; +import * as fs from 'node:fs'; import * as path from 'node:path'; import { findAllOnPosixPath } from './executable-path'; @@ -167,13 +168,24 @@ function getDirectoryName(filePath: string): string { : normalized.slice(0, lastSlashIndex); } +// A directory with symlinks resolved, so two spellings of one, such as /bin and +// /usr/bin where /bin links to usr/bin (merged /usr), count as one install +// location. The path as given when it can't be resolved. +export function getRealDirectory(dir: string): string { + try { + return fs.realpathSync(dir); + } catch { + return dir; + } +} + function getUniqueResolvedDirs(resolvedPaths: string[]): string[] { const seen = new Set(); const dirs: string[] = []; for (const resolvedPath of resolvedPaths) { const dir = getDirectoryName(resolvedPath); - const comparableDir = normalizePathForComparison(dir); + const comparableDir = normalizePathForComparison(getRealDirectory(dir)); if (seen.has(comparableDir)) { continue; } diff --git a/src/utils/global-package-manager.ts b/src/utils/global-package-manager.ts index 167859629..fcb580b69 100644 --- a/src/utils/global-package-manager.ts +++ b/src/utils/global-package-manager.ts @@ -9,6 +9,7 @@ import { getCommandResolutionPaths, getExpectedGlobalBinDir, getPersistentCommandResolutionPaths, + getRealDirectory, isPathInsideDir, type GlobalPackageManager } from './global-command-resolution'; @@ -141,7 +142,7 @@ function getUniqueResolvedDirs(resolvedPaths: string[]): string[] { for (const resolvedPath of resolvedPaths) { const dir = getDirectoryName(resolvedPath); - const comparableDir = getComparablePath(dir); + const comparableDir = getComparablePath(getRealDirectory(dir)); if (seen.has(comparableDir)) { continue; } From 36bffc43565a95a7a7a24ee928c405483e3e22b4 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 01:44:18 -0500 Subject: [PATCH 3/8] fix(install): read PATH from process.env when the PATH search runs The PATH search used when there is no `which` kept the process.env object that existed when its module loaded. Code that replaces process.env with a new object afterwards (a test restoring a saved environment does) left the search reading the old object, so a PATH set on the new one was never seen. The default search now reads process.env each time it runs. --- src/utils/__tests__/executable-path.test.ts | 15 +++++++++++++++ src/utils/executable-path.ts | 10 +++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/utils/__tests__/executable-path.test.ts b/src/utils/__tests__/executable-path.test.ts index 118e619b4..27b2b1174 100644 --- a/src/utils/__tests__/executable-path.test.ts +++ b/src/utils/__tests__/executable-path.test.ts @@ -99,6 +99,21 @@ describe('findAllOnPosixPath', () => { expect(findAllOnPosixPath('npm', { env: {}, isExecutableFile: () => true })).toEqual([]); }); + // A test or a caller may swap in a new env object; the lookup must see it + it.skipIf(process.platform === 'win32')('reads PATH from process.env as it is when called', () => { + const binDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-path-env-')); + const originalEnv = process.env; + try { + fs.writeFileSync(path.join(binDir, 'npm'), '#!/bin/sh\n', { mode: 0o755 }); + process.env = { ...originalEnv, PATH: binDir }; + + expect(findAllOnPosixPath('npm')).toEqual([path.join(binDir, 'npm')]); + } finally { + process.env = originalEnv; + fs.rmSync(binDir, { recursive: true, force: true }); + } + }); + it.skipIf(process.platform === 'win32')('only lists files the user can run', () => { const binDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-path-scan-')); const originalPath = process.env.PATH; diff --git a/src/utils/executable-path.ts b/src/utils/executable-path.ts index 7533c1537..c45eb6b96 100644 --- a/src/utils/executable-path.ts +++ b/src/utils/executable-path.ts @@ -104,16 +104,12 @@ function isExecutableFile(candidate: string): boolean { } } -const DEFAULT_POSIX_SEARCH: PosixPathSearch = { - env: process.env, - isExecutableFile -}; - /** * Every file named `name` on PATH that the user can run, in PATH order: what - * `which -a` lists. + * `which -a` lists. The default search reads process.env when called, so an env + * object swapped in after this module loaded is still seen. */ -export function findAllOnPosixPath(name: string, search: PosixPathSearch = DEFAULT_POSIX_SEARCH): string[] { +export function findAllOnPosixPath(name: string, search: PosixPathSearch = { env: process.env, isExecutableFile }): string[] { const pathValue = search.env.PATH; if (!pathValue) { return []; From a7f5ea04c1765b970c9035c333748b5c17b30881 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 06:36:29 -0500 Subject: [PATCH 4/8] fix(install): list each other install once in the multiple-binaries warning The warning counts installs by directory, with symlinks resolved, but built its "Other matches" list from every path `which -a` printed after the first. With a real second install on a merged-/usr system, where /bin links to usr/bin, PATH order gives /usr/bin/ccstatusline, /bin/ccstatusline and then the other one, so the list named /bin/ccstatusline as another binary although it is the first match reached a second way. The list now takes the first path listed in each directory and leaves out the first match's directory, so each other install appears once, spelled as PATH lists it. --- .../global-command-resolution.test.ts | 21 ++++++++++ .../__tests__/global-package-manager.test.ts | 42 +++++++++++++++++++ src/utils/global-command-resolution.ts | 19 +++++---- src/utils/global-package-manager.ts | 19 +++++---- 4 files changed, 83 insertions(+), 18 deletions(-) diff --git a/src/utils/__tests__/global-command-resolution.test.ts b/src/utils/__tests__/global-command-resolution.test.ts index ef2d0e524..23a6312e0 100644 --- a/src/utils/__tests__/global-command-resolution.test.ts +++ b/src/utils/__tests__/global-command-resolution.test.ts @@ -173,6 +173,27 @@ describe('global command resolution', () => { } }); + it.skipIf(process.platform === 'win32')('lists another install once and leaves out other spellings of the first match', () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-merged-usr-')); + try { + fs.mkdirSync(path.join(root, 'usr', 'bin'), { recursive: true }); + fs.mkdirSync(path.join(root, '.bun', 'bin'), { recursive: true }); + fs.writeFileSync(path.join(root, 'usr', 'bin', 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + fs.writeFileSync(path.join(root, '.bun', 'bin', 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + fs.symlinkSync('usr/bin', path.join(root, 'bin')); + mockExecFileSync({ + 'which -a ccstatusline': `${root}/usr/bin/ccstatusline\n${root}/bin/ccstatusline\n${root}/.bun/bin/ccstatusline\n`, + 'npm prefix -g': `${root}/usr\n` + }); + + const resolution = inspectGlobalCommandResolution('npm', { platform: 'linux' }); + + expect(resolution.warning).toBe(`⚠ Multiple ccstatusline binaries are on PATH. Claude Code will run the first match: ${root}/usr/bin/ccstatusline.\nOther matches: ${root}/.bun/bin/ccstatusline`); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it('ignores transient bunx status line shims when resolving global commands', () => { mockExecFileSync({ 'which -a ccstatusline': '/var/folders/demo/T/bunx-501-ccstatusline@latest/node_modules/.bin/ccstatusline\n/Users/alice/.bun/bin/ccstatusline\n', diff --git a/src/utils/__tests__/global-package-manager.test.ts b/src/utils/__tests__/global-package-manager.test.ts index 0871f089e..09971653c 100644 --- a/src/utils/__tests__/global-package-manager.test.ts +++ b/src/utils/__tests__/global-package-manager.test.ts @@ -145,6 +145,48 @@ describe('global package manager inspection', () => { } }); + it.skipIf(process.platform === 'win32')('lists another install once and leaves out other spellings of the active one', () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-merged-usr-')); + try { + const packageDir = path.join(root, 'usr', 'lib', 'node_modules', 'ccstatusline'); + fs.mkdirSync(path.join(root, 'usr', 'bin'), { recursive: true }); + fs.mkdirSync(path.join(root, '.bun', 'bin'), { recursive: true }); + fs.mkdirSync(packageDir, { recursive: true }); + fs.writeFileSync(path.join(root, 'usr', 'bin', 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + fs.writeFileSync(path.join(root, '.bun', 'bin', 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + fs.writeFileSync(path.join(packageDir, 'package.json'), '{"version":"2.2.13"}'); + fs.symlinkSync('usr/bin', path.join(root, 'bin')); + mockExecFileSync({ + 'which -a ccstatusline': `${root}/usr/bin/ccstatusline\n${root}/bin/ccstatusline\n${root}/.bun/bin/ccstatusline\n`, + 'npm prefix -g': `${root}/usr\n`, + 'npm root -g': `${root}/usr/lib/node_modules\n` + }); + + const activeCommand = inspectActiveGlobalCommand({ + commandAvailability: { + npm: true, + bun: false + }, + platform: 'linux' + }); + + expect(activeCommand).toEqual({ + packageManager: 'npm', + resolvedPath: `${root}/usr/bin/ccstatusline`, + resolvedPaths: [ + `${root}/usr/bin/ccstatusline`, + `${root}/bin/ccstatusline`, + `${root}/.bun/bin/ccstatusline` + ], + binDir: `${root}/usr/bin`, + version: '2.2.13', + warning: `⚠ Multiple ccstatusline binaries are on PATH. Claude Code will run the first match: ${root}/usr/bin/ccstatusline.\nOther matches: ${root}/.bun/bin/ccstatusline` + }); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it('ignores transient bunx status line shims when identifying the active global command', () => { mockExecFileSync({ 'which -a ccstatusline': '/var/folders/demo/T/bunx-501-ccstatusline@latest/node_modules/.bin/ccstatusline\n/Users/alice/.bun/bin/ccstatusline\n', diff --git a/src/utils/global-command-resolution.ts b/src/utils/global-command-resolution.ts index e34c6761a..44b994685 100644 --- a/src/utils/global-command-resolution.ts +++ b/src/utils/global-command-resolution.ts @@ -179,22 +179,23 @@ export function getRealDirectory(dir: string): string { } } -function getUniqueResolvedDirs(resolvedPaths: string[]): string[] { +// The first listed path in each directory, comparing directories with symlinks +// resolved: one path per install, starting with the first match +function getOnePathPerDirectory(resolvedPaths: string[]): string[] { const seen = new Set(); - const dirs: string[] = []; + const paths: string[] = []; for (const resolvedPath of resolvedPaths) { - const dir = getDirectoryName(resolvedPath); - const comparableDir = normalizePathForComparison(getRealDirectory(dir)); + const comparableDir = normalizePathForComparison(getRealDirectory(getDirectoryName(resolvedPath))); if (seen.has(comparableDir)) { continue; } seen.add(comparableDir); - dirs.push(dir); + paths.push(resolvedPath); } - return dirs; + return paths; } export function isPathInsideDir(filePath: string, dir: string): boolean { @@ -222,9 +223,9 @@ function getResolutionWarning( return '⚠ ccstatusline is not currently resolvable on PATH. Claude Code runs ccstatusline, so restart your shell or update PATH if it cannot launch.'; } - const resolvedDirs = getUniqueResolvedDirs(resolvedPaths); - if (resolvedDirs.length > 1) { - return `⚠ Multiple ccstatusline binaries are on PATH. Claude Code will run the first match: ${firstResolvedPath}.\nOther matches: ${formatPathList(resolvedPaths.slice(1))}`; + const installPaths = getOnePathPerDirectory(resolvedPaths); + if (installPaths.length > 1) { + return `⚠ Multiple ccstatusline binaries are on PATH. Claude Code will run the first match: ${firstResolvedPath}.\nOther matches: ${formatPathList(installPaths.slice(1))}`; } if (expectedBinDir && !isPathInsideDir(firstResolvedPath, expectedBinDir)) { diff --git a/src/utils/global-package-manager.ts b/src/utils/global-package-manager.ts index fcb580b69..734ee78de 100644 --- a/src/utils/global-package-manager.ts +++ b/src/utils/global-package-manager.ts @@ -136,22 +136,23 @@ function getComparablePath(filePath: string): string { return filePath.replace(/\\/g, '/').toLowerCase().replace(/\/+$/, ''); } -function getUniqueResolvedDirs(resolvedPaths: string[]): string[] { +// The first listed path in each directory, comparing directories with symlinks +// resolved: one path per install, starting with the active one +function getOnePathPerDirectory(resolvedPaths: string[]): string[] { const seen = new Set(); - const dirs: string[] = []; + const paths: string[] = []; for (const resolvedPath of resolvedPaths) { - const dir = getDirectoryName(resolvedPath); - const comparableDir = getComparablePath(getRealDirectory(dir)); + const comparableDir = getComparablePath(getRealDirectory(getDirectoryName(resolvedPath))); if (seen.has(comparableDir)) { continue; } seen.add(comparableDir); - dirs.push(dir); + paths.push(resolvedPath); } - return dirs; + return paths; } function formatPathList(paths: string[]): string { @@ -303,9 +304,9 @@ function getActiveResolutionWarning( return '⚠ ccstatusline is not currently resolvable on PATH. Claude Code runs ccstatusline, so restart your shell or update PATH if it cannot launch.'; } - const resolvedDirs = getUniqueResolvedDirs(resolvedPaths); - if (resolvedDirs.length > 1) { - return `⚠ Multiple ccstatusline binaries are on PATH. Claude Code will run the first match: ${active.resolvedPath}.\nOther matches: ${formatPathList(resolvedPaths.slice(1))}`; + const installPaths = getOnePathPerDirectory(resolvedPaths); + if (installPaths.length > 1) { + return `⚠ Multiple ccstatusline binaries are on PATH. Claude Code will run the first match: ${active.resolvedPath}.\nOther matches: ${formatPathList(installPaths.slice(1))}`; } if (active.packageManager === 'unknown') { From 7b3a803ebd77f59c9a02d288296a6ff2aa7d2b10 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 06:38:06 -0500 Subject: [PATCH 5/8] fix(install): resolve PATH directories' letter case the same under Node and Bun The duplicate-binary checks resolve each PATH directory with fs.realpathSync before comparing. Where the file system ignores letter case (macOS by default), Bun's realpathSync returns the case stored on disk but Node's returns the case it was given. A PATH that spells one directory two ways, such as .../bin and .../Bin, therefore showed "Multiple ccstatusline binaries are on PATH" when the TUI ran under Node and no warning under Bun. The lookup now uses fs.realpathSync.native, which asks the operating system and returns the on-disk case under both runtimes. A directory that can't be resolved still falls back to the path as listed. --- .../global-command-resolution.test.ts | 24 +++++++++++++++++++ src/utils/global-command-resolution.ts | 7 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/utils/__tests__/global-command-resolution.test.ts b/src/utils/__tests__/global-command-resolution.test.ts index 23a6312e0..1f91fa1cd 100644 --- a/src/utils/__tests__/global-command-resolution.test.ts +++ b/src/utils/__tests__/global-command-resolution.test.ts @@ -12,6 +12,7 @@ import { import { getCommandResolutionPaths, + getRealDirectory, inspectGlobalCommandResolution } from '../global-command-resolution'; import { @@ -49,6 +50,17 @@ function missingProgramError(command: string): Error { return Object.assign(new Error(`spawnSync ${command} ENOENT`), { code: 'ENOENT' }); } +// macOS and Windows file systems ignore letter case by default; most Linux ones don't +function tempFileSystemIgnoresCase(): boolean { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-case-')); + try { + fs.mkdirSync(path.join(dir, 'probe')); + return fs.existsSync(path.join(dir, 'PROBE')); + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +} + describe('global command resolution', () => { afterEach(() => { vi.restoreAllMocks(); @@ -194,6 +206,18 @@ describe('global command resolution', () => { } }); + // Where letter case is ignored, PATH can spell one directory two ways + it.skipIf(!tempFileSystemIgnoresCase())('resolves a directory spelled in another letter case to one path', () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-case-')); + try { + fs.mkdirSync(path.join(root, 'bin')); + + expect(getRealDirectory(path.join(root, 'Bin'))).toBe(getRealDirectory(path.join(root, 'bin'))); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it('ignores transient bunx status line shims when resolving global commands', () => { mockExecFileSync({ 'which -a ccstatusline': '/var/folders/demo/T/bunx-501-ccstatusline@latest/node_modules/.bin/ccstatusline\n/Users/alice/.bun/bin/ccstatusline\n', diff --git a/src/utils/global-command-resolution.ts b/src/utils/global-command-resolution.ts index 44b994685..efe28f4dd 100644 --- a/src/utils/global-command-resolution.ts +++ b/src/utils/global-command-resolution.ts @@ -170,10 +170,13 @@ function getDirectoryName(filePath: string): string { // A directory with symlinks resolved, so two spellings of one, such as /bin and // /usr/bin where /bin links to usr/bin (merged /usr), count as one install -// location. The path as given when it can't be resolved. +// location. The path as given when it can't be resolved. The native call also +// returns the letter case on disk where case is ignored (macOS), as Bun's +// realpathSync does but Node's doesn't, so both runtimes count .../Bin and +// .../bin as one. export function getRealDirectory(dir: string): string { try { - return fs.realpathSync(dir); + return fs.realpathSync.native(dir); } catch { return dir; } From 33272ac2dffbb38100bc196961c37482aba358b5 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 06:38:50 -0500 Subject: [PATCH 6/8] test(install): keep the PATH search for when which is missing, not failing The lookup searches PATH itself only when `which` can't be started (ENOENT). When `which` runs and exits non-zero, it found nothing, and that answer stands. No test covered this: with the ENOENT check removed, every failed `which -a ccstatusline` would fall through to the PATH search, and the tests still passed. The new case has `which -a` exit with status 1 while PATH holds an executable ccstatusline, and expects no matches. --- .../global-command-resolution.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/utils/__tests__/global-command-resolution.test.ts b/src/utils/__tests__/global-command-resolution.test.ts index 1f91fa1cd..b6f11d788 100644 --- a/src/utils/__tests__/global-command-resolution.test.ts +++ b/src/utils/__tests__/global-command-resolution.test.ts @@ -50,6 +50,11 @@ function missingProgramError(command: string): Error { return Object.assign(new Error(`spawnSync ${command} ENOENT`), { code: 'ENOENT' }); } +// What a program that runs and exits with status 1 throws, as `which` does when it finds nothing +function failedCommandError(command: string): Error { + return Object.assign(new Error(`Command failed: ${command}`), { status: 1 }); +} + // macOS and Windows file systems ignore letter case by default; most Linux ones don't function tempFileSystemIgnoresCase(): boolean { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-case-')); @@ -125,6 +130,21 @@ describe('global command resolution', () => { } }); + it.skipIf(process.platform === 'win32')('does not look through PATH itself when which runs and fails', () => { + const binDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-path-')); + const originalPath = process.env.PATH; + try { + fs.writeFileSync(path.join(binDir, 'ccstatusline'), '#!/bin/sh\n', { mode: 0o755 }); + process.env.PATH = binDir; + mockExecFileSync({ 'which -a ccstatusline': failedCommandError('which -a ccstatusline') }); + + expect(getCommandResolutionPaths('ccstatusline', { platform: 'linux' })).toEqual([]); + } finally { + process.env.PATH = originalPath; + fs.rmSync(binDir, { recursive: true, force: true }); + } + }); + it('silences child stderr on best-effort probes so failures cannot leak to the terminal', () => { const execFileSyncSpy = mockExecFileSync({ 'which -a ccstatusline': '/home/alice/.bun/bin/ccstatusline\n', From b4b115d8ee5af6708803ca050c31b98b11393841 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 07:14:14 -0500 Subject: [PATCH 7/8] test(install): check that PATH directories resolve through the native realpath The letter-case test passes under Bun with or without the native call, because Bun's plain realpathSync already reports the on-disk case, and it is skipped where the file system is case-sensitive. A second test checks the call itself, so a revert fails under bun test on any system. --- .../__tests__/global-command-resolution.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utils/__tests__/global-command-resolution.test.ts b/src/utils/__tests__/global-command-resolution.test.ts index b6f11d788..d555a4068 100644 --- a/src/utils/__tests__/global-command-resolution.test.ts +++ b/src/utils/__tests__/global-command-resolution.test.ts @@ -238,6 +238,21 @@ describe('global command resolution', () => { } }); + // Bun's plain realpathSync already reports the on-disk case, so only the + // call itself shows that Node gets the same answer + it('resolves directories with the native realpath', () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ccstatusline-case-')); + try { + const nativeSpy = vi.spyOn(fs.realpathSync, 'native'); + + getRealDirectory(root); + + expect(nativeSpy).toHaveBeenCalledWith(root); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } + }); + it('ignores transient bunx status line shims when resolving global commands', () => { mockExecFileSync({ 'which -a ccstatusline': '/var/folders/demo/T/bunx-501-ccstatusline@latest/node_modules/.bin/ccstatusline\n/Users/alice/.bun/bin/ccstatusline\n', From ec5007162fd6164dc2a31a3e3b38811020a7d0a7 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 16:32:09 -0500 Subject: [PATCH 8/8] refactor(install): build the default PATH search in a named helper findAllOnPosixPath spelled its default search as an object literal inside the parameter list, which made the signature hard to read at a glance. The default now comes from defaultPosixPathSearch(), next to the isExecutableFile check it uses. A default parameter is evaluated on every call that leaves it out, so the helper still builds a fresh search from process.env as it is when the search runs: an env object swapped in after the module loaded is still seen. --- src/utils/executable-path.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/executable-path.ts b/src/utils/executable-path.ts index c45eb6b96..7cc218604 100644 --- a/src/utils/executable-path.ts +++ b/src/utils/executable-path.ts @@ -104,12 +104,16 @@ function isExecutableFile(candidate: string): boolean { } } +function defaultPosixPathSearch(): PosixPathSearch { + return { env: process.env, isExecutableFile }; +} + /** * Every file named `name` on PATH that the user can run, in PATH order: what * `which -a` lists. The default search reads process.env when called, so an env * object swapped in after this module loaded is still seen. */ -export function findAllOnPosixPath(name: string, search: PosixPathSearch = { env: process.env, isExecutableFile }): string[] { +export function findAllOnPosixPath(name: string, search: PosixPathSearch = defaultPosixPathSearch()): string[] { const pathValue = search.env.PATH; if (!pathValue) { return [];