CLI: --mcp-config must come before -p due to variadic argument parsing
Description
When using claude -p with --mcp-config, the argument order matters unexpectedly. The --mcp-config flag must come before -p, otherwise the prompt is incorrectly parsed as an MCP config file path.
Steps to Reproduce
# This fails - prompt is parsed as a config file path
claude -p --mcp-config /tmp/mcp-config.json "Use explore to get 1 memory"
# Error: Invalid MCP configuration:
# MCP config file not found: /Users/mars/.../Use explore to get 1 memory
# This works
claude --mcp-config /tmp/mcp-config.json -p "Use explore to get 1 memory"
# This also works (using -- separator)
claude -p --mcp-config /tmp/mcp-config.json -- "Use explore to get 1 memory"
Expected Behavior
Option order should not matter. Both of these should work identically:
claude -p --mcp-config config.json "prompt"
claude --mcp-config config.json -p "prompt"
Root Cause
The --mcp-config <configs...> flag is variadic (accepts multiple space-separated values). The parser appears to consume subsequent arguments as config paths until it hits a recognized flag. When -p comes first, the parser doesn't know where the config list ends, so it treats the prompt as another config file.
Suggested Fixes
- Require explicit termination for variadic args
- Use comma-separated instead of space-separated for multiple configs
- Improve error message to suggest using
--separator when the "config file" looks like a prompt
Environment
- claude-code version: 1.0.x (current)
- macOS arm64, Bun v1.3.5
🤖 Generated with Claude Code
Found 2 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/5593
- https://github.com/anthropics/claude-code/issues/2341
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
This issue has been automatically closed as a duplicate of #5593.
If this is incorrect, please re-open this issue or create a new one.
🤖 Generated with Claude Code
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.