[BUG] /pr-comments fails with 404 when headRepository.nameWithOwner is empty
Description
The built-in /pr-comments slash command fails with HTTP 404 errors when fetching PR comments from the GitHub API. The command constructs API URLs using headRepository.nameWithOwner from gh pr view --json headRepository, which returns an empty string "".
Root Cause
This is actually an upstream gh CLI bug. In cli/cli source (api/query_builder.go), the GraphQL query for headRepository only requests id and name:
case "headRepository":
q = append(q, `headRepository{id,name}`)
But the Go struct PRRepository declares a NameWithOwner field that is never populated by the query — so it zero-values to "". The GitHub GraphQL API would return it correctly (String! non-null) if it were included in the selection set.
This means /pr-comments will fail for every repository, not just private ones — nameWithOwner is always empty.
Steps to Reproduce
- Run
/pr-comments #<PR_NUMBER>on any repository - The command runs
gh pr view --json headRepositoryand gets:
``json``
{"headRepository": {"id": "...", "name": "repo-name", "nameWithOwner": ""}}
- API calls are constructed with empty owner/repo → HTTP 404
Suggested Fix
Don't rely on headRepository.nameWithOwner. Instead, use one of:
gh repo view --json nameWithOwner -q '.nameWithOwner'(always works)- Construct from
headRepositoryOwner.login+headRepository.name:
``bash``
gh pr view --json headRepositoryOwner,headRepository \
--jq '"\(.headRepositoryOwner.login)/\(.headRepository.name)"'
Environment
- Claude Code (latest)
- macOS
ghCLI v2.x
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗