GitHub Event Streams and gh event listen: Stop Polling Pull Requests in Scripts and AI Agents
What Is GitHub Event Streams?
Every CI script and coding agent that opens a pull request eventually has to wait: for checks, for a reviewer, for a conflict to clear. Until now that meant a polling loop. You called gh pr view every 30 seconds, burned rate limit, and in an AI agent burned tokens on every check.
On November 17, 2026 GitHub put Event Streams into preview. You subscribe to a pull request, keep a connection open, and GitHub pushes an event when something changes. In GitHub's words, an agent "sleeps while there's no work and wakes as soon as there is."
A day later, on November 18, GitHub announced that GitHub CLI v2.105.0 adds a gh event command group that wraps it. GitHub's changelog post is titled Wait for pull request events with GitHub CLI.
Unlike webhooks, there is no public endpoint to host. The Event Streams documentation describes the transport as Server-Sent Events (SSE), so it runs from a laptop, a CI job or an agent sandbox.
Before You Start: Preview Limits
Read these first, because several will decide whether you can use it at all:
- Waitlist only. Sign up at gh.io/event-streams-signup. Requests from an account that isn't enabled get
403"Event subscriptions are not enabled for this account." - Pull requests only, and only on GitHub.com. Not GHE.com, and not GitHub Enterprise Server.
- One PR per subscription. A subscription expires 24 hours after creation, and you can have up to 100 active per user, app or installation token.
- No replay. Events arrive only while a stream is open, and you can get duplicates or receive them out of order.
- It may change. It's a public preview, and the docs warn of breaking changes "with short notice."
The docs list the accepted tokens: personal access tokens, OAuth tokens, GitHub App user tokens and GitHub App installation tokens. The account or installation needs read access to the pull request. Apps authenticating as themselves aren't supported.
On the enablement model, an app installation token works when the org it's installed on is enabled. That includes GITHUB_TOKEN inside Actions.
The Five Event Types
Event Streams sends signals that something changed, not what changed. The docs say to fetch the event's api_url for details. These are the types:
| Event type | Fires when |
|---|---|
com.github.pull_request.review.submitted.v1 |
A review is submitted (approve, request changes or comment) |
com.github.pull_request.state.changed.v1 |
The PR is merged, closed, reopened, marked ready, or converted to draft |
com.github.pull_request.head.changed.v1 |
The head commit changes, for example after a push |
com.github.pull_request.merge_conflict.v1 |
GitHub detects a merge conflict |
com.github.pull_request.check_suite.status.changed.v1 |
A check suite on the head commit completes, whatever the result |
Three caveats from the docs:
- No "all checks done" event. Each check suite fires separately, so you still query the PR's check suites to decide whether everything has finished.
- Conversation comments are silent. A comment on the Conversation tab produces no event. Review comments and replies to them do, as review events.
- Conflict events can lag. Conflict detection runs only after someone views or requests the PR.
Using gh event listen
Update GitHub CLI to v2.105.0 or later, then run gh event --help to confirm you have the command group. According to the gh event listen manual, the command creates a subscription, opens the stream, and prints each event to stdout as one line of CloudEvent JSON. Status messages go to stderr.
By default it exits after the first event. That one behaviour is what makes it fit scripts so well.
Wait for a review
gh event listen \
--resource https://github.com/OWNER/REPO/pull/42 \
--event com.github.pull_request.review.submitted.v1 \
--timeout 10m
--timeout takes seconds or a duration such as 30s or 10m. When it runs out, the command exits with status 8, so a script can tell "timed out" apart from "event arrived".
Get the next check-suite result
gh event listen \
--resource https://github.com/OWNER/REPO/pull/42 \
--event com.github.pull_request.check_suite.status.changed.v1 \
--jq .data.conclusion
Check suite events always include data.conclusion. It is one of success, failure, neutral, cancelled, timed_out, action_required, stale, skipped, startup_failure or unknown. If you're new to jq filters, try your expression in the jq playground first.
Watch several events until stopped
gh event listen \
--resource https://github.com/OWNER/REPO/pull/42 \
--follow \
--event com.github.pull_request.merge_conflict.v1,com.github.pull_request.head.changed.v1
The other flags:
--count <n>exits after n events.-t, --templateformats output with a Go template.--subscription <id>reuses an existing subscription.gh event subscription create|list|view|deletemanages subscriptions directly.
A wait-for-CI loop for an agent or script
Here's the pattern I'd use in an agent's "push, then wait" step. It waits on events instead of sleeping, re-checks the real state after each event (the docs recommend this, since events carry no detail), and treats exit code 8 as a timeout:
#!/usr/bin/env bash
set -u
PR="https://github.com/OWNER/REPO/pull/42"
while true; do
gh event listen --resource "$PR" \
--event com.github.pull_request.check_suite.status.changed.v1 \
--timeout 30m --jq .data.conclusion
rc=$?
if [ "$rc" -eq 8 ]; then echo "timed out waiting for checks" >&2; exit 1; fi
if [ "$rc" -ne 0 ]; then echo "gh event listen failed ($rc)" >&2; exit "$rc"; fi
# Events say *something* changed; ask GitHub for the current state.
pending=$(gh pr checks "$PR" --json bucket --jq '[.[] | select(.bucket=="pending")] | length')
[ "$pending" = "0" ] && break
done
gh pr checks "$PR"
The bucket field on gh pr checks is how I read pending checks with current gh; it isn't part of the Event Streams docs. Run gh pr checks --help to confirm them on your version.
GitHub says gh pr create, gh pr view, gh run view, gh run watch and gh api now suggest gh event listen instead of polling. Agents that follow CLI hints should pick it up without extra prompting.
Using the REST API Directly
If you're not in a shell, the Event Streams docs list these endpoints on api.github.com:
| Method | Route | Purpose |
|---|---|---|
POST |
/event-subscriptions |
Create a subscription |
GET |
/event-subscriptions |
List active subscriptions |
GET |
/event-subscriptions/{id} |
Get one |
DELETE |
/event-subscriptions/{id} |
Delete one |
GET |
/event-subscriptions/{id}/events |
Open the SSE stream |
To create a subscription:
gh api -X POST /event-subscriptions \
-f resource_url=https://github.com/OWNER/REPO/pull/NUMBER \
-f 'event_types[]=com.github.pull_request.review.submitted.v1' \
-f 'event_types[]=com.github.pull_request.state.changed.v1'
The response includes an events_url. Open it with a client that streams. The docs point out that gh api buffers the full response, so use curl -N:
curl -sS -N -H 'Accept: text/event-stream' \
-H "Authorization: Bearer $TOKEN" \
"$EVENTS_URL"
Each SSE message has an id, an event (the type name) and a data line holding the full CloudEvent as JSON. To read one comfortably, paste it into the JSON prettifier. When the stream is idle, the server sends a comment line starting with : at least every 15 seconds. Ignore those.
Handle the end of a stream properly
The server closes a stream with a final github.stream.end event. Branch on data.outcome, not on the optional reason:
subscription_ended: the subscription expired or you lost access. Stop, and create a new subscription if you still need one.reconnect: reopen the same subscription. Back off with jitter, and refresh your token first if it might have expired.
If the connection drops without that event, reconnect.
The docs add two token gotchas. Installation tokens expire after an hour, and their streams end at the next access check after that. And GITHUB_TOKEN can't be renewed, so delete the subscriptions it created before the Actions job ends. Also note that deleting a subscription does not close streams that are already open; close the stream first.
Where This Fits
For a coding agent, this turns "check the PR every minute for an hour" into one blocking call. It costs no tokens while it waits and nothing in rate limit. For CI glue, such as auto-merge bots or "ping me when review lands" scripts, it removes the need to host a webhook receiver.
The 24-hour expiry and the lack of replay mean it isn't a replacement for webhooks in long-running services yet. But for the wait-on-one-PR case it's the cleanest option GitHub has shipped. While you're updating your GitHub tooling, also look at workflow lockfiles and the npm package firewall.
