claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] ENABLE_EXPERIMENTAL_MCP_CLI is ignored when a prompt is passed as a command line argument

Open AndrewHannigan opened this issue 1 month ago • 3 comments

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?

Problem

The ENABLE_EXPERIMENTAL_MCP_CLI environment variable is being ignored when a prompt is passed to claude on the command line.

What Should Happen?

ENABLE_EXPERIMENTAL_MCP_CLI should be respected when a prompt is passed to claude on the command line.

Steps to Reproduce

In this example, we call claude without a command line prompt. You can see the subsequent /context shows no MCP context is loaded (as expected with the mcp-cli feature).

andrewhannigan:repro_mcp_cli_bug/ $ ENABLE_EXPERIMENTAL_MCP_CLI=true claude                                                                                                                                                                [23:45:01]

╭─── Claude Code v2.1.1 ─────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                    │ Tips for getting started                                          │
│                Welcome back Andrew!                │ Run /init to create a CLAUDE.md file with instructions for Claude │
│                                                    │ ───────────────────────────────────────────────────────────────── │
│                       ▐▛███▜▌                      │ Recent activity                                                   │
│                      ▝▜█████▛▘                     │ No recent activity                                                │
│                        ▘▘ ▝▝                       │                                                                   │
│                                                    │                                                                   │
│ Sonnet 4.5 (1M context) · API Usage Billing · TRM  │                                                                   │
│ Labs                                               │                                                                   │
│              ~/src/repro_mcp_cli_bug               │                                                                   │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

❯ /context
  ⎿   Context Usage
     ⛀ ⛁ ⛁ ⛁ ⛀ ⛀ ⛀ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   claude-sonnet-4-5-20250929[1m] · 18k/1000k tokens (2%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 2.8k tokens (0.3%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 15.0k tokens (1.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 322 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Skills: 11 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 8 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 937k (93.7%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛝ Autocompact buffer: 45.0k tokens (4.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝

     Memory files · /memory
     └ ~/.claude/CLAUDE.md: 322 tokens

     Skills and slash commands · /skills

     User
     └ psql: 11 tokens

In this example, we pass a prompt via the command line ("test" in this case). When we run /context we see that the MCP tools have been loaded into the context and are taking up significant tokens, which should not happen when using the mcp-cli.

andrewhannigan:repro_mcp_cli_bug/ $ ENABLE_EXPERIMENTAL_MCP_CLI=true claude "test"                                                                                                                                                         [23:45:22]

╭─── Claude Code v2.1.1 ─────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                    │ Tips for getting started                                          │
│                Welcome back Andrew!                │ Run /init to create a CLAUDE.md file with instructions for Claude │
│                                                    │ ───────────────────────────────────────────────────────────────── │
│                       ▐▛███▜▌                      │ Recent activity                                                   │
│                      ▝▜█████▛▘                     │ No recent activity                                                │
│                        ▘▘ ▝▝                       │                                                                   │
│                                                    │                                                                   │
│ Sonnet 4.5 (1M context) · API Usage Billing · TRM  │                                                                   │
│ Labs                                               │                                                                   │
│              ~/src/repro_mcp_cli_bug               │                                                                   │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

❯ test

⏺ Hello! I'm Claude Code, ready to help you with your software engineering tasks.

  I can assist you with:                                                                                                                                                                                                                                - Writing and debugging code
  - Exploring and understanding codebases
  - Running commands and tests
  - Working with git and GitHub
  - Querying databases (including Citus/Postgres via psql)
  - And much more!

  What would you like to work on today?

  (And remember to take breaks and get outside when you need to! 🌳)

❯ /context
  ⎿   Context Usage
     ⛀ ⛁ ⛁ ⛁ ⛁ ⛀ ⛀ ⛀ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   claude-sonnet-4-5-20250929[1m] · 24k/1000k tokens (2%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 2.8k tokens (0.3%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 15.3k tokens (1.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ MCP tools: 5.5k tokens (0.6%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 322 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Skills: 11 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 114 tokens (0.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 931k (93.1%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛝ Autocompact buffer: 45.0k tokens (4.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝

     MCP tools · /mcp
     └ mcp__groundcover__get_workloads: 329 tokens
     └ mcp__groundcover__logsql_query_logs: 256 tokens
     └ mcp__groundcover__query_traces: 984 tokens
     └ mcp__groundcover__get_k8s_infrastructure_list: 176 tokens
     └ mcp__groundcover__query_monitors_issues: 537 tokens
     └ mcp__groundcover__query_logs: 721 tokens
     └ mcp__groundcover__query_monitors: 415 tokens
     └ mcp__groundcover__get_k8s_object_yaml: 133 tokens
     └ mcp__groundcover__logsql_query_traces: 257 tokens
     └ mcp__groundcover__query_metrics: 800 tokens
     └ mcp__groundcover__query_events: 670 tokens
     └ mcp__groundcover__logsql_query_events: 259 tokens

     Memory files · /memory
     └ ~/.claude/CLAUDE.md: 322 tokens

     Skills and slash commands · /skills

     User
     └ psql: 11 tokens


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  [Sonnet 4.5 (1M context)] 25k/1000k (2%)                                                                                                                                                           Update available! Run: brew upgrade claude-code

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.2 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other

Additional Information

Using Ghostty with zsh

AndrewHannigan avatar Jan 09 '26 05:01 AndrewHannigan

Cc @catherinewu given announcement here

AndrewHannigan avatar Jan 09 '26 05:01 AndrewHannigan

@AndrewHannigan Thanks for posting, I have also experienced this bug today..

maxritter avatar Jan 09 '26 12:01 maxritter

@maxritter In case helpful: For now, I've switched to using ENABLE_TOOL_SEARCH=true instead which doesn't have this issue.

Since ENABLE_TOOL_SEARCH vs ENABLE_EXPERIMENTAL_MCP_CLI both accomplish similar goals but the former is GA and latter is experimental, it seems like CC team could be leaning towards ENABLE_TOOL_SEARCH as path forward. Interested in any additional context from CC team on this.

AndrewHannigan avatar Jan 11 '26 20:01 AndrewHannigan

@AndrewHannigan Thanks for the heads up! Makes sense but unfortunately I had some weird bugs with some of my MCP Servers and the Enable Search Tool approach, so I hope this gets fixed soon and I can continue using the awesome MCP CLI approach.

maxritter avatar Jan 12 '26 07:01 maxritter

Related Use Case: MCP Servers Not Initialized with Slash Commands

We've encountered this issue when launching Claude Code with slash commands that depend on MCP servers:

claude /work-linear-task
# Result: Linear MCP server doesn't initialize, command fails

Expected: MCP servers initialize before executing the slash command Actual: MCP servers don't initialize, tools unavailable

Workaround: Launch normally first, then run command:

claude          # Wait for init
/work-linear-task  # Then run command

This affects workflow automation that would benefit from direct CLI invocation like claude /command-name args.

Related: This appears to be the same root cause as the ENABLE_EXPERIMENTAL_MCP_CLI flag being ignored - initialization sequence doesn't complete before slash command execution.

Tracking in our project: https://linear.app/bbuc/issue/TKK-242

bbuc-ewoks avatar Jan 19 '26 07:01 bbuc-ewoks