@@ -273,9 +273,12 @@ export class RootCommand extends Command {
273273 // Determine if we should complete commands
274274 private shouldCompleteCommands (
275275 toComplete : string ,
276- endsWithSpace : boolean
276+ endsWithSpace : boolean ,
277+ isRootCommandContext : boolean
277278 ) : boolean {
278- return ! toComplete . startsWith ( '-' ) ;
279+ // Only suggest commands when we're still completing at the root context.
280+ // Once a command is matched, we should move on to its arguments/flags.
281+ return isRootCommandContext && ! toComplete . startsWith ( '-' ) ;
279282 }
280283
281284 // Handle flag completion (names and values)
@@ -471,6 +474,7 @@ export class RootCommand extends Command {
471474 }
472475
473476 const [ matchedCommand ] = this . matchCommand ( previousArgs ) ;
477+ const isRootContext = matchedCommand === this ;
474478 const lastPrevArg = previousArgs [ previousArgs . length - 1 ] ;
475479
476480 // 1. Handle flag/option completion
@@ -504,7 +508,9 @@ export class RootCommand extends Command {
504508 }
505509
506510 // 2. Handle command/subcommand completion
507- if ( this . shouldCompleteCommands ( toComplete , endsWithSpace ) ) {
511+ if (
512+ this . shouldCompleteCommands ( toComplete , endsWithSpace , isRootContext )
513+ ) {
508514 this . handleCommandCompletion ( previousArgs , toComplete ) ;
509515 }
510516 // 3. Handle positional arguments - always check for root command arguments
0 commit comments