Skip to content

fix: point runner sessions at the GitHub MCP tools when gh isn't usable - #16

Draft
rfay wants to merge 1 commit into
mainfrom
20261117_rfay_gh_runner_auth
Draft

rfay wants to merge 1 commit into
mainfrom
20261117_rfay_gh_runner_auth

Conversation

@rfay

@rfay rfay commented Nov 17, 2026

Copy link
Copy Markdown
Member

Short Summary (TL;DR)

In Claude Code self-hosted runner sessions, gh is the machine's own CLI, either not signed in or signed in as the workspace owner, so the REST fallback from #15 never triggers there. This tells agents to check gh against the session's account and use the GitHub MCP tools otherwise, and makes the scripts say so instead of failing with gh's own sign-in advice.

The Issue

github-rest.md said self-hosted runners provide a REST-only gh. In Claude Code 2.1.322 runner sessions the per-session shim exists but isn't on the Bash tool's PATH, so gh resolves to /usr/bin/gh. On a workspace nobody signed in, every gh command, gh api included, fails with "To get started with GitHub CLI, please run: gh auth login" and never prints "GitHub GraphQL is not available", so the skills' trigger for github-rest.md doesn't fire. On a workspace whose owner ran gh auth login, gh acts as that owner for every session, including sessions other claude.ai accounts start. The session's system prompt points at the GitHub MCP tools instead.

How This PR Solves The Issue

  • github-rest.md gets a "Self-hosted runners" section: compare gh api user with the MCP get_me account, use the GitHub MCP tools when gh isn't signed in or is another account, and never run gh auth login, gh auth switch or set GH_TOKEN/GITHUB_TOKEN in a shared runner workspace. A table maps pr-context.sh, mentions.sh, failed-job.sh and the gh pr/gh issue/pending-review steps to MCP tools. The REST material stays, under "Cloud sessions: REST only".
  • The review, commit and ci-failure skills send runner sessions, and any session whose gh isn't signed in, to that file first. ci-failure's table no longer tells runner sessions to run gh auth login.
  • pr-context.sh and mentions.sh stop with a message naming the MCP tools and github-rest.md when gh is missing or exits with status 4, gh's "authentication required" status, instead of falling through to REST requests that fail the same way. Other GraphQL failures still fall back to REST.
  • failed-job.sh replaces its gh auth status preflight, which a REST-only gh may not support, with the same status-4 check on its first request, and gives the MCP tools as the runner alternative. On a Buildkite URL it skips the GitHub history when gh is missing or signed out, instead of failing after printing the build.

Manual Testing Instructions

With an empty gh config, so the machine's sign-in isn't touched:

mkdir -p ~/tmp/ghcfg
env -u GH_TOKEN -u GITHUB_TOKEN GH_CONFIG_DIR=~/tmp/ghcfg plugins/ddev/skills/review/pr-context.sh 15 ddev/agent-skills
env -u GH_TOKEN -u GITHUB_TOKEN GH_CONFIG_DIR=~/tmp/ghcfg plugins/ddev/skills/ci-failure/failed-job.sh https://github.com/ddev/agent-skills/actions/runs/44103475708

Each exits 1 with the MCP pointer. With a signed-in gh, both print as before, and a gh stub that fails gh api graphql with status 1 still gets the REST output.

Automated Testing Overview

claude plugin validate . and shellcheck 0.11.0 pass. I ran pr-context.sh, mentions.sh and failed-job.sh signed out, signed in, with no gh on PATH, and with GraphQL stubbed to fail. I didn't find a public Buildkite build to run the signed-out Buildkite path end to end. Cloud sessions weren't re-checked; the REST-only description of them is unchanged from #15.

Release/Deployment Notes

None; installs pick up the latest commit.


Generated by Claude Code

## Short Summary (TL;DR)

In Claude Code self-hosted runner sessions, `gh` is the machine's own CLI, either not signed in or signed in as the workspace owner, so the REST fallback from #15 never triggers there. This tells agents to check `gh` against the session's account and use the GitHub MCP tools otherwise, and makes the scripts say so instead of failing with gh's own sign-in advice.

## The Issue

- For ddev/coder-ddev#246

`github-rest.md` said self-hosted runners provide a REST-only `gh`. In Claude Code 2.1.322 runner sessions the per-session shim exists but isn't on the Bash tool's `PATH`, so `gh` resolves to `/usr/bin/gh`. On a workspace nobody signed in, every `gh` command, `gh api` included, fails with "To get started with GitHub CLI, please run: gh auth login" and never prints "GitHub GraphQL is not available", so the skills' trigger for `github-rest.md` doesn't fire. On a workspace whose owner ran `gh auth login`, `gh` acts as that owner for every session, including sessions other claude.ai accounts start. The session's system prompt points at the GitHub MCP tools instead.

## How This PR Solves The Issue

- `github-rest.md` gets a "Self-hosted runners" section: compare `gh api user` with the MCP `get_me` account, use the GitHub MCP tools when `gh` isn't signed in or is another account, and never run `gh auth login`, `gh auth switch` or set `GH_TOKEN`/`GITHUB_TOKEN` in a shared runner workspace. A table maps `pr-context.sh`, `mentions.sh`, `failed-job.sh` and the `gh pr`/`gh issue`/pending-review steps to MCP tools. The REST material stays, under "Cloud sessions: REST only".
- The review, commit and ci-failure skills send runner sessions, and any session whose `gh` isn't signed in, to that file first. ci-failure's table no longer tells runner sessions to run `gh auth login`.
- `pr-context.sh` and `mentions.sh` stop with a message naming the MCP tools and `github-rest.md` when `gh` is missing or exits with status 4, gh's "authentication required" status, instead of falling through to REST requests that fail the same way. Other GraphQL failures still fall back to REST.
- `failed-job.sh` replaces its `gh auth status` preflight, which a REST-only `gh` may not support, with the same status-4 check on its first request, and gives the MCP tools as the runner alternative. On a Buildkite URL it skips the GitHub history when `gh` is missing or signed out, instead of failing after printing the build.

## Manual Testing Instructions

With an empty gh config, so the machine's sign-in isn't touched:

```bash
mkdir -p ~/tmp/ghcfg
env -u GH_TOKEN -u GITHUB_TOKEN GH_CONFIG_DIR=~/tmp/ghcfg plugins/ddev/skills/review/pr-context.sh 15 ddev/agent-skills
env -u GH_TOKEN -u GITHUB_TOKEN GH_CONFIG_DIR=~/tmp/ghcfg plugins/ddev/skills/ci-failure/failed-job.sh https://github.com/ddev/agent-skills/actions/runs/44103475708
```

Each exits 1 with the MCP pointer. With a signed-in `gh`, both print as before, and a `gh` stub that fails `gh api graphql` with status 1 still gets the REST output.

## Automated Testing Overview

`claude plugin validate .` and shellcheck 0.11.0 pass. I ran `pr-context.sh`, `mentions.sh` and `failed-job.sh` signed out, signed in, with no `gh` on `PATH`, and with GraphQL stubbed to fail. I didn't find a public Buildkite build to run the signed-out Buildkite path end to end. Cloud sessions weren't re-checked; the REST-only description of them is unchanged from #15.

## Release/Deployment Notes

None; installs pick up the latest commit.

Generated with Claude Code (https://claude.com/claude-code)

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

rfay commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Another session reworked the same files from a brief that conflicts with this PR in one place. The work is a local commit only, not pushed: 20261117_rfay_gh_auth_fallback (1b0a61d) on claude1-rfay.

Where they conflict

A gh signed in as a different account. This PR has agents compare gh api user with the MCP get_me account, and use the MCP tools when they differ. The other brief says that with a login, the agent uses gh normally, GraphQL included. Reasoning:

  • A personal runner whose owner ran gh auth login is the normal setup, and the one the maintainers use. There, gh acting as the owner is what the owner wants. Comparing accounts doesn't help, and on that setup it pushes agents to the MCP tools, which reach only attached repositories.
  • The MCP account and the gh account can differ for harmless reasons, such as a bot or a second account that's attached to claude.ai. A mismatch alone doesn't show that gh is wrong to use.
  • The risk this PR guards against, other claude.ai accounts' sessions acting as the owner on a shared workspace, comes from how the runner is set up. It's a runner-operator issue (coder-ddev docs), not something each skill should detect.

Where they agree

  • Don't tell agents to run gh auth login, gh auth switch, or set GH_TOKEN/GITHUB_TOKEN.
  • Without a sign-in, use the GitHub MCP tools, and say that they reach only the repositories attached to the session.
  • The scripts stop with that advice instead of passing on gh's error, and failed-job.sh skips the Buildkite history without gh.

Smaller differences

  • Detection: this PR checks for exit status 4 on the first request. The local commit runs gh auth status, and also accepts a gh that answers gh api user, in case a REST-only gh doesn't support auth status. Either works. Status 4 saves a request.
  • README: this PR leaves "In Claude Code cloud and self-hosted sessions, gh passes on only gh api REST requests" in place. The local commit corrects it.
  • MCP table: this PR maps the scripts and the gh pr/gh issue steps to MCP tools. The local commit doesn't, and the table is worth keeping.

Options

  1. Update this PR: drop the account comparison, keep the MCP table and status-4 handling, and fix the README.
  2. Replace this PR's content with the local commit, and add the MCP table back to it.
  3. Keep this PR as it is, if shared multi-user runners are the case it should handle. Then fix the README too.

Generated by Claude Code

@stasadev
stasadev self-requested a review November 25, 2026 17:18

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scripts work as described. Two things before merge: the account comparison (inline) and the README.

README.md:19 still says that in Claude Code self-hosted sessions gh passes on only gh api REST requests. That now contradicts github-rest.md.

Claude Code ran pr-context.sh, mentions.sh and failed-job.sh on this branch and on main: signed in, signed out, with no gh on PATH, and with gh api graphql stubbed to fail. Signed in, the output matches main. Signed out or without gh, each stops with the MCP pointer instead of falling through to REST, and the stub still gets REST. It also ran the signed-out Buildkite path on a failed build (ddev-windows-mutagen 6759): this branch prints the build and the "skipped" line, main exits 4 after the build. Every MCP tool and method in the table exists in github-mcp-server v2.3.0.

🤖 Reviewed with assistance from Claude Code

it acts as that account for every session on the machine, including
sessions other people start.

Before using `gh` there, compare `gh api user --jq .login` with the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with your option 1 and drop the account comparison. On a personal runner where the owner signed gh in, which is how we use them, a mismatch with the claude.ai GitHub account sends the agent to the MCP tools. Those see only attached repositories and have nothing like mentions.sh, so reviews get worse in the common case. Keeping other people's sessions off a shared runner seems like a job for the runner setup (coder-ddev docs).

# buildkite/<pipeline> to GitHub, so read the history from there.
gh_repo=$(jq -r '.pipeline.provider.url // "" | sub("^https://github.com/"; "")' "$out/build.json")
[ -n "$gh_repo" ] || return 0
command -v gh > /dev/null || return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing: without gh this skips the history silently, while signed out it prints the "skipped" line. Maybe print the same line here?

@rfay

rfay commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

With a little more time on this, I see that claude normally has a gh shim that isn't powerful enough, but it's a shim. I'm not 100% sure we should add this, as the complexities are actually different than thought. I'll make this draft for now.

@rfay
rfay marked this pull request as draft November 25, 2026 18:48
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.

3 participants