Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

perf(mcp): run the startup pane sweep once per root through ensureSwept

Jack Rudenkob0c9b9ae5a23
diff --git a/packages/cli/src/mcp-server.ts b/packages/cli/src/mcp-server.ts
index fb1a884e..b482a912 100644
--- a/packages/cli/src/mcp-server.ts
+++ b/packages/cli/src/mcp-server.ts
@@ -52,8 +52,9 @@ import {
assertMagmuxAvailable,
checkChildFlags,
contractMeta,
+ ensureSwept,
installPaneShutdownHooks,
- sweepOrphanPanes,
+ sockRootFor,
} from "./pane/index.js";
import { findAvailablePort } from "./port-manager.js";
import { ensureEndpointsRegistered } from "./providers/endpoint-registration.js";
@@ -2509,8 +2510,9 @@ async function main() {
await server.connect(transport);
installMcpShutdown(sessionManager);
// The startup sweep: panes whose owner died (and whose watcher died too) are reaped
- // after an identity check. Asynchronous; a failure costs nothing but the sweep.
- void sweepOrphanPanes().catch(() => undefined);
+ // after an identity check. Asynchronous, and once per root per process — the first
+ // pane's own sweep (ensureSwept in startPaneSession) is this one, not a second `ps`.
+ void ensureSwept(sockRootFor()).catch(() => undefined);
}
/**
diff --git a/packages/cli/src/pane/index.ts b/packages/cli/src/pane/index.ts
index a839c8a0..bca4839f 100644
--- a/packages/cli/src/pane/index.ts
+++ b/packages/cli/src/pane/index.ts
@@ -24,6 +24,7 @@ export {
sockRootFor,
} from "./pane-launch.js";
export {
+ ensureSwept,
installPaneShutdownHooks,
livePaneCount,
MAX_LIVE_PANES,