diff --git a/src/cliproxy/service-manager.ts b/src/cliproxy/service-manager.ts index ea9dff59..0ef4d2e7 100644 --- a/src/cliproxy/service-manager.ts +++ b/src/cliproxy/service-manager.ts @@ -76,7 +76,7 @@ async function waitForPort( } /** - * Register cleanup handlers to stop proxy on process exit + * Register process-exit cleanup handlers for in-process workers. */ function registerCleanup(): void { if (cleanupRegistered) return; @@ -87,11 +87,8 @@ function registerCleanup(): void { tokenRefreshWorker.stop(); tokenRefreshWorker = null; } - // Then stop proxy process - if (proxyProcess && !proxyProcess.killed) { - proxyProcess.kill('SIGTERM'); - proxyProcess = null; - } + // Do not stop detached CLIProxy on parent exit. + // Persistence is expected across CCS command lifecycles. }; process.once('exit', cleanup); diff --git a/src/commands/cliproxy/proxy-lifecycle-subcommand.ts b/src/commands/cliproxy/proxy-lifecycle-subcommand.ts index aea76afb..d59319c2 100644 --- a/src/commands/cliproxy/proxy-lifecycle-subcommand.ts +++ b/src/commands/cliproxy/proxy-lifecycle-subcommand.ts @@ -8,6 +8,8 @@ import { initUI, header, color, dim, ok, warn, info } from '../../utils/ui'; import { getProxyStatus, stopProxy } from '../../cliproxy/services'; +import { detectRunningProxy } from '../../cliproxy/proxy-detector'; +import { CLIPROXY_DEFAULT_PORT } from '../../cliproxy/config-generator'; export async function handleProxyStatus(): Promise { await initUI(); @@ -26,9 +28,23 @@ export async function handleProxyStatus(): Promise { console.log(''); console.log(dim('To stop: ccs cliproxy stop')); } else { - console.log(` Status: ${color('Not running', 'warning')}`); - console.log(''); - console.log(dim('CLIProxy starts automatically when you run ccs gemini, codex, etc.')); + // Fallback: detect untracked/orphaned proxy process (e.g. detached session without lock file). + const detected = await detectRunningProxy(); + if (detected.running && detected.verified) { + console.log(` Status: ${color('Running', 'success')}`); + console.log(` PID: ${detected.pid ?? 'unknown'}`); + console.log(` Port: ${CLIPROXY_DEFAULT_PORT}`); + console.log(` Sessions: ${detected.sessionCount || 0} active`); + if (!detected.sessionCount) { + console.log(dim(' Note: Detected running proxy without local session lock')); + } + console.log(''); + console.log(dim('To stop: ccs cliproxy stop')); + } else { + console.log(` Status: ${color('Not running', 'warning')}`); + console.log(''); + console.log(dim('CLIProxy starts automatically when you run ccs gemini, codex, etc.')); + } } console.log(''); }