claude-code - 💡(How to fix) Fix [DOCS] `CLAUDE_CODE_SHELL_PREFIX` docs omit stdio MCP argument-preservation guidance [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56161Fetched 2026-05-05 05:56:35
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

Root Cause

That omission matters because stdio MCP servers are configured as exact command/argument arrays, and v2.1.128 fixed a bug where those arguments could be corrupted when the prefix was set and an argument contained spaces or shell metacharacters.

Code Example

#!/usr/bin/env bash
# log the command here if needed
exec "$@"
RAW_BUFFERClick to expand / collapse

Documentation Type

Unclear/confusing documentation

Documentation Location

https://code.claude.com/docs/en/env-vars

Section/Topic

CLAUDE_CODE_SHELL_PREFIX in Environment variables, plus the stdio MCP server startup guidance in MCP configuration

Current Documentation

The env vars page currently says:

CLAUDE_CODE_SHELL_PREFIX | Command prefix that wraps shell commands Claude Code spawns: Bash tool calls, hook commands, and stdio MCP server startup commands. Useful for logging or auditing. Example: setting /path/to/logger.sh runs each command as /path/to/logger.sh <command>

The MCP docs currently say:

claude mcp add [options] <name> -- <command> [args...]

and later:

Command arrays must match exactly - both the command and all arguments in the correct order

What's Wrong or Missing?

The docs say that CLAUDE_CODE_SHELL_PREFIX wraps stdio MCP startup commands, but they do not explain the argument-forwarding contract for that wrapper.

That omission matters because stdio MCP servers are configured as exact command/argument arrays, and v2.1.128 fixed a bug where those arguments could be corrupted when the prefix was set and an argument contained spaces or shell metacharacters.

Today the docs do not tell readers:

  • whether the original stdio command and its arguments are preserved as separate argv entries
  • how a logging/auditing wrapper should safely re-exec the wrapped command
  • that rebuilding the command as a shell string can break MCP server startup or exact serverCommand matching

Suggested Improvement

Add a short note to CLAUDE_CODE_SHELL_PREFIX and cross-reference it from the stdio MCP section.

Suggested content:

When CLAUDE_CODE_SHELL_PREFIX wraps a stdio MCP server startup command, the original command and arguments should be forwarded without flattening or re-quoting them. If your wrapper re-executes the command, pass the original argv through exactly.

Example wrapper guidance:

#!/usr/bin/env bash
# log the command here if needed
exec "$@"

Also add a warning not to use eval, $*, or unquoted expansions for wrappers that may handle arguments containing spaces or shell metacharacters.

Impact

Medium - Makes feature difficult to understand

Additional Context

Affected Pages:

PageLine(s)Context
https://code.claude.com/docs/en/env-vars137CLAUDE_CODE_SHELL_PREFIX says it wraps stdio MCP startup commands but does not explain argv preservation
https://code.claude.com/docs/en/mcp292-307, 1331-1338stdio servers are configured as <command> [args...] and command-based restrictions require exact argument matching

Total scope: 2 pages affected

Relevant release note: v2.1.128 fixed corrupted stdio MCP arguments when CLAUDE_CODE_SHELL_PREFIX was set and an argument contained spaces or shell metacharacters.

extent analysis

TL;DR

Update the documentation for CLAUDE_CODE_SHELL_PREFIX to clarify how it wraps stdio MCP server startup commands and provide guidance on safely re-executing the wrapped command.

Guidance

  • Add a note to the CLAUDE_CODE_SHELL_PREFIX documentation explaining that the original command and arguments should be forwarded without flattening or re-quoting them.
  • Provide an example of a safe wrapper script that passes the original argv through exactly, such as exec "$@".
  • Warn against using eval, $*, or unquoted expansions for wrappers that may handle arguments containing spaces or shell metacharacters.
  • Cross-reference the updated CLAUDE_CODE_SHELL_PREFIX documentation from the stdio MCP section.

Example

#!/usr/bin/env bash
# log the command here if needed
exec "$@"

Notes

The suggested improvement aims to clarify the documentation and prevent issues with MCP server startup or exact serverCommand matching. The example wrapper script demonstrates how to safely re-execute the wrapped command.

Recommendation

Apply the suggested documentation updates and wrapper guidance to ensure clear and safe usage of CLAUDE_CODE_SHELL_PREFIX with stdio MCP servers.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING