Skip to content

feat: gh-read, read-only gh with the owner's Coder GitHub login for runner sessions - #267

Merged
rfay merged 2 commits into
mainfrom
20261124_rfay_gh_read_wrapper
Nov 24, 2026
Merged

rfay merged 2 commits into
mainfrom
20261124_rfay_gh_read_wrapper

Conversation

@rfay

@rfay rfay commented Nov 24, 2026

Copy link
Copy Markdown
Member

The Issue

Claude Code runner sessions get a proxied gh and GitHub MCP tools that reach only the repositories attached to the session. Search works across GitHub, but reading an issue, PR, comment thread, file or CI run anywhere else fails with 403 ("GitHub access to this repository is not enabled for this session"). Recent examples were socktainer/socktainer and libracoder/kiri. add_repo can't fix it for third-party repositories, because API access needs the Claude GitHub App installed on them. Each person running gh auth login in their workspace would work, but it's setup every team member has to repeat, and it gives sessions a broad token.

How This PR Solves The Issue

  • New gh-read in ~/.local/bin: runs the real gh with the workspace owner's token from Coder's GitHub external auth (the one the Drupal templates already use for Composer), with an empty gh config dir. Every owner reads GitHub as themselves, with no gh auth login; linking GitHub once in Coder is enough.
  • It accepts only read commands: issue/pr view, list, diff, checks; search; repo/run/release/workflow view and list; api with GET, and GraphQL queries. It refuses other methods, -f/-F without -X GET, --input, GraphQL mutations, auth and everything else. This guards against mistakes; the token's real limits come from the GitHub App behind Coder's external auth. With the App not installed on any account, its user tokens can only read public repositories.
  • /etc/claude-code/CLAUDE.md tells every runner session to use gh-read for repositories outside the session, and to keep the session's own gh or MCP tools for writes. A managed permission rule allows Bash(gh-read:*).
  • Both are installed whenever the runner setting is on, even before the environment secret exists. The runner README explains it.

Manual Testing Instructions

  1. Push freeform and create a workspace with the runner enabled and an environment secret; link GitHub at <coder URL>/external-auth/github.
  2. In the workspace, gh-read issue list -R socktainer/socktainer -L 2 and gh-read pr diff 894 -R libracoder/kiri return data; gh-read pr comment 1 -R x/y -b hi is refused.
  3. Start a session in that environment and ask "Summarize the discussion on socktainer/socktainer PR 542 and list the five newest open PRs in libracoder/kiri", without mentioning gh-read.

Done on staging-coder.ddev.com (template version gh-read-3, combined with #266): the session used gh-read for all three GitHub calls with no permission prompt (auto mode), and never fell back to add_repo or WebFetch. Before linking GitHub, gh-read prints the link URL and exits.

Automated Testing Overview

None added. shellcheck passes on gh-read. terraform fmt and make validate weren't run here (no Terraform in this workspace); CI runs them.

Release/Deployment Notes

The runner README section that says a session's gh is the workspace's own gh is out of date (sessions now put a proxied gh first on PATH); that's left for a separate fix. This PR and #266 both touch managed_settings and the runner README, so the second to merge needs a small rebase.


Generated by Claude Code

…unner sessions

Claude Code runner sessions get a proxied gh and GitHub MCP tools that reach
only the repositories attached to the session, so reading issues, PRs and
comments in other repositories (socktainer/socktainer, libracoder/kiri)
fails with 403. gh-read runs the real gh with the token from Coder external
auth ("coder external-auth access-token github"), so each workspace owner
reads GitHub as themselves without gh auth login. It accepts only read
commands; /etc/claude-code/CLAUDE.md tells sessions to use it, and a managed
permission rule allows it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UrTUMxoyzqiN3JtHacV96S
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Previews

The start.coder.ddev.com landing-page preview has been removed. Read the Docs keeps or removes its own docs preview.

…de Coder

Self-hosted runners outside Coder, such as the macOS one, have no external
auth. There gh-read now takes a read-only token from the macOS Keychain item
gh-read-token, or from ~/.config/gh-read/token (mode 600), and finds gh in
/opt/homebrew/bin. Coder workspaces keep using the owner's Coder login.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UrTUMxoyzqiN3JtHacV96S
@rfay
rfay merged commit 7be7af6 into main Nov 24, 2026
21 checks passed
@rfay
rfay deleted the 20261124_rfay_gh_read_wrapper branch November 24, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants