claude-code - 💡(How to fix) Fix [BUG] MCP server env block in ~/.claude.json not passed to spawned MCP servers inside Dev Container [1 comments, 2 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#53144Fetched 2026-04-26 05:23:17
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

Error Message

Error Messages/Logs

Fix Action

Fix / Workaround

Workaround Add the env var to the Dev Container's remoteEnv (e.g. "OPENAI_API_KEY": "${localEnv:OPENAI_API_KEY}") so it's set process-wide and inherited by the spawned MCP server.

Code Example

The MCP server starts but the env var is empty. API calls fail with 401 UnauthorizedMissing bearer or basic authentication in header.

Verified manually in the container:


echo '{"jsonrpc":"2.0","id":1,"method":"initialize",...}' \
  | OPENAI_API_KEY="$KEY" codex mcp-server
…returns a normal init response. So the codex binary honors env-var auth fine — Claude Code just isn't passing the configured env block.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

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

What's Wrong?

Environment Claude Code: 2.1.119 VS Code: 1.116.0 Dev Containers extension: 0.454.0 Host: macOS, Docker Desktop 4.67.0, image mcr.microsoft.com/devcontainers/go:1.25 Steps to reproduce On host, configure an MCP server in ~/.claude.json with an env block containing a credential, e.g.:

"mcpServers": { "codex": { "type": "stdio", "command": "codex", "args": ["mcp-server"], "env": { "OPENAI_API_KEY": "sk-proj-..." } } } Bind-mount ~/.claude.json into a Dev Container so Claude Code in the container reads the same file. Open a Claude session inside the container and call a tool routed through the codex MCP server. Expected The MCP server starts with OPENAI_API_KEY set in its environment (same behavior as host).

Actual The MCP server starts but the env var is empty. API calls fail with 401 Unauthorized — Missing bearer or basic authentication in header.

Verified manually in the container:

echo '{"jsonrpc":"2.0","id":1,"method":"initialize",...}'
| OPENAI_API_KEY="$KEY" codex mcp-server …returns a normal init response. So the codex binary honors env-var auth fine — Claude Code just isn't passing the configured env block.

Workaround Add the env var to the Dev Container's remoteEnv (e.g. "OPENAI_API_KEY": "${localEnv:OPENAI_API_KEY}") so it's set process-wide and inherited by the spawned MCP server.

What Should Happen?

The MCP server starts with OPENAI_API_KEY set in its environment (same behavior as host).

Error Messages/Logs

The MCP server starts but the env var is empty. API calls fail with 401 Unauthorized — Missing bearer or basic authentication in header.

Verified manually in the container:


echo '{"jsonrpc":"2.0","id":1,"method":"initialize",...}' \
  | OPENAI_API_KEY="$KEY" codex mcp-server
…returns a normal init response. So the codex binary honors env-var auth fine — Claude Code just isn't passing the configured env block.

Steps to Reproduce

On host, configure an MCP server in ~/.claude.json with an env block containing a credential, e.g.:

"mcpServers": { "codex": { "type": "stdio", "command": "codex", "args": ["mcp-server"], "env": { "OPENAI_API_KEY": "sk-proj-..." } } } Bind-mount ~/.claude.json into a Dev Container so Claude Code in the container reads the same file. Open a Claude session inside the container and call a tool routed through the codex MCP server.

Claude Model

None

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.119

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

The issue can be fixed by adding the OPENAI_API_KEY environment variable to the Dev Container's remoteEnv configuration.

Guidance

  • The problem seems to be related to the environment variables not being passed correctly from the host to the Dev Container.
  • To verify, check the environment variables inside the container using printenv or env command.
  • As a workaround, add the OPENAI_API_KEY environment variable to the Dev Container's remoteEnv configuration, for example: "OPENAI_API_KEY": "${localEnv:OPENAI_API_KEY}".
  • This will set the environment variable process-wide and make it available to the spawned MCP server.

Example

No code snippet is provided as it's not necessary in this case, but the workaround can be applied by modifying the Dev Container configuration.

Notes

The issue might be related to how Claude Code handles environment variables when spawning new processes. The provided workaround should fix the issue, but it's unclear if this is a regression or a known limitation.

Recommendation

Apply the workaround by adding the OPENAI_API_KEY environment variable to the Dev Container's remoteEnv configuration, as it provides a straightforward solution to the problem.

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

claude-code - 💡(How to fix) Fix [BUG] MCP server env block in ~/.claude.json not passed to spawned MCP servers inside Dev Container [1 comments, 2 participants]