--file is declared [array] and message is a positional [array], so yargs greedily pulls the message words into the file list when the flag comes first.
Reproduced on 1.18.11, clean node:24-alpine container, nothing else installed.
Fails:
$ opencode run --file /tmp/note.txt summarize this please
Error: File not found: summarize
Works, same arguments, message moved ahead of the flag:
$ opencode run summarize this please --file /tmp/note.txt
Hello file content.
opencode run --help shows why:
Positionals:
message message to send [array] [default: []]
Options:
-f, --file file(s) to attach to message [array]
Two things make this cost more time than it should. Flag-before-message is the natural order to write, and the error names the first word of the message, so it reads as "opencode cannot find my file" rather than "the argument order matters". Nothing points at the parse.
Workaround for anyone who lands here: insert -- before the message.
opencode run --file /tmp/note.txt -- summarize this please
Possible fixes, whichever matches your CLI conventions: nargs(1) on --file so it takes exactly one value per occurrence and repeats for multiple files, or requiresArg, or just documenting the -- in the help text.
I have carried a wrapper that injects the -- since 1.15.x, so this is long-standing rather than a recent regression. Happy to send a PR if you have a preference among those three.
--fileis declared[array]andmessageis a positional[array], so yargs greedily pulls the message words into the file list when the flag comes first.Reproduced on 1.18.11, clean
node:24-alpinecontainer, nothing else installed.Fails:
Works, same arguments, message moved ahead of the flag:
opencode run --helpshows why:Two things make this cost more time than it should. Flag-before-message is the natural order to write, and the error names the first word of the message, so it reads as "opencode cannot find my file" rather than "the argument order matters". Nothing points at the parse.
Workaround for anyone who lands here: insert
--before the message.Possible fixes, whichever matches your CLI conventions:
nargs(1)on--fileso it takes exactly one value per occurrence and repeats for multiple files, orrequiresArg, or just documenting the--in the help text.I have carried a wrapper that injects the
--since 1.15.x, so this is long-standing rather than a recent regression. Happy to send a PR if you have a preference among those three.