[BUG] Claude Code argument parser breaks with --plugin-dir and subcommand options

Resolved 💬 3 comments Opened Mar 12, 2026 by svd Closed Mar 12, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Claude Code argument parser breaks with --plugin-dir and subcommand options

Summary

When --plugin-dir is passed to Claude Code before a subcommand (like mcp add), Claude's argument parser incorrectly treats subcommand-specific options (like
--transport) as top-level options, resulting in "unknown option" errors.

Expected Behavior

When --plugin-dir is passed before a subcommand, Claude's parser should still recognize subcommand-specific options correctly. The command claude --plugin-dir
/path/to/plugin mcp add --transport http should behave identically to claude mcp add --transport http.

Actual Behavior

Claude's argument parser appears to reset its parsing context when --plugin-dir is encountered, causing subsequent subcommand options to be misinterpreted as top-level options.

What Should Happen?

When --plugin-dir is passed before a subcommand, Claude's parser should still recognize subcommand-specific options correctly. The command claude --plugin-dir /path/to/plugin mcp add --transport http should behave identically to claude mcp add --transport http.

Error Messages/Logs

error: unknown option '--transport'

Steps to Reproduce

  1. Without --plugin-dir (works correctly):

claude mcp add --transport http grep https://mcp.grep.app/

  1. Result: ✅ Command executes successfully
  2. With --plugin-dir before subcommand (fails):

claude --plugin-dir /path/to/plugin mcp add --transport http grep https://mcp.grep.app/

  1. Result: ❌ Error: error: unknown option '--transport'
  2. With --plugin-dir and -- delimiter (also fails):

claude --plugin-dir /path/to/plugin -- mcp add --transport http grep https://mcp.grep.app/

  1. Result: ❌ Treats --transport as a positional argument (creates MCP server named --transport)

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.74

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

Environment

  • Claude Code version: 2.1.74
  • Platform: macOS (Darwin 25.3.0)
  • Reproducible: Yes, consistently

Additional Context

This issue was discovered when integrating CodeMie CLI with Claude Code. The SSO provider's enrichArgs lifecycle hook prepends --plugin-dir to all Claude commands to load custom extensions. This breaks any Claude subcommand that accepts options (e.g., mcp add --transport, mcp list --json, etc.).

Possible Root Cause

The argument parser may be treating --plugin-dir as a "mode switch" that resets parsing state, or there may be an issue with how the parser handles option ordering when --plugin-dir appears before the first subcommand.

Workaround

Currently, the only workaround is to avoid using --plugin-dir when running commands that require subcommand-specific options. This is problematic for tools like CodeMie that need to inject the --plugin-dir flag for extension loading.

View original on GitHub ↗

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