From 806dfbbfac17edf69c5ed84b73fa7c351365fd9e Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:17:05 -0500 Subject: [PATCH 1/2] fix(tui): stop editor keys pausing on a global ccstatusline install When Claude Code runs the global `ccstatusline` command (a pinned install, which is the install menu's default, or a self-managed one), App looked that command up in its render body. The lookup runs `which -a`, `npm prefix -g` and `bun pm bin -g` synchronously, and a pinned install runs `which` and the bin-dir lookup again for the relaunch path. The label editor's live preview and every widget edit redraw App, so each of those keys blocked the TUI for a quarter to half a second on macOS. Keys pressed meanwhile reached Ink as one read, which it parses as a single key or none: of six quick backspaces, two or three took effect. Run the lookups in a memo keyed on what they depend on: the saved installation metadata, Claude's status line command and the install state. They now run once loading finishes, and again after an install, update or uninstall from the TUI, since each changes one of those. The screens show the same thing. Ctrl+S and Check for Updates still look the command up when pressed. --- src/tui/App.tsx | 51 ++++++++++++------ src/tui/__tests__/App.test.ts | 99 +++++++++++++++++++++++++++++++++-- 2 files changed, 131 insertions(+), 19 deletions(-) diff --git a/src/tui/App.tsx b/src/tui/App.tsx index 23e5c51a4..710ee1e4f 100644 --- a/src/tui/App.tsx +++ b/src/tui/App.tsx @@ -10,6 +10,7 @@ import Gradient from 'ink-gradient'; import React, { useCallback, useEffect, + useMemo, useRef, useState } from 'react'; @@ -322,11 +323,11 @@ function clearInstallationMetadata(settings: Settings | null): Settings | null { export function getCurrentInstallation( isClaudeInstalled: boolean, existingStatusLine: string | null, - settings: Settings + savedInstallation: InstallationMetadata | undefined ): InstallationMetadata { - return isClaudeInstalled && !existingStatusLine && settings.installation - ? settings.installation - : classifyInstallation(existingStatusLine, settings.installation); + return isClaudeInstalled && !existingStatusLine && savedInstallation + ? savedInstallation + : classifyInstallation(existingStatusLine, savedInstallation); } function trimTrailingSeparators(filePath: string): string { @@ -583,7 +584,7 @@ export const App: React.FC = () => { } // Global save shortcut if (key.ctrl && input === 's' && settings && screen !== 'confirm') { - const installation = getCurrentInstallation(isClaudeInstalled, existingStatusLine, settings); + const installation = getCurrentInstallation(isClaudeInstalled, existingStatusLine, settings.installation); const activeCommand = installation.method === 'pinned' || installation.method === 'self-managed' ? inspectActiveGlobalCommand({ commandAvailability }) : null; @@ -743,7 +744,7 @@ export const App: React.FC = () => { const handleUpdateCheck = useCallback(() => { setUpdateCheckerState({ status: 'checking' }); const installation = settings - ? getCurrentInstallation(isClaudeInstalled, existingStatusLine, settings) + ? getCurrentInstallation(isClaudeInstalled, existingStatusLine, settings.installation) : classifyInstallation(existingStatusLine, undefined); const activeCommand = installation.method === 'pinned' || installation.method === 'self-managed' ? inspectActiveGlobalCommand({ commandAvailability }) @@ -867,22 +868,42 @@ export const App: React.FC = () => { setScreen('main'); }, [importValidation, settings]); - if (!settings || !hasLoadedClaudeStatus || !hasLoadedInstalledState) { + const savedInstallation = settings?.installation; + const hasLoaded = settings !== null && hasLoadedClaudeStatus && hasLoadedInstalledState; + // Looking up the global ccstatusline command runs `which -a`, `npm prefix -g` and + // `bun pm bin -g`, which block for a few hundred ms. Editor keys redraw App (the live + // preview, each widget edit), so the lookups run only when the installation changes: + // once loading finishes, and after an install, update or uninstall here, since each + // changes the installation metadata or Claude's status line. Null while loading. + const installationState = useMemo(() => { + if (!hasLoaded) { + return null; + } + + const currentInstallation = getCurrentInstallation(isClaudeInstalled, existingStatusLine, savedInstallation); + const activeGlobalCommand = currentInstallation.method === 'pinned' || currentInstallation.method === 'self-managed' + ? inspectActiveGlobalCommand({ commandAvailability }) + : null; + const effectiveInstallation = getPathInferredInstallation(currentInstallation, activeGlobalCommand); + const pinnedRelaunchCommand = effectiveInstallation.method === 'pinned' + && effectiveInstallation.packageManager !== 'unknown' + ? getPinnedGlobalRelaunchCommand(effectiveInstallation.packageManager) + : null; + + return { activeGlobalCommand, effectiveInstallation, pinnedRelaunchCommand }; + }, [commandAvailability, existingStatusLine, hasLoaded, isClaudeInstalled, savedInstallation]); + + if (!settings || !installationState) { return Loading settings...; } const runningVersion = getPackageVersion(); - const currentInstallation = getCurrentInstallation(isClaudeInstalled, existingStatusLine, settings); - const activeGlobalCommand = currentInstallation.method === 'pinned' || currentInstallation.method === 'self-managed' - ? inspectActiveGlobalCommand({ commandAvailability }) - : null; - const effectiveInstallation = getPathInferredInstallation(currentInstallation, activeGlobalCommand); - const pinnedVersionMismatch = effectiveInstallation.method === 'pinned' - && effectiveInstallation.packageManager !== 'unknown' + const { activeGlobalCommand, effectiveInstallation, pinnedRelaunchCommand } = installationState; + const pinnedVersionMismatch = pinnedRelaunchCommand ? getPinnedVersionMismatch( effectiveInstallation, runningVersion, - getPinnedGlobalRelaunchCommand(effectiveInstallation.packageManager), + pinnedRelaunchCommand, versionInstalledThisSession ) : null; diff --git a/src/tui/__tests__/App.test.ts b/src/tui/__tests__/App.test.ts index a950ddc63..e7c413821 100644 --- a/src/tui/__tests__/App.test.ts +++ b/src/tui/__tests__/App.test.ts @@ -14,6 +14,7 @@ import { type InstallationMetadata } from '../../types/Settings'; import * as claudeSettings from '../../utils/claude-settings'; +import * as globalCommandResolution from '../../utils/global-command-resolution'; import * as globalPackageManager from '../../utils/global-package-manager'; import { getPackageVersion } from '../../utils/terminal'; import * as updateChecker from '../../utils/update-checker'; @@ -113,10 +114,7 @@ describe('Pinned version mismatch guard', () => { installedVersion: '2.2.13' }; - expect(getCurrentInstallation(true, null, { - ...DEFAULT_SETTINGS, - installation - })).toEqual(installation); + expect(getCurrentInstallation(true, null, installation)).toEqual(installation); }); it('does not block auto-update or matching pinned installs', () => { @@ -502,6 +500,99 @@ describe('App live label preview', () => { }); }); +describe('App lookup of the global ccstatusline command', () => { + let sandbox: AppSandbox; + + beforeEach(() => { + sandbox = setUpAppSandbox(); + vi.spyOn(claudeStatus, 'loadClaudeStatusLineState').mockResolvedValue({ existingStatusLine: 'ccstatusline', refreshInterval: null }); + vi.spyOn(claudeSettings, 'isInstalled').mockResolvedValue(true); + }); + + afterEach(() => { + sandbox.restore(); + }); + + // The real lookups run `which -a`, `npm prefix -g` and `bun pm bin -g` + it.each(['pinned', 'self-managed'] as const)('looks up a %s install once, not again for each editor key', async (method) => { + const runningVersion = getPackageVersion(); + fs.writeFileSync(sandbox.settingsPath, JSON.stringify({ + ...DEFAULT_SETTINGS, + lines: [[{ id: 'model', type: 'model', metadata: { label: '7d' } }]], + ...(method === 'pinned' && { installation: { method: 'pinned', installedVersion: runningVersion } }) + })); + const inspectActiveCommand = vi.spyOn(globalPackageManager, 'inspectActiveGlobalCommand').mockReturnValue({ + packageManager: 'npm', + resolvedPath: '/usr/local/bin/ccstatusline', + resolvedPaths: ['/usr/local/bin/ccstatusline'], + binDir: '/usr/local/bin', + version: runningVersion, + warning: null + }); + const inspectResolution = vi.spyOn(globalCommandResolution, 'inspectGlobalCommandResolution').mockReturnValue({ + resolvedPaths: ['/usr/local/bin/ccstatusline'], + firstResolvedPath: '/usr/local/bin/ccstatusline', + expectedBinDir: '/usr/local/bin', + warning: null + }); + const rendered = renderApp(); + + try { + await waitFor(() => { + expect(rendered.getFrame()).toContain('🧰 Manage Installation'); + }); + await pressKey(rendered, KEYS.enter, 'Select Line to Edit Items'); + await pressKey(rendered, KEYS.enter, 'Edit Line 1'); + await pressKey(rendered, 'e', '(default: "Model: ")'); + await pressKey(rendered, 'X', '7dXClaude'); + await pressKey(rendered, 'Y', '7dXYClaude'); + await pressKey(rendered, 'Z', '7dXYZClaude'); + await pressKey(rendered, KEYS.enter, 'Edit Line 1'); + await pressKey(rendered, 'r', '(raw value)'); + await pressKey(rendered, KEYS.escape, 'Select Line to Edit Items'); + await pressKey(rendered, KEYS.escape, '🧰 Manage Installation'); + + expect(inspectActiveCommand).toHaveBeenCalledOnce(); + // Pinned installs also look up the relaunch path for the version-mismatch screen + expect(inspectResolution).toHaveBeenCalledTimes(method === 'pinned' ? 1 : 0); + } finally { + rendered.cleanup(); + } + }); + + it('looks again after the TUI updates the pinned global install', async () => { + fs.writeFileSync(sandbox.settingsPath, JSON.stringify({ + ...DEFAULT_SETTINGS, + installation: { method: 'pinned', installedVersion: '2.0.0' } + })); + let versionOnDisk = '2.0.0'; + const inspectActiveCommand = vi.spyOn(globalPackageManager, 'inspectActiveGlobalCommand').mockImplementation(() => ({ + packageManager: 'npm', + resolvedPath: '/usr/local/bin/ccstatusline', + resolvedPaths: ['/usr/local/bin/ccstatusline'], + binDir: '/usr/local/bin', + version: versionOnDisk, + warning: null + })); + vi.spyOn(updateChecker, 'runGlobalPackageInstall').mockImplementation((packageManager, version) => { + versionOnDisk = version; + return Promise.resolve(); + }); + const rendered = renderApp(); + + try { + await waitFor(() => { + expect(rendered.getFrame()).toContain('Pinned Install Version Mismatch'); + }); + await pressKey(rendered, KEYS.enter, '✓ Global package updated'); + expect(rendered.getFrame()).toContain('Main Menu'); + expect(inspectActiveCommand).toHaveBeenCalledTimes(2); + } finally { + rendered.cleanup(); + } + }); +}); + describe('App save guard for an invalid settings.json', () => { let sandbox: AppSandbox; From 73739ca88ed039eb16e10506b4626e8b4a0d4208 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 16:32:28 -0500 Subject: [PATCH 2/2] refactor(tui): let App choose how to classify the installation getCurrentInstallation took an isClaudeInstalled flag that switched between two behaviours: with ccstatusline installed in Claude Code, the saved metadata stands in until the status line command is read; otherwise the command alone is classified. Each caller already holds that state, so each now picks: classifyInstalledStatusLine for the installed case, classifyInstallation otherwise. Check for Updates passes the saved metadata as settings?.installation instead of special-casing missing settings, since no saved metadata already classifies the command alone. --- src/tui/App.tsx | 21 +++++++++++++-------- src/tui/__tests__/App.test.ts | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/tui/App.tsx b/src/tui/App.tsx index 710ee1e4f..aa34dac55 100644 --- a/src/tui/App.tsx +++ b/src/tui/App.tsx @@ -320,12 +320,13 @@ function clearInstallationMetadata(settings: Settings | null): Settings | null { return next; } -export function getCurrentInstallation( - isClaudeInstalled: boolean, +// Claude Code runs ccstatusline, so until its status line command is read, the saved +// metadata describes the install +export function classifyInstalledStatusLine( existingStatusLine: string | null, savedInstallation: InstallationMetadata | undefined ): InstallationMetadata { - return isClaudeInstalled && !existingStatusLine && savedInstallation + return !existingStatusLine && savedInstallation ? savedInstallation : classifyInstallation(existingStatusLine, savedInstallation); } @@ -584,7 +585,9 @@ export const App: React.FC = () => { } // Global save shortcut if (key.ctrl && input === 's' && settings && screen !== 'confirm') { - const installation = getCurrentInstallation(isClaudeInstalled, existingStatusLine, settings.installation); + const installation = isClaudeInstalled + ? classifyInstalledStatusLine(existingStatusLine, settings.installation) + : classifyInstallation(existingStatusLine, settings.installation); const activeCommand = installation.method === 'pinned' || installation.method === 'self-managed' ? inspectActiveGlobalCommand({ commandAvailability }) : null; @@ -743,9 +746,9 @@ export const App: React.FC = () => { const handleUpdateCheck = useCallback(() => { setUpdateCheckerState({ status: 'checking' }); - const installation = settings - ? getCurrentInstallation(isClaudeInstalled, existingStatusLine, settings.installation) - : classifyInstallation(existingStatusLine, undefined); + const installation = isClaudeInstalled + ? classifyInstalledStatusLine(existingStatusLine, settings?.installation) + : classifyInstallation(existingStatusLine, settings?.installation); const activeCommand = installation.method === 'pinned' || installation.method === 'self-managed' ? inspectActiveGlobalCommand({ commandAvailability }) : null; @@ -880,7 +883,9 @@ export const App: React.FC = () => { return null; } - const currentInstallation = getCurrentInstallation(isClaudeInstalled, existingStatusLine, savedInstallation); + const currentInstallation = isClaudeInstalled + ? classifyInstalledStatusLine(existingStatusLine, savedInstallation) + : classifyInstallation(existingStatusLine, savedInstallation); const activeGlobalCommand = currentInstallation.method === 'pinned' || currentInstallation.method === 'self-managed' ? inspectActiveGlobalCommand({ commandAvailability }) : null; diff --git a/src/tui/__tests__/App.test.ts b/src/tui/__tests__/App.test.ts index e7c413821..ebf0c2919 100644 --- a/src/tui/__tests__/App.test.ts +++ b/src/tui/__tests__/App.test.ts @@ -22,9 +22,9 @@ import { applyTuiImport, buildConfigLoadWarning, buildInvalidConfigSaveConfirm, + classifyInstalledStatusLine, clearInstallMenuSelection, getConfirmCancelScreen, - getCurrentInstallation, getPathInferredInstallation, getPinnedVersionMismatch } from '../App'; @@ -114,7 +114,7 @@ describe('Pinned version mismatch guard', () => { installedVersion: '2.2.13' }; - expect(getCurrentInstallation(true, null, installation)).toEqual(installation); + expect(classifyInstalledStatusLine(null, installation)).toEqual(installation); }); it('does not block auto-update or matching pinned installs', () => {