CLI: --mcp-config must come before -p due to variadic argument parsing

Resolved 💬 3 comments Opened Jan 3, 2026 by jackccrawford Closed Jan 6, 2026

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

  1. Require explicit termination for variadic args
  2. Use comma-separated instead of space-separated for multiple configs
  3. 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗