From 3bbcdb958c787a2917de8e844f3d1d5ee264c9c4 Mon Sep 17 00:00:00 2001 From: shhhhhhjokerist <104197119+shhhhhhjokerist@users.noreply.github.com> Date: Tue, 10 Nov 2026 10:30:33 +0800 Subject: [PATCH] docs: keep PAT references literal so hosts expand them at connect The "With an environment variable" examples in the Claude Code installation guide and the README expanded GITHUB_PAT in the shell before passing it to the client: claude mcp add github -- docker run -i --rm \ -e GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PAT ... That puts the token value in the process arguments and in whatever configuration the client saves, which is exactly what the installation guide is trying to avoid. Both hosts expand ${VAR} themselves in command, args, env, url and headers when they connect, so pass the reference through unexpanded instead: - Linux/macOS and Docker examples export GITHUB_PAT first and then use single quotes: -e 'GITHUB_PERSONAL_ACCESS_TOKEN=${GITHUB_PAT}' and -H 'Authorization: Bearer ${GITHUB_PAT}'. - The PowerShell example quotes each argument with '...' and uses $env:GITHUB_PAT, which the shell does not expand either. The remaining examples (Windows legacy cmd, the plain docker -e form, and the "paste the token" alternatives) are unchanged because they either cannot reference an environment variable at all or intentionally inline the value. Bash keeps a command in history exactly as typed, so the surrounding notes now say that shell expansion exposes the token in process arguments and saved configuration, not in shell history. --- README.md | 8 +++++--- docs/installation-guides/install-claude.md | 15 +++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 432541f434..571f641ad1 100644 --- a/README.md +++ b/README.md @@ -225,13 +225,15 @@ To keep your GitHub PAT secure and reusable across different MCP hosts: 3. **Reference the token in configurations** + Quote the value when you add the server so the host expands `${GITHUB_PAT}` when it connects. Letting the shell expand it instead writes the token into the process arguments and the saved configuration: + ```bash # CLI usage - claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PAT -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server + claude mcp add github -e 'GITHUB_PERSONAL_ACCESS_TOKEN=${GITHUB_PAT}' -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server - # In config files (where supported) + # In config files (where the host supports environment variable expansion) "env": { - "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT" + "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PAT}" } ``` diff --git a/docs/installation-guides/install-claude.md b/docs/installation-guides/install-claude.md index 04658c4520..6f130df803 100644 --- a/docs/installation-guides/install-claude.md +++ b/docs/installation-guides/install-claude.md @@ -40,14 +40,15 @@ claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/ With an environment variable (Linux/macOS): ```bash export GITHUB_PAT="$(grep '^GITHUB_PAT=' .env | cut -d '=' -f2-)" -claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp","headers":{"Authorization":"Bearer '"$GITHUB_PAT"'"}}' +claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp","headers":{"Authorization":"Bearer ${GITHUB_PAT}"}}' ``` +Single quotes keep `${GITHUB_PAT}` literal in the stored configuration, and Claude Code expands it when it connects. Expanding it in the shell instead would put the token in the process arguments and the saved config. With an environment variable (Windows PowerShell): ```powershell $githubPatLine = Get-Content .env | Select-String "^\s*GITHUB_PAT\s*=" | Select-Object -First 1 $env:GITHUB_PAT = ($githubPatLine.Line -split "=", 2)[1].Trim().Trim('"').Trim("'") -claude mcp add-json github "{`"type`":`"http`",`"url`":`"https://api.githubcopilot.com/mcp`",`"headers`":{`"Authorization`":`"Bearer $env:GITHUB_PAT`"}}" +claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp","headers":{"Authorization":"Bearer ${GITHUB_PAT}"}}' ``` > **About the `--scope` flag** (optional): Use this to specify where the configuration is stored: @@ -80,7 +81,8 @@ claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=YOUR_GITHUB_PAT -- docker With an environment variable: ```bash -claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=$(grep GITHUB_PAT .env | cut -d '=' -f2) -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server +export GITHUB_PAT="$(grep '^GITHUB_PAT=' .env | cut -d '=' -f2-)" +claude mcp add github -e 'GITHUB_PERSONAL_ACCESS_TOKEN=${GITHUB_PAT}' -- docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server ``` 2. Restart Claude Code 3. Run `claude mcp list` to see if the GitHub server is configured @@ -112,7 +114,8 @@ claude mcp add --transport http github https://api.githubcopilot.com/mcp -H "Aut With an environment variable: ```bash -claude mcp add --transport http github https://api.githubcopilot.com/mcp -H "Authorization: Bearer $(grep GITHUB_PAT .env | cut -d '=' -f2)" +export GITHUB_PAT="$(grep '^GITHUB_PAT=' .env | cut -d '=' -f2-)" +claude mcp add --transport http github https://api.githubcopilot.com/mcp -H 'Authorization: Bearer ${GITHUB_PAT}' ``` #### Windows (PowerShell) @@ -120,8 +123,8 @@ claude mcp add --transport http github https://api.githubcopilot.com/mcp -H "Aut If you see `missing required argument 'name'`, put the server name immediately after `claude mcp add`: ```powershell -$pat = "YOUR_GITHUB_PAT" -claude mcp add github --transport http https://api.githubcopilot.com/mcp/ -H "Authorization: Bearer $pat" +$env:GITHUB_PAT = "YOUR_GITHUB_PAT" +claude mcp add github --transport http https://api.githubcopilot.com/mcp/ -H 'Authorization: Bearer ${GITHUB_PAT}' ``` ---