diff --git a/main/cli.c b/main/cli.c
index 127aa19aba93a8495a910be2e6369e6239091a86..35d3078294d85fdc4b67778016dba15cfee39523 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1662,7 +1662,7 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
 			 * Run the generator if one is available. In any case we are done.
 			 */
 			if (e->generator)
-				ret = e->generator(matchstr, word, argindex, state);
+				ret = e->generator(matchstr, word, argindex, state - matchnum);
 			else if (e->command) {	/* new style command */
 				/* prepare fake arguments for the generator.
 				 * argv[-1] is the cli entry we use,