Boundlayer
GitHub CLIAI Coding AgentsEvent-Driven ArchitectureCI/CDDeveloper Workflows

GitHub Event Streams for Coding Agents: Replace Pull Request Polling Safely

Use GitHub CLI event streams to coordinate coding agents with PR reviews and CI checks, while accounting for preview access, missed events, timeouts, and authoritative state validation.

8 min read

By BoundLayer Engineering Team

BoundLayer is a senior engineering partner for SaaS, fintech, AI automation, cloud infrastructure, legacy modernization, Web3, IoT, GPU computing, and data systems.

Coding agents often create a pull request and then poll GitHub for a review, a new commit, or completed checks. GitHub CLI now offers another option: gh event listen can wait for pull request events and print them as JSON lines. It can make an agent workflow more responsive and reduce repeated status reads, but it is not a durable job queue and it does not remove the need to verify the pull request's current state.

GitHub Event Streams and the gh event commands are in preview. Access is limited to enabled accounts on GitHub.com, and the feature may change. Treat it as a useful interaction primitive for bounded agent sessions, not as the only source of truth for release-critical automation.

What the CLI can wait for

With GitHub CLI v2.105.0 or later, gh event listen accepts a pull request URL and event types. It opens a subscription, listens for events, and writes each event to stdout as a CloudEvent JSON object. By default, it exits after the first event; --count, --follow, and --timeout control how long it waits.

The current CLI manual lists events for submitted reviews, pull request state and head changes, merge conflicts, and completed check suites. For example:

gh event listen \
  --resource "$PR_URL" \
  --event com.github.pull_request.review.submitted.v1 \
  --timeout 30m

This is a better fit than repeatedly asking for the same PR state when an agent has completed a bounded action and is waiting for a human or CI. It also gives the workflow a clear timeout instead of an unbounded loop.

Treat events as wake-up signals, not decisions

An event tells the agent that something changed. It should not be treated as a complete, authoritative snapshot of everything the agent needs to decide. After an event arrives, query the current PR or check state and evaluate the repository's actual branch protections and required checks.

This distinction matters for CI. A pull request may have multiple check suites, each producing its own completion event. One green suite does not mean all required checks have passed. After a check-suite event, refresh the aggregate check state with the CLI or API and continue only when the required checks for the current head commit are satisfied.

Likewise, a review event may be stale relative to a new push, or a PR may have been closed while the agent was waiting. Re-read the PR's current head SHA, state, review decision, and checks before taking any consequential action. Never merge solely because one event says a check completed; let branch protection and explicit policy remain the authority.

Close the listener startup race

GitHub documents that earlier events are not replayed. If a review arrives just before the listener is attached, that event will not be delivered to the new listener. A robust loop therefore combines event listening with a fresh state read:

  1. Start the listener and confirm it reports that the stream is attached.
  2. Read the current PR and check state.
  3. If the desired condition is already true, continue without waiting.
  4. Otherwise, wait for a relevant event, then read current state again.
  5. On timeout, reconnect, or process restart, repeat the state read before deciding what to do.

The state query closes the gap between “the event has already happened” and “the listener is ready.” It also makes duplicate or irrelevant notifications harmless: the workflow's next step is determined by the latest resource state, not by the number of events received.

Account for disconnects and expiring subscriptions

The CLI automatically reconnects if a stream breaks, but events that occur while disconnected are not delivered. The manual also says subscriptions expire after 24 hours and that each account has a limit on active subscriptions. A listener can therefore improve a live session without providing durable, replayable delivery.

For an interactive coding agent, a sensible pattern is to wait for a bounded period, refresh the PR state on timeout, and let a human resume the task if the session ends. For a release pipeline or a multi-hour business process, use a durable orchestrator or a webhook-backed service with persisted state, retries, deduplication, and reconciliation. Event Streams can be a trigger in such a design only if the surrounding system can recover from missed delivery.

Keep event handling narrow and safe

The event stream's stdout contains JSON lines, while status messages go to stderr. Keep those channels separate when composing shell scripts or agent tools. Parse only the fields needed, such as event type and the changed resource URL, and fetch the canonical resource through the authenticated CLI. Treat event content and PR-authored text as untrusted input; do not turn it into shell commands or broaden an agent's permissions based on event data.

Limit listeners to the PR and event types required for the task. Apply a timeout, handle the documented timeout exit status separately from a successful event, and clean up subscriptions when a workflow no longer needs them. Keep the agent's GitHub identity scoped to the minimum operations it needs, and keep merge, deployment, and other consequential actions behind normal repository protections and human approval where appropriate.

Where this fits in an agent workflow

Event Streams are useful at the boundary between an agent's work and external collaboration: wait for a requested review, notice that a branch changed, or respond after checks complete. They do not replace CI, required status checks, review policies, or a durable orchestration layer.

A practical division of responsibility is:

  • the agent proposes code and opens or updates a pull request;
  • GitHub branch protection defines what is required before merge;
  • gh event listen wakes a bounded agent session when a relevant PR event arrives;
  • the agent re-reads canonical state and summarizes what changed;
  • humans or approved automation decide whether to merge or deploy.

BoundLayer builds AI-assisted engineering workflows with explicit permission boundaries, reliable CI gates, and human control over production changes. For related patterns, see our AI SDLC workflow guide, AI agent evaluation guide, and production MCP security guide.

Sources

Building agents around your software delivery workflow?

We help teams connect coding agents to CI and collaboration tools without weakening review, access, or deployment controls.

Free consultation

Get a Free 30-Minute Technical Consultation

Share a few details about your project and we'll get back to you within 48 hours with a clear next step.

  • No sales pressure — a senior engineer, not a sales rep
  • Clear next step within 48 hours
  • We can sign an NDA before we talk

By submitting, you agree to be contacted about your request. We respect your privacy and can sign an NDA on request.