[Bug] nanocoder run exits 0 without running when the prompt contains -v, --version, -h or --help
Description
nanocoder run exits 0 without running anything when the prompt contains the word -v, --version, -h or --help. It prints the version or the top-level help instead.
The --version/-v and --help/-h fast paths in source/cli.tsx (lines 76 and 258 on main @ 31e58cf8) check the whole argv with args.includes(...), so they fire even when the token is part of the run prompt. They run before validateCliArgs and parseRunPrompt, so they win over the documented rule in source/cli-args.ts: "Arguments after run are deliberately left alone because they are prompt text, where option-looking tokens may be part of the user's request." KNOWN_RUN_FLAGS in source/run-prompt-args.ts already treats -v/-h as prompt text; only the fast paths disagree.
The worst case is a silent success: a CI step like nanocoder run go test -v exits 0 and the pipeline goes green, but the prompt never ran.
This is the same family as #2308, but a separate gap: open PR #2313 makes --continue/--resume/--acp count only before run, and doesn't touch the -v/-h fast paths.
Environment
- OS: macOS 26.6 (Apple Silicon)
- Node version: v24.22.3
- Nanocoder version: 1.32.0 (
main@31e58cf8, built locally) - Provider: not applicable (the run never starts)
- Model: not applicable
Steps to Reproduce
nanocoder run go test -vnanocoder run node --versionnanocoder run grep -h foo- Control:
nanocoder run go test -V(capital V)
Expected Behavior
Words after run are prompt text, so cases 1-3 start the run like case 4 does.
Actual Behavior
| Command | Output | Exit code |
|---|---|---|
nanocoder run go test -v |
1.32.0 |
0 |
nanocoder run node --version |
1.32.0 |
0 |
nanocoder run grep -h foo |
full top-level --help text |
0 |
nanocoder run go test -V (control) |
reaches the run path (directory-trust check in my scratch dir) | 1 |
Logs/Screenshots
Raw output
Run from a scratch copy of the repo with HOME pointed at an empty folder, so no real config was used.
$ nanocoder run go test -v
1.32.0
exit=0
$ nanocoder run node --version
1.32.0
exit=0
$ nanocoder run grep -h foo
Usage: nanocoder [options] [command]
...
exit=0
$ nanocoder run go test -V
Directory /private/tmp/nanocoder-verify is not trusted. Pass --trust-directory to bypass the disclaimer for this run only, or set NANOCODER_TRUST_DIRECTORY=1 to trust this directory permanently.
exit=1
$ nanocoder --version
1.32.0
exit=0
Proposed fix
A small change, limited to the two fast paths:
- Only look for
-v/--versionand-h/--helpin the arguments beforerun. Prompt words afterrunare left alone, the same rule #2313 applies to--acp/--continue/--resume. - Keep
nanocoder --version,nanocoder -v,nanocoder --helpandnanocoder -hworking exactly as today. - Add integration cases to
source/cli-value-flags.cli-integration.spec.ts:run go test -vandrun grep -h fooreach the run path;--versionand--helpbeforerunstill print and exit 0.
The fix doesn't overlap any open PR: #2313's changes start further down in cli.tsx, and #2300 only edits the help text.
Questions before I start
nanocoder run --help/nanocoder run -hwith no other prompt words: should these keep printing the top-level help? My plan is to keep that behaviour, but only when the flag is the only thing afterrun.- Sharing code with #2313: #2313 adds a
preRunArgsslice for the same purpose. Would you rather I wait for it to merge and reuse that, or land this on its own with a small helper that #2313 can adopt later? - Scope: should this stay limited to
run? The sameargs.includescheck also lets a stray-h/-vwin for other subcommands, but I haven't verified those cases, so I'd leave them out unless you want them included.
@addyCooks, could you assign this to me? I'd like to open the PR once we agree on the questions above.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
Duplicate search: open and closed issues and PRs for "version flag", "help flag", "prints the version", "run prompt flag", "hijack" and "exit 0 without". #266 (closed) added --version/--help. #2308 and open PR #2313 cover the --acp/--continue/--resume and value-flag half of the run-prompt rule, but not lines 76/258.
I'm picking this up. Plan: make the --version/-v and --help/-h fast paths in source/cli.tsx only look at arguments before run, so option-looking tokens in the run prompt stay prompt text (consistent with KNOWN_RUN_FLAGS and the rule in cli-args.ts), with tests for the cases in the table.
Thanks @SamanPandey-in, confirmed on current main: nanocoder run go test -v, run node --version and run grep -h foo print the version or help and exit 0 instead of running the prompt (cli.tsx lines 76 and 258 check the whole argv).
Answers to your questions:
- Yes, keep
nanocoder run --help/run -hprinting the help when the flag is the only thing afterrun. - Land it on its own with a small helper; #2313 can adopt it later.
- Keep this limited to
run. If the same pattern bites other subcommands, we'll track that separately.
Assigning this to you @SamanPandey-in, since you asked first. @gugamorato-svg, please don't open a PR before you've been assigned the issue; comment first and wait for the assignment. You opened #2319 for this before it was assigned, so please coordinate with Saman here, or close #2319 if Saman is going to open the PR.