pollhook
v0.10.1
Published
GitHub webhook deliveries without webhooks: a local listener fed by REST API polling
Maintainers
Readme
pollhook
GitHub webhook deliveries without webhooks. pollhook polls the GitHub REST API with a read-only token and turns what it sees into GitHub-shaped events, so you can wait for CI, stream repository activity, or feed a webhook handler without admin rights, a public URL or a GitHub App.

Website: https://radomir.dev/pollhook/
Table of contents
- Install
- Quick start
- What you can do with it
- Configuration
- The daemon
- Rate limits
- Reading status
- CLI reference
- Limits
- How it compares
- Requirements
- Contributing
- License
Install
npm install -g pollhookor run it without installing: npx pollhook --help. Needs Node.js 22.13 or newer
(requirements).
Quick start
Authenticate. pollhook uses
POLLHOOK_TOKEN, then yourgh auth login, thenGH_TOKENorGITHUB_TOKEN. A token that can read the repository is enough; Projects v2 events also need theprojectscope, package eventsread:packages.Create the config:
pollhook init --repo owner/name --events workflow_run,pull_request,check_runThat writes
~/.config/pollhook/config.json(it refuses to overwrite one without--force). Add or remove repositories later withpollhook config add-repo owner/nameandpollhook config remove-repo owner/name; a running daemon picks the change up.pollhook config checkvalidates the file and prints the resolved interval and strategy of every event.Wait for things. The first command starts the daemon in the background by itself:
pollhook run 123456789 # exits 0 on success, 1 on failure pollhook checks 42 # every check on a pull request pollhook pr 42 --until merged pollhook emit --brief # live stream of deliveries
The first poll of each event only records current state, so you never get a replay of history. A wait on something that already finished returns immediately.
Exit codes for the wait commands: 0 success, 1 the thing failed, 8 timeout,
2 bad arguments or a daemon that could not be reached.
What you can do with it
- Wait in scripts and agents.
pollhook run,checks,pr,pagesandwait --event ... --match key=valueblock and exit with a meaningful code. Any number of waiters share one poller. - Watch a stream.
pollhook emitprints one JSON delivery per line;--briefprints one readable line per delivery. A config edit does not drop the stream, and if the daemon restarts or crashesemitreconnects with backoff and replays what it missed from the local store, printing each delivery once. - Feed a webhook handler. Set
deliver.urlto a loopback address and pollhook POSTs GitHub-shaped requests withX-GitHub-Event,X-GitHub-Deliveryand, with asecret, a realX-Hub-Signature-256.
Configuration
~/.config/pollhook/config.json (override with --config or POLLHOOK_CONFIG).
The daemon reloads it when the file changes or on SIGHUP; a broken edit is
reported as configError in pollhook status and the old config keeps running.
{
"$schema": "https://unpkg.com/pollhook/pollhook.schema.json",
"intervals": { "workflow_run": 10, "pull_request": 15 },
"strategies": { "workflow_run": "while-active" },
"repos": [
{
"repo": "owner/name",
"events": ["workflow_run", "pull_request", "check_run", "status"],
"intervalSeconds": 60,
"intervals": { "check_run": 120, "status": 120 }
}
],
"orgs": [{ "org": "my-org", "events": ["team", "membership"], "intervalSeconds": 300 }],
"deliver": { "url": "http://127.0.0.1:7345/hook", "secret": "change-me" },
"stateDir": "~/.local/state/pollhook"
}repos[].eventslists what to poll. Leave it out and every supported event is polled, which costs more requests; list only what you need.pollhook eventsshows every event with its minimum interval, and docs/events.md documents what each one can and cannot report.- Intervals resolve per event: the repository's
intervals, then the globalintervals, then the target'sintervalSeconds(default 60 for repositories, 300 for organisations). The adapter's own floor always wins, and no interval can be under 5 seconds. strategiespicksfixed(default) orwhile-active. Withwhile-activeonworkflow_run, polling relaxes to 30 seconds while every running workflow is still under half of its typical duration.orgscovers organisation-level events (team,membership,package,registry_package).packageTypesnarrows the package registries polled; the default is all six, and the narrowing applies to both package events.deliver.urlmust be loopback. The control socket is a unix socket at$XDG_RUNTIME_DIR/pollhook.sock, so pollhook opens no network port.$schemapoints editors at pollhook.schema.json, which autocompletes event names and flags typos while you type.pollhook initadds it for you, andpollhook config checkwarns about keys pollhook ignores.
The daemon
One background process does all the polling and serves every command over a unix
socket. You never have to start it: the first command that needs it launches it,
detached, with its log in ~/.local/state/pollhook/daemon.log, and says so on
stderr. A daemon started that way exits after 30 minutes with no connected client, so
a forgotten one does not spend your rate limit. Stop it any time with
pollhook stop.
pollhook daemonrun by hand never exits on its own, and neither does any daemon whose config has adeliver.url, since a webhook feed has to stay up.--no-autostartorPOLLHOOK_NO_AUTOSTART=1turns the automatic start off, and commands then fail with "cannot reach pollhook".- Only one daemon runs per state directory. A second one refuses to start, even when its socket path differs.
emitreconnects when the daemon goes away, but never restarts it.
Run it as a service
With systemd, copy contrib/pollhook.service to
~/.config/systemd/user/, make sure ExecStart points at your pollhook
(which pollhook), then:
systemctl --user daemon-reload
systemctl --user enable --now pollhook
journalctl --user -u pollhook -fThe unit keeps your home read-only except ~/.local/state.
Rate limits
GitHub caps each token at a number of API requests per hour (5,000 for a normal
token). That is a rate limit, not a charge: reading the API costs nothing, and
pollhook is free to run. A 304 Not Modified does not count against the limit, and
pollhook sends If-None-Match on every poll, so a quiet repository uses little of
it: a ten-minute run on one repository made 485 requests, 135 of them with bodies,
which is about 800 requests an hour counted against the limit. Every poll is delayed
by up to 10% at random, so targets that share an interval do not hit the API in
lockstep. When the remaining quota runs low the daemon stretches every interval (3x
under 15% remaining, 10x under 5%) and honours Retry-After. pollhook poke polls
immediately when you know something just happened.
Reading status
pollhook status prints one line per target:
owner/repo events=3 last_poll=... next_poll=... last_event=...
quota 4869/5000 remaining, resets ...
deliveries 60, waiters 0, streams 1, pid 1234error= is a transient failure that clears after a clean round. degraded= lists
adapters GitHub answered with 403 or 404 (a feature that is disabled, or a token
without access); they retry hourly. status --json has the reasons.
CLI reference
| Command | What it does |
| --- | --- |
| pollhook init [--repo OWNER/NAME]... [--events a,b] [--force] [--config PATH] | Writes a starter config and refuses to overwrite one. |
| pollhook config check [--config PATH] | Validates the config and prints the resolved interval and strategy per event. |
| pollhook config add-repo OWNER/NAME [--events a,b] [--interval N] [--config PATH] | Adds a repository to the config; a running daemon reloads it. |
| pollhook config remove-repo OWNER/NAME [--config PATH] | Removes a repository from the config. |
| pollhook daemon [--config PATH] [--idle-exit 30m] | Polls GitHub and serves consumers over a unix socket. |
| pollhook status [--json] | Shows last and next poll per target, quota, degraded adapters and waiters. |
| pollhook events | Lists every implemented event with its polling floor. |
| pollhook deliveries [--limit N] [--repo OWNER/NAME] | Prints recent deliveries from the state store. |
| pollhook emit [--brief] | Streams deliveries as JSON lines until stopped, reconnecting and replaying after a daemon restart. |
| pollhook run <run-id> [--repo OWNER/NAME] [--timeout 30m] | Waits for a workflow run and exits with its conclusion. |
| pollhook checks <pr> [--repo OWNER/NAME] [--timeout 30m] | Waits for every check on a pull request's head commit. |
| pollhook pr <pr> --until merged\|closed\|reviewed\|conflict [--repo OWNER/NAME] [--timeout 30m] | Waits for a pull request to reach a state. |
| pollhook pages <sha> [--repo OWNER/NAME] [--timeout 30m] | Waits for the Pages build of a commit. |
| pollhook wait --event EVENT [--match key=value]... [--repo OWNER/NAME] [--timeout 30m] | Waits for any delivery matching an event and optional field matches. |
| pollhook poke [--repo OWNER/NAME] | Polls now instead of waiting out the interval. |
| pollhook stop | Stops the running daemon. |
| pollhook cleanup | Reports that pollhook creates no webhooks. |
Flags:
pollhook init:--repo OWNER/NAMErepeatable, default a placeholder to edit;--events a,bcomma-separated event names, default workflow_run,pull_request;--forceoverwrite an existing file;--config PATHconfig file, default ~/.config/pollhook/config.jsonpollhook config check:--config PATHconfig file, default ~/.config/pollhook/config.jsonpollhook config add-repo:--events a,bcomma-separated event names, default workflow_run,pull_request;--interval Npoll interval in seconds;--config PATHconfig file, default ~/.config/pollhook/config.jsonpollhook config remove-repo:--config PATHconfig file, default ~/.config/pollhook/config.jsonpollhook daemon:--config PATHconfig file, default ~/.config/pollhook/config.jsonpollhook status:--jsonprints the raw status bodypollhook deliveries:--limit Nhow many to print, default 20;--repo OWNER/NAMEtargets one repositorypollhook emit:--briefone human line per delivery instead of the payloadpollhook run:--repo OWNER/NAMEtargets one repository;--timeout 30mhow long to waitpollhook checks:--repo OWNER/NAMEtargets one repository;--timeout 30mhow long to waitpollhook pr:--until STATEmerged, closed, reviewed or conflict;--repo OWNER/NAMEtargets one repository;--timeout 30mhow long to waitpollhook pages:--repo OWNER/NAMEtargets one repository;--timeout 30mhow long to waitpollhook wait:--event EVENTevent name, seepollhook events;--match key=valuerepeatable top-level field match;--repo OWNER/NAMEtargets one repository;--timeout 30mhow long to waitpollhook poke:--repo OWNER/NAMEtargets one repository
Exit codes: 0 success, 1 the waited-on run, check set or pull request failed, 8 timeout, 2 bad input or daemon unreachable.
Limits
Polling sees state, and a webhook is a history of transitions, so some things are permanently different:
- Transitions that leave no state behind are invisible: an object created and deleted between two polls, or a review submitted and dismissed before the next poll.
- Short-lived states can be coalesced. A run may go from
queuedtocompletedas a single delivery. senderis the authenticated user, not necessarily whoever acted.- GitHub App events (
installation*,marketplace_purchase) are out of scope on purpose: they need an App, and pollhook works with a plain token. GraphQL-only state (review thread resolution, project status updates) is not supported yet.
pollhook is also deliberately not a webhook tool. It never creates a webhook or
an App, and it does not wrap gh webhook forward, which needs a real webhook and
admin rights; the point is webhooks without webhooks. It is read-only: it never sends POST, PUT, PATCH or DELETE to GitHub,
and nothing listens on a network interface. Deliveries are at-least-once and
de-duplicated by fingerprint.
How it compares
gh webhook forwardand smee.io relay real events, but need a webhook and admin rights, and the webhook stays behind in the repository settings.- GitHub App delivery polling needs an App installed on the repository.
gh event listenis a waitlisted preview.- The Events API (
/repos/{owner}/{repo}/events) has no CI, check or deployment events, and GitHub documents its latency as "anywhere from 30s to 6h".
Requirements
- Node.js 22.13 or newer. The state store uses the built-in
node:sqlite, which is available without a flag from 22.13. pollhook has no native dependencies to compile. - A GitHub token that can read the repositories you watch, from
POLLHOOK_TOKEN,gh auth login, orGH_TOKEN/GITHUB_TOKEN. - GitHub.com. For a GitHub Enterprise Server host,
POLLHOOK_API_URLoverrides the API base URL; that path is untested. - Linux or macOS. Developed and tested on Linux; the control socket is a unix socket, so Windows is not supported yet.
On Node 22.13 specifically, Node itself prints ExperimentalWarning: SQLite is an
experimental feature once at startup. It is harmless, and pollhook hides it on
later Node versions.
Contributing
git clone https://github.com/radomir-dev/pollhook && cd pollhook
npm ci
npm run doctordoctor runs types, lint, format, architecture rules, dead-code detection, an
audit, the tests (vitest) with coverage floors, the generated-docs check, and the
build with a package check. CI runs the same command.
Mutation testing is separate because it takes a long time: npm run mutation runs
Stryker over src/ with the suite, and a weekly workflow uploads the HTML report.
Stryker cannot read TypeScript 7's compiler API, so stryker.config.json points
tsconfigFile at a file that does not exist to skip its tsconfig rewrite. Pull request titles must follow
Conventional Commits; releases, the changelog and the npm publish are automated
from them. Open work is in the issue tracker.
