[BUG] /pr-comments fails with 404 when headRepository.nameWithOwner is empty

Resolved 💬 2 comments Opened Mar 12, 2026 by NadavLor Closed Apr 9, 2026

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

  1. Run /pr-comments #<PR_NUMBER> on any repository
  2. The command runs gh pr view --json headRepository and gets:

``json
{"headRepository": {"id": "...", "name": "repo-name", "nameWithOwner": ""}}
``

  1. API calls are constructed with empty owner/repo → HTTP 404

Suggested Fix

Don't rely on headRepository.nameWithOwner. Instead, use one of:

  1. gh repo view --json nameWithOwner -q '.nameWithOwner' (always works)
  2. Construct from headRepositoryOwner.login + headRepository.name:

``bash
gh pr view --json headRepositoryOwner,headRepository \
--jq '"\(.headRepositoryOwner.login)/\(.headRepository.name)"'
``

Environment

  • Claude Code (latest)
  • macOS
  • gh CLI v2.x

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗