From d263fe0f26e8b86089a30574725872ae1bde4da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= <35082514+alezmad@users.noreply.github.com> Date: Thu, 9 Apr 2026 01:25:10 +0100 Subject: [PATCH] fix(cli): delay welcome notification for MCP init handshake Welcome was silently dropped when sent before Claude Code's notifications/initialized. Add 2s delay after WS connects to ensure the MCP handshake is complete. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/cli/src/mcp/server.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/cli/src/mcp/server.ts b/apps/cli/src/mcp/server.ts index bb2f2d0..6084013 100644 --- a/apps/cli/src/mcp/server.ts +++ b/apps/cli/src/mcp/server.ts @@ -1899,9 +1899,11 @@ Your message mode is "${messageMode}". } // Welcome notification: give Claude immediate context on connect. - // No delay needed — WS is already connected at this point. - const welcomeClient = allClients()[0]; - if (welcomeClient && welcomeClient.status === "open") { + // Delay slightly to ensure Claude Code has completed MCP initialization + // handshake (notifications/initialized) before we push channel messages. + setTimeout(async () => { + const welcomeClient = allClients()[0]; + if (!welcomeClient || welcomeClient.status !== "open") return; try { const peers = await welcomeClient.listPeers(); const peerNames = peers @@ -1916,7 +1918,7 @@ Your message mode is "${messageMode}". }, }); } catch { /* best effort */ } - } + }, 2_000); } // end wirePushHandlers // Event loop keepalive: Node.js stdout to a pipe is buffered. Without