Variadic --allowedTools option consumes positional prompt argument
Bug Description
claude --print --allowedTools "Bash" "my prompt" fails because --allowedTools is defined as a variadic option (<tools...>) which greedily consumes all subsequent positional arguments, including the prompt.
Repro
# Fails - prompt gets consumed by --allowedTools (hangs waiting for stdin)
claude --print --allowedTools "Bash" "my prompt"
# Works - prompt via stdin avoids the variadic consumption
echo "my prompt" | claude --print --allowedTools "Bash"
# Works - no variadic flag present
claude --print "my prompt"
Root Cause
In the Commander.js option definition, --allowedTools <tools...> uses variadic syntax. Commander's variadic options consume all remaining arguments after the flag, so the trailing positional prompt argument gets swallowed into the allowedTools array instead of being recognized as the [prompt] program argument.
Suggested Fix
Option 1 (Recommended): Require comma-separated values instead of variadic
Change --allowedTools <tools...> to --allowedTools <tools> and split on commas internally. This is already supported per the help text ("Comma or space-separated list") so just drop the variadic ... from the option definition and parse commas in the handler.
Same fix applies to other variadic options: --disallowedTools, --tools, --betas, --add-dir, --mcp-config, --plugin-dir.
Option 2: Reorder argument parsing
After parsing, if the prompt positional is empty and the last element of allowedTools doesn't look like a tool name, pop it off and use it as the prompt.
Option 3: Document the limitation
At minimum, note in --help that variadic flags must come after the prompt, or that stdin should be used when combining --print with variadic flags.
Environment
- Claude Code version: Latest
- OS: macOS (Darwin 24.5.0)
Workaround
Use stdin for the prompt when combining with variadic flags:
echo "my prompt" | claude --print --allowedTools "Bash"This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗