NewsCrawler.org

Letting Claude Code use gh in a devcontainer without GH_TOKEN in environment variables

Claude Codeにghを使わせても、GH_TOKENをコンテナの環境変数に置かないdevcontainer構成
Image: zenn.dev

A developer configured a devcontainer[1] so that Claude Code can create pull requests and issues through GitHub CLI without a token in the container's environment variables, since a token there would be displayed outright if Claude Code accidentally printed env. The real gh binary is installed outside PATH at /usr/local/lib/gh, and a wrapper script at /usr/local/bin/gh reads the token from /run/secrets/gh_token and exports GH_TOKEN[2] only to the gh process. Docker Compose passes the token file as a secret, and a tmpfs[3] mount covers the repository's .secrets/ directory so the token is not readable through the bind-mounted repository. In testing on a node:24-trixie base image with GitHub CLI 2.102.1, Docker 29.9.2, Docker Compose v5.6.1 and Claude Code 2.1.310, docker inspect showed neither GH_TOKEN nor GITHUB_TOKEN among the container's environment variables. The author notes what this cannot prevent: Compose mounts file secrets with world-readable 0444 permissions and gh auth token still prints the token, so the setup adds deny rules in .claude/settings.json and uses a Fine-grained PAT[4] limited to selected repositories with a 60-day expiry, though, as the Claude Code documentation states, Bash permission rules are not a security boundary.

Read the original zenn.dev

Sources

  • Zenn JA

    Claude Codeにghを使わせても、GH_TOKENをコンテナの環境変数に置かないdevcontainer構成

    6 likes4 bookmarks0 comments

Published: First seen: Читать по-русски

Open as a page