docs(install-claude): "environment variable" examples put the PAT in argv and the saved config

未关闭 适合新手
#3,758 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
markdown

调研方向

从docs/installation-guides/install-claude.md中的命令示例和README.md中的令牌配置示例入手;比较两者如何将PAT传递给Claude Code。查看issue引用的Claude Code环境变量展开文档,确认受支持的语法。完成标准是,所有列出的环境变量示例在保存的配置中都保留变量引用,并且不再将PAT展开到命令参数中。

由索引模型根据 Issue 内容生成。

描述

Problem

Several Claude Code commands in docs/installation-guides/install-claude.md (and one in README.md) expand the personal access token in the shell before Claude Code runs, so the token ends up in the process argument list, in shell history, and as a literal value in the saved MCP configuration:

  • install-claude.md, "With an environment variable (Linux/macOS)": "Bearer '"$GITHUB_PAT"'" closes the single quotes so the shell substitutes the token into the claude mcp add-json argument.
  • install-claude.md, "With an environment variable (Windows PowerShell)": "Bearer $env:GITHUB_PAT" inside a double-quoted string, same effect.
  • install-claude.md, Docker "With an environment variable": -e GITHUB_PERSONAL_ACCESS_TOKEN=$(grep GITHUB_PAT .env | cut -d '=' -f2).
  • install-claude.md, legacy format: -H "Authorization: Bearer $(grep GITHUB_PAT .env | cut -d '=' -f2)", and the PowerShell variant $pat = "YOUR_GITHUB_PAT" followed by -H "Authorization: Bearer $pat".
  • README.md, "Reference the token in configurations": -e GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_PAT.

The sections are labelled "With an environment variable", but the stored configuration does not reference the variable; it holds the token itself.

Suggested fix

Claude Code expands ${VAR} references in an MCP server's url, headers, env, command, and args when it connects (Claude Code MCP docs, "Environment variable expansion"). Keeping the reference in single quotes stores ${GITHUB_PAT} literally, so the token stays in the environment and never reaches argv, history, or the config file. Minimal diff, against main at 99d6d6503a7b2a133e2f8a595d6d0ba24b4086d3:

--- a/README.md
+++ b/README.md
@@ -226,8 +226,8 @@
 3. **Reference the token in configurations**
 
    ```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
+   # CLI usage (single quotes: Claude Code expands ${GITHUB_PAT} at start-up, so the token stays out of argv and the saved config)
+   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)
    "env": {
--- a/docs/installation-guides/install-claude.md
+++ b/docs/installation-guides/install-claude.md
@@ -40,14 +40,16 @@
 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}"}}'

+The single quotes keep ${GITHUB_PAT} literal. Claude Code expands it from the environment when it connects, so the token stays out of the command line, shell history, and the saved configuration. Set GITHUB_PAT in the environment Claude Code starts from.
+
With an environment variable (Windows 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 +82,7 @@

With an environment variable:

-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
+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
  1. Restart Claude Code
  2. Run claude mcp list to see if the GitHub server is configured
    @@ -112,7 +114,7 @@

With an environment variable:

-claude mcp add --transport http github https://api.githubcopilot.com/mcp -H "Authorization: Bearer $(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 +122,7 @@
If you see missing required argument 'name', put the server name immediately after claude mcp add:

-$pat = "YOUR_GITHUB_PAT"
-claude mcp add github --transport http https://api.githubcopilot.com/mcp/ -H "Authorization: Bearer $pat"
+claude mcp add github --transport http https://api.githubcopilot.com/mcp/ -H 'Authorization: Bearer ${GITHUB_PAT}'


The placeholder variants (`YOUR_GITHUB_PAT`) are left as they are. I can open this as a pull request if that is easier to review.
主要语言
Go
星标
34.2k
派生
5.3k
平均合并
5 天 18 小时
30 天内合并 PR
13

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/github-mcp-server 的其他 Issue

查看 github/github-mcp-server 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。