Skip to content

claude-code: CLAUDE_CODE_OAUTH_TOKEN over-specified as Required; no path for plugins needing a personal token (github MCP) #118

Open

Description

@gatezh

Summary

Two related gaps around Claude Code authentication in the claude-code template, found while wiring the official github Claude Code plugin into a downstream project:

  1. CLAUDE_CODE_OAUTH_TOKEN in the sandbox is over-specified as "Required" and silently injects an empty string when the host variable is unset.
  2. There is no template support or guidance for plugins whose MCP server needs a personal token — the github plugin is the concrete case. It needs a host-provided env var plus a firewall allowlist entry, and neither has a home in the template today.

These are independently actionable; happy to split into two issues if you'd prefer.


Part 1 — CLAUDE_CODE_OAUTH_TOKEN is over-specified

claude-code/.devcontainer/claude-sandbox/devcontainer.json:125-127:

    // Required — the sandbox firewall blocks OAuth login, so the token must be
    // injected from the host. See "Sandbox Authentication" section in README.
    "CLAUDE_CODE_OAUTH_TOKEN": "${localEnv:CLAUDE_CODE_OAUTH_TOKEN}"

It is labelled Required, but it isn't required on the normal path. Both variants mount the same named volume at /home/node/.claude:

"source=myproject-claude-config-${localWorkspaceFolderBasename},target=/home/node/.claude,type=volume"

So if you sign in once in the default variant (VS Code Claude Code extension, or claude in a terminal), the credentials are already on disk when the sandbox starts. The token injection is only genuinely needed if someone uses the sandbox standalone, having never opened the default variant — which I'd guess is the rarer case.

The concrete problem

${localEnv:VAR} resolves to an empty string when the host variable is unset. Anyone who never ran claude setup-token therefore gets CLAUDE_CODE_OAUTH_TOKEN="" injected into every sandbox container, invisibly.

That appears harmless in practice — Claude Code documents that setting a variable to "" is "treated as unset for provider selection" — so this is a clarity bug, not a breakage. But the combination of a Required label, a claude setup-token workflow in the README, and an env var that is silently empty makes it very easy to conclude the token is load-bearing when it isn't. In our downstream project it had been carried for months, fully unused, and the comment was taken at face value in our own docs.

Verification

# Host variable is unset:
$ echo "[${CLAUDE_CODE_OAUTH_TOKEN}]"
[]

# The variable is still present in the container, as empty:
$ printenv CLAUDE_CODE_OAUTH_TOKEN | cat -A
$
# ...while `claude` works fine, authenticated from the shared volume:
$ ls /home/node/.claude/.credentials.json

Suggested fix

Keep the mechanism (it's the right escape hatch for standalone sandbox use), but re-describe it and make its optionality explicit:

    // Optional — only needed if you use the sandbox WITHOUT ever opening the default
    // variant. Normally credentials arrive on the shared /home/node/.claude volume:
    // sign in once in the default variant and the sandbox picks them up.
    // For standalone sandbox use the firewall blocks interactive OAuth, so inject a
    // token instead: generate with `claude setup-token`, export on the host.
    // NOTE: when the host var is unset this resolves to an empty string, which
    // Claude Code treats as unset.
    "CLAUDE_CODE_OAUTH_TOKEN": "${localEnv:CLAUDE_CODE_OAUTH_TOKEN}"

and adjust the README's "Sandbox Authentication" section to lead with the shared-volume path.

Affected files

  • claude-code/.devcontainer/claude-sandbox/devcontainer.json:125-127
  • README "Sandbox Authentication" section

Part 2 — Support plugins whose MCP server needs a personal token

The official github plugin (github@claude-plugins-official) ships this .mcp.json:

{"github": {"type":"http","url":"https://api.githubcopilot.com/mcp/",
  "headers":{"Authorization":"Bearer ${GITHUB_PERSONAL_ACCESS_TOKEN}"}}}

Three consequences for the template:

a) The token must reach the Claude Code process environment. .env-style files loaded by project dev scripts don't help — the VS Code extension never reads them. The canonical devcontainer mechanism is remoteEnv + ${localEnv:}, which per the spec is preferred over containerEnv for values that aren't static ("you can update its value without having to rebuild the full container") and reaches the VS Code server plus its terminals. Suggested addition to claude-code/.devcontainer/devcontainer.json (and the sandbox variant):

  "remoteEnv": {
    "GITHUB_PERSONAL_ACCESS_TOKEN": "${localEnv:GITHUB_PERSONAL_ACCESS_TOKEN}"
  }

Worth pairing with a README note recommending a host secret manager over a plaintext ~/.zshrc export, and flagging the same empty-string-when-unset caveat as Part 1.

b) The sandbox firewall blocks the MCP endpoint. api.githubcopilot.com needs an allowlist entry in init-firewall.sh. The GitHub IP ranges fetched from api.github.com/meta do not cover it. Same applies to other remote-MCP plugins — we also added mcp.linear.app and mcp.resend.com:

    "chatgpt.com" \
    "api.githubcopilot.com" \
    "mcp.linear.app" \
    "mcp.resend.com"; do

c) A PAT is unavoidable for this plugin. Worth stating in the README so people don't hunt for an OAuth path: GitHub's own OAuth login "applies to the stdio server only. The remote server and the http command have their own authentication" (docs/oauth-login.md), and the plugin hardcodes the Authorization header, which Claude Code does not let a user override for a plugin-provided MCP server.

I've left the plugin list itself out of scope, since init-plugins.sh is explicitly a project-customized starter — but a README pointer for "plugin needs a token → use remoteEnv, and allowlist its host in the sandbox" would save the next person the same dig.

Affected files

  • claude-code/.devcontainer/devcontainer.json (add remoteEnv)
  • claude-code/.devcontainer/claude-sandbox/devcontainer.json (add remoteEnv)
  • .devcontainer/claude-sandbox/init-firewall.sh (repo-root exemplar — allowlist MCP hosts)
  • README (plugin-token guidance)

Related

  • gh config volume #114 — persisting ~/.config/gh via a named volume. Adjacent: a persisted gh login is the other half of a good in-container GitHub story, and gh auth token is a plausible source for the PAT above.
  • Downstream implementation of both parts: done in a private project.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions