File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -270,4 +270,31 @@ export async function run(): Promise<void> {
270270 defaultName : `claude-code-${ nanoid ( 4 ) } ` ,
271271 } ) ;
272272 agentId = reg . agentId ;
273+
274+ // -----------------------------------------------------------------------
275+ // Shutdown — clean up mesh state when Claude Code exits
276+ // -----------------------------------------------------------------------
277+
278+ async function shutdown ( ) : Promise < void > {
279+ try {
280+ if ( agentId !== undefined ) {
281+ await store . setAgentOffline ( agentId ) ;
282+ }
283+ await store . shutdown ( ) ;
284+ } catch {
285+ // best-effort — the process is exiting anyway
286+ }
287+ }
288+
289+ for ( const signal of [ "SIGTERM" , "SIGINT" , "SIGHUP" ] as const ) {
290+ process . on ( signal , ( ) => {
291+ void shutdown ( ) . finally ( ( ) => process . exit ( 0 ) ) ;
292+ } ) ;
293+ }
294+
295+ process . on ( "exit" , ( ) => {
296+ // Synchronous fallback if async shutdown didn't complete in time.
297+ // store.shutdown() is async but the coordinator socket unref() in
298+ // MeshStore.init() means the process won't hang on the way out.
299+ } ) ;
273300}
You can’t perform that action at this time.
0 commit comments