MCPcopy
hub / github.com/codeaashu/claude-code / killOrphanedTeammatePanes

Function killOrphanedTeammatePanes

src/utils/swarm/teamHelpers.ts:598–634  ·  view source on GitHub ↗

* Best-effort kill of all pane-backed teammate panes for a team. * Called from cleanupSessionTeams on ungraceful leader exit (SIGINT/SIGTERM). * Dynamic imports avoid adding registry/detection to this module's static * dep graph — this only runs at shutdown, so the import cost is irrelevant.

(teamName: string)

Source from the content-addressed store, hash-verified

596 * dep graph — this only runs at shutdown, so the import cost is irrelevant.
597 */
598async function killOrphanedTeammatePanes(teamName: string): Promise<void> {
599 const teamFile = readTeamFile(teamName)
600 if (!teamFile) return
601
602 const paneMembers = teamFile.members.filter(
603 m =>
604 m.name !== TEAM_LEAD_NAME &&
605 m.tmuxPaneId &&
606 m.backendType &&
607 isPaneBackend(m.backendType),
608 )
609 if (paneMembers.length === 0) return
610
611 const [{ ensureBackendsRegistered, getBackendByType }, { isInsideTmux }] =
612 await Promise.all([
613 import('./backends/registry.js'),
614 import('./backends/detection.js'),
615 ])
616 await ensureBackendsRegistered()
617 const useExternalSession = !(await isInsideTmux())
618
619 await Promise.allSettled(
620 paneMembers.map(async m => {
621 // filter above guarantees these; narrow for the type system
622 if (!m.tmuxPaneId || !m.backendType || !isPaneBackend(m.backendType)) {
623 return
624 }
625 const ok = await getBackendByType(m.backendType).killPane(
626 m.tmuxPaneId,
627 useExternalSession,
628 )
629 logForDebugging(
630 `cleanupSessionTeams: killPane ${m.name} (${m.backendType} ${m.tmuxPaneId}) → ${ok}`,
631 )
632 }),
633 )
634}
635
636/**
637 * Cleans up team and task directories for a given team name.

Callers 1

cleanupSessionTeamsFunction · 0.85

Calls 7

readTeamFileFunction · 0.85
isPaneBackendFunction · 0.85
ensureBackendsRegisteredFunction · 0.85
getBackendByTypeFunction · 0.85
logForDebuggingFunction · 0.85
isInsideTmuxFunction · 0.50
killPaneMethod · 0.45

Tested by

no test coverage detected