Repository navigation
Conversation
The official github plugin's MCP server sends
`Authorization: Bearer ${GITHUB_PERSONAL_ACCESS_TOKEN}` with no OAuth fallback,
so an unset variable is a bare "Bearer " and HTTP 400. The image now sets it from
`gh auth token`, whose OAuth token that endpoint accepts, so no personal access
token has to be created. A token already in the environment (including an
injected repo-scoped one in the sandbox) wins; with no login nothing is exported.
Baked into the image as /etc/profile.d/github-mcp-token.sh, sourced from both
~/.zshrc and ~/.bashrc, so VS Code's user env probe carries it into the
extension host. No postCreateCommand step, so nothing can race the extension's
sign-in (#58).
Refs #118 (part 2).
…gin path gh auth token already prefers GH_TOKEN, then GITHUB_TOKEN, then hosts.yml, so the snippet's own branches go; --hostname github.com keeps a GH_HOST pointing at GHE from exporting an enterprise token. verify-image.sh now checks a gh login on disk through both rc files with printenv (export- sensitive, no SC2016). The README says where the token ends up and when to reload, and allowed-domains.txt gets a commented api.githubcopilot.com.
# Conflicts: # claude-code/.devcontainer/Dockerfile
gatezh
changed the base branch from
master
to
claude-code/bash-shell-and-disk-prune
November 27, 2026 20:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Both
claude-codeimages setGITHUB_PERSONAL_ACCESS_TOKENfrom the container'sghlogin, so the MCP server of the officialgithub@claude-plugins-officialplugin works without a personal access token. Resolves part 2 of #118.Why
The plugin's
.mcp.jsonsendsAuthorization: Bearer ${GITHUB_PERSONAL_ACCESS_TOKEN}and has no OAuth fallback. With the variable unset it sends a bareBearer, and every request fails with HTTP 400 (Authorization header is badly formatted).#118 (2c) says a PAT is unavoidable. That isn't so:
api.githubcopilot.com/mcp/accepts thegho_OAuth token thatgh auth tokenprints. Probed: HTTP 200 oninitialize, andclaude mcp listshows Connected. Claude Code 2.1.332 expandsGITHUB_PERSONAL_ACCESS_TOKENin a remote server's headers; it isn't on the list of credential variables Claude Code reads as empty. No PAT is created or stored.Design
Chosen: a snippet baked into the image.
/etc/profile.d/github-mcp-token.shis copied in thesharedstage, and~/.zshrcand~/.bashrcsource it. zsh never reads/etc/profile.d, and terminals are non-login shells, so the image wires both rc files. VS Code's user environment probe (loginInteractiveShellby default) carries the export into the extension host. This covers both targets and every consumer with no template change. It makes noclaudecalls, so it can't race the extension's sign-in (fix(devcontainer): theme, login, node_modules isolation, self-contained claude-code config #58).Rejected: Claude Code's native
headersHelper. A helper that runsgh auth tokenwould keep the token out of every process's environment, and it picks up a new login without a reload. A user-scope server with one was probed and connects. It has no image-level home, though:managedMcpServersrefuses entries withheadersHelperor${VAR}.managed-mcp.jsontakes exclusive control and blocks plugin servers..mcp.jsonis upstream and has only static headers.It would need a per-project
claude mcp add-jsonstep outside the plugin system, and installing the official plugin the usual way would still give 400s.Rejected: a per-project
postCreateCommandscript. The default template has nopostCreateCommandon purpose (fix(devcontainer): theme, login, node_modules isolation, self-contained claude-code config #58), and the snippet is the same for every consumer.Rejected:
remoteEnvwith${localEnv:GITHUB_PERSONAL_ACCESS_TOKEN}(claude-code: CLAUDE_CODE_OAUTH_TOKEN over-specified as Required; no path for plugins needing a personal token (github MCP) #118's suggestion). It needs a token on the host, which is the PAT this avoids.The snippet is a single
gh auth token --hostname github.comcall. gh already prefersGH_TOKEN, thenGITHUB_TOKEN, then its stored login.--hostnamekeeps aGH_HOSTthat points at GHE from exporting an enterprise token. A non-emptyGITHUB_PERSONAL_ACCESS_TOKENalready in the environment wins. An empty one, as${localEnv:...}gives for an unset host variable, counts as unset. With no token and no login, nothing is exported.Changes
claude-code/.devcontainer/github-mcp-token.sh(new): sourced, committed100755per the repo rule, installed0644.claude-code/.devcontainer/Dockerfile: COPY into/etc/profile.d, and source it from both rc files, in thesharedstage after the other baked scripts.claude-code/verify-image.sh: with a throwawayhosts.yml,zsh -icandbash -icboth export the login's token (checked withprintenv, so the variable must be exported). With no login, the snippet exports nothing, not even an empty value.claude-code/README.md: a "GitHub MCP server" section under Git and GitHub Authentication. It covers how to add the plugin and how the token is found. It says the token is in the environment of every process, including the agent's Bash tool and any approved project MCP server, and that the window needs a reload after a login or token change. It also covers the sandbox'sapi.githubcopilot.comallowlist entry, which the GitHub ranges don't cover. The "Both targets" list mentions the new file.claude-code/.devcontainer/claude-sandbox/allowed-domains.txt: a commentedapi.githubcopilot.comentry, in the same style as the other plugins' entries.Notes
headersHelper, for the reasons above. It puts theghtoken in every shell's environment. Anything running asnodecould already read~/.config/gh/hosts.yml, so the added exposure is small. In the sandbox the token is the repo-scoped fine-grained one.verify-image.sh defaultpassed inside the publishedclaude-code:latest, with the snippet mounted and the rc lines appended as the Dockerfile does. It fails when the~/.bashrcline is removed. Probed precedence:GH_TOKENbeatsGITHUB_TOKENbeats the login; an empty value falls through;GH_HOST=GHE still exports the github.com token;bash -licexports it. Hadolint v2.12.0: no findings on master or the branch.shellcheck: clean. I didn't build the image locally; CI builds it and runsverify-image.sh.gh auth tokenadds about 50 ms, and only to shells where the variable isn't already set. VS Code terminals inherit it from the probed environment.CLAUDE_CODE_OAUTH_TOKENdescribed as Required) is separate and not touched here.Troubleshooting.md("Claude Code authentication", line 72) says there is no documented path for plugins that need a personal token. After merge, point it at the README's "GitHub MCP server" section.