From 8ea48c5eaa19d0b6c5f4ffbbb51c2bb5f0ea0303 Mon Sep 17 00:00:00 2001 From: Tabish Bidiwale Date: Sat, 10 Jan 2026 15:07:06 -0800 Subject: [PATCH] fix: use actionCommand for telemetry command tracking The preAction hook receives (thisCommand, actionCommand) where thisCommand is the root program and actionCommand is the actual subcommand being run. Using thisCommand was incorrectly tracking the root command instead of the actual subcommand executed by the user. --- src/cli/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index be2620f0a..a02ec5efa 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -50,7 +50,10 @@ program program.option('--no-color', 'Disable color output'); // Apply global flags and telemetry before any command runs -program.hook('preAction', async (thisCommand) => { +// Note: preAction receives (thisCommand, actionCommand) where: +// - thisCommand: the command where hook was added (root program) +// - actionCommand: the command actually being executed (subcommand) +program.hook('preAction', async (thisCommand, actionCommand) => { const opts = thisCommand.opts(); if (opts.color === false) { process.env.NO_COLOR = '1'; @@ -59,8 +62,8 @@ program.hook('preAction', async (thisCommand) => { // Show first-run telemetry notice (if not seen) await maybeShowTelemetryNotice(); - // Track command execution - const commandPath = getCommandPath(thisCommand); + // Track command execution (use actionCommand to get the actual subcommand) + const commandPath = getCommandPath(actionCommand); await trackCommand(commandPath, version); });