Repository navigation
Description
OpenCodeReview Version
open-code-review dev darwin/arm64 (built from source, latest main)
Operating System
macOS (Apple Silicon)
Installation Method
Built from source
LLM Provider
Anthropic (Claude)
Bug Description
Parent commands (session, config, delegate, llm, rules) silently display help and return exit code 0 when given an unknown subcommand. This is inconsistent with the root command and leaf commands, which correctly return exit code 1 with an error message.
| Command level | Input | Exit code | Behavior |
|---|---|---|---|
| Root | ocr nonexistent |
1 | Error: unknown command "nonexistent" for "ocr" |
| Leaf | ocr review unknown |
1 | Error: unknown command "unknown" for "ocr review" |
| Parent | ocr session unknown |
0 | Silently prints help, no error |
| Parent | ocr config unknown |
0 | Silently prints help, no error |
| Parent | ocr delegate unknown |
0 | Silently prints help, no error |
| Parent | ocr llm unknown |
0 | Silently prints help, no error |
| Parent | ocr rules unknown |
0 | Silently prints help, no error |
Steps to Reproduce
# 1. Run a parent command with an unknown subcommand
ocr session unknown
echo $? # prints 0
# 2. Compare with root command
ocr nonexistent
echo $? # prints 1
# 3. Compare with leaf command
ocr review unknown
echo $? # prints 1Expected Behavior
All commands should consistently return exit code 1 and print an error message when given an unrecognized subcommand. For example, ocr session unknown should output:
Error: unknown command "unknown" for "ocr session"
and exit with code 1, matching the behavior of the root command and leaf commands.
Logs / Error Output
$ ocr session unknown
List and inspect saved review sessions
Usage:
ocr session [command]
Aliases:
session, sessions
Available Commands:
list List recent review sessions for the current repo
show Show one session's metadata and per-file items
Flags:
-h, --help help for session
Use "ocr session [command] --help" for more information about a command.
$ echo $?
0Additional Context
The root cause is that parent commands (sessionCmd, configCmd, delegateCmd, llmCmd, rulesCmd) are defined without a RunE/Run function. In Cobra, when a parent command has no RunE and receives an unrecognized subcommand, it falls back to displaying help and returns nil (exit 0). Adding a RunE that returns cmd.Help() (or any non-nil function) would cause Cobra to properly report "unknown command" errors for these parent commands, consistent with the root command's behavior.
Activity
binyaaminofficial commentedon Aug 2, 2026
This behavior occurs because Cobra parent commands (sessionCmd, configCmd, delegateCmd, llmCmd, rulesCmd) are defined without an explicit Args validation rule or RunE handler. When an unrecognized subcommand is passed to a parent command without a Run function, Cobra falls back to printing help and exits with status 0.
Code Fix
Update the parent command definitions across session, config, delegate, llm, and rules to require strict argument handling using cobra.ExactArgs(0):
var sessionCmd = &cobra.Command{
Use: "session",
Short: "List and inspect saved review sessions",
Args: cobra.ExactArgs(0),
}
var configCmd = &cobra.Command{
Use: "config",
Short: "Manage OpenCodeReview configuration",
Args: cobra.ExactArgs(0),
}
var delegateCmd = &cobra.Command{
Use: "delegate",
Short: "Manage task delegation settings",
Args: cobra.ExactArgs(0),
}
var llmCmd = &cobra.Command{
Use: "llm",
Short: "Manage LLM provider configurations",
Args: cobra.ExactArgs(0),
}
var rulesCmd = &cobra.Command{
Use: "rules",
Short: "Manage code review rule sets",
Args: cobra.ExactArgs(0),
}
Verification
After applying cobra.ExactArgs(0), passing an unknown subcommand correctly triggers Cobra's native error handling and returns exit code 1:
$ ocr session unknown
Error: unknown command "unknown" for "ocr session"
Run 'ocr session --help' for usage.
$ echo $?
1
fix(cli): return error on unknown subcommands for parent commands (#660)
fix(cli): return error on unknown subcommands for parent commands (al…