AI Moves

GitHub CLI Pull Request Events: Listen First, Then Check State

GitHub CLI can wait for pull request events. Check the current review and CI status when you connect, when an event arrives, or when the wait expires.

By NurevoFlow Editorial2 min read (estimate)
A dim workstation with two monitors and a closed notebook.

Image: AI-generated editorial illustration.

If an agent is waiting for a human review, it may keep asking GitHub the same question every minute: has the pull request changed yet? GitHub CLI now has a preview command that can wait for a specific pull request event instead. gh event listen can watch for a review, state change, new head commit, merge-conflict signal or completed check suite, then print each event as JSON. GitHub announced the command on November 18 for gh 2.105.0 and later. (GitHub Changelog, Event Streams guide)

Before trying it, check the preview gates: Event Streams access is waitlist-based, the current service is on GitHub.com rather than GHE.com, and your user or app installation needs read access to the pull request. Both Event Streams and gh event are previews that may change. (Event Streams guide)

In one terminal, a code-review agent can wait up to 30 minutes for a submitted review:

gh event listen \
  --resource https://github.com/OWNER/REPO/pull/42 \
  --event com.github.pull_request.review.submitted.v1 \
  --timeout 30m

GitHub does not replay changes that occurred before the stream opened. Once the listener prints “Listening for events” to stderr, use a second terminal to reconcile the pull request:

gh pr view 42 --repo OWNER/REPO --json state,reviewDecision,latestReviews,headRefOid

This ordering catches a review that landed just before the stream attached. If the review you needed already landed, stop waiting. Later, the event is a wake-up signal, not the review decision itself: fetch its API URL or inspect the pull request again to see whether the reviewer approved, requested changes or commented. A hypothetical agent can then stop polling on a timer while keeping its action tied to the current PR state. (Event Streams guide, gh event listen manual, gh pr view manual)

CI is a separate case. GitHub emits one event for each completed check suite, and one pull request can have several suites. A green event tells you about one suite. Run gh pr checks 42 --repo OWNER/REPO to inspect current CI status. GitHub says the stream excludes commit statuses created through the REST API. If a required check uses one, fetch that status separately. (Event Streams guide, gh pr checks manual)

When --timeout expires, gh event listen exits with status 8. That means the wait ended without a matching event; it does not mean a review was rejected or checks failed. Refresh the PR/check view and either start another bounded wait or hand the case to a person. If the preview is unavailable, periodic checks remain a fallback. (gh event listen manual, gh pr checks manual)

Sources

  1. Wait for pull request events with GitHub CLIRetrieved
  2. Using GitHub Event StreamsRetrieved
  3. gh event listenRetrieved
  4. gh pr viewRetrieved
  5. gh pr checksRetrieved