Skip to content

Write HTML. Render video. Built for agents.

fix(cli): print the update-available notice once, not on every event-loop drain

James7f755913a60d
diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts
index 1e414b6841..34755f5a91 100644
--- a/packages/cli/src/cli.ts
+++ b/packages/cli/src/cli.ts
@@ -193,8 +193,12 @@ if (!isHelp && !hasJsonFlag && command !== "upgrade") {
const commandStart = Date.now();
let commandFailed = false;
-// Async flush for normal exit (beforeExit fires when the event loop drains)
-process.on("beforeExit", () => {
+// Async flush for normal exit. `beforeExit` re-fires every time the
+// event loop drains, and the async `_flush()` itself schedules new
+// work — so a plain `on` listener would print the update notice (and
+// re-flush) once per drain (the user-reported double-print). `once`
+// detaches after first invocation, which is what we want for both.
+process.once("beforeExit", () => {
_flush?.().catch(() => {});
if (!hasJsonFlag) _printUpdateNotice?.();
});