diff --git a/commands/cli/parse.go b/commands/cli/parse.go
index 11003335ef3fb7228192c79bb8e974b23d0a2238..0b99fd4998115735d96d1fa6ec680355c8ccf3e4 100644
--- a/commands/cli/parse.go
+++ b/commands/cli/parse.go
@@ -223,7 +223,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
 	// if there is at least one ArgDef, we can safely trigger the inputs loop
 	// below to parse stdin.
 	numInputs := len(inputs)
-	if len(argDefs) > 0 && stdin != nil {
+	if len(argDefs) > 0 && argDefs[len(argDefs)-1].SupportsStdin && stdin != nil {
 		numInputs += 1
 	}
 
diff --git a/commands/cli/parse_test.go b/commands/cli/parse_test.go
index 2c42ddcc4528bf1e0a5168fc3c658efe1e5f66c1..c6215299b7341e29cf073c665580a14b998fcf29 100644
--- a/commands/cli/parse_test.go
+++ b/commands/cli/parse_test.go
@@ -283,4 +283,7 @@ func TestArgumentParsing(t *testing.T) {
 
 	fstdin = fileToSimulateStdin(t, "stdin1")
 	test([]string{"noarg"}, fstdin, []string{})
+
+	fstdin = fileToSimulateStdin(t, "stdin1")
+	test([]string{"optionalsecond", "value1", "value2"}, fstdin, []string{"value1", "value2"})
 }