Pull-based GitHub webhook relay for coding agents. Part of ratchet-stack.
A GitHub App pushes webhooks to a small AWS Lambda + DynamoDB table (1-day TTL), and agents pull matching events through the CLI (wait, tail, serve) or the MCP server (wait_for_events, get_events) using a cursor they own.
GitHub App webhook -> Lambda -> DynamoDB (1-day TTL) <- agent (wait / tail / mcp / serve)
Webhooks push to DynamoDB and agents pull from it instead of a true webhook push model:
- Batching and turn efficiency. Delivering every webhook straight to an agent would trigger a turn per event, many irrelevant or part of a burst. Agents have to filter and batch anyway (
waitandwait_for_eventslet a burst settle before returning). - Resuming after disconnects or usage limits. Events stay buffered in DynamoDB for one day and each consumer owns its cursor, so an agent that disconnects, restarts, or hits a usage limit picks up where it left off (or gets
gap: truepast retention). - Tolerates CLI and agent disconnects. Pull needs no always-on connection or public callback endpoint, so network drops, sleeps, and process restarts do not lose events.
- No control plane. One Lambda function URL and one DynamoDB table with TTL — ~$0.12–$4.80/month on DynamoDB On-Demand (default), or $0/month on AWS Always Free tiers with
PROVISIONED25/25 (cost model). Stores a filterable envelope plus optional payload for every subscribed event and comment, with no command allowlist. Payload text is untrusted input.
See docs/design.md for the full architecture, envelope schema, and trust model.
hook-harness wait blocks until matching events arrive (and settle), prints one JSON object ({events, gap, cursor, timedOut?}), and exits 0. hook-harness tail streams matches as NDJSON.
--on adds named filter presets (repeatable or comma lists; OR'd with other filters). The MCP tools take the same names as on.
| Preset | Matches |
|---|---|
ejection |
Merge-queue ejection (pull_request dequeued with a failure reason, not MERGE) |
main-failure |
Failed workflow_run, or another App's check_suite (not Actions'), on main |
dependabot-pr |
Dependabot opened or reopened a PR |
review-requested, review-requested:<login|team> |
A review was requested (from that reviewer) |
label:<name> |
That label was added to an issue or PR |
/<command> |
A new comment starting with that command, e.g. /shepherd |
workflow:<name>[@<branch>] |
A run of that Actions workflow finished (any conclusion), e.g. workflow:Publish@main |
deployment, deployment:<environment>[@<branch>] |
A deployment finished (success, failure or error), e.g. deployment:production; @<branch> needs a deployer that sends a branch, not a SHA, as the ref |
release, release:<tag> |
A release was published (with that tag) |
status:<context> |
A commit status from external CI finished, e.g. status:ci/circleci: build |
hook-harness wait --owner acme --on ejection,main-failure,dependabot-pr,/shepherd --on label:needs-review --no-payload- Custom filters: combine field flags (
--event,--action,--branch,--command,--label,--pr,--min-association, etc.) or pass repeatable--filter '<json>'objects. Runhook-harness wait --helpfor all flags. - Multiple owners:
--owner acme,acme-labspolls each owner under one cursor (the token's repo scope must cover every owner). - Provenance:
authorAssociationandauthorcome from the webhook. Private org members appear asCONTRIBUTORorNONE, so verify membership via the GitHub API before privileged actions (see docs/github-app.md).
Several agents on one machine can share a single relay poller. serve polls the relay once and fans events out over Server-Sent Events; wait and tail read from it with --source (or HOOK_HARNESS_SOURCE).
hook-harness serve --owner acme,acme-labs --cursor relay # 127.0.0.1:7391
hook-harness wait --source http://127.0.0.1:7391 --cursor plan --event pull_request --command /plan
curl -N 'http://127.0.0.1:7391/events?event=push&branch=main'GET /eventsstreams per-client filtered envelopes withLast-Event-ID(or?after=) replay from a 1000-event / 1-hour ring buffer and an explicitgapevent if a client falls behind.GET /healthzreports{ok, upstream: {lastPollAt, lastError, cursor}, clients, buffered}.- Loopback only by default; non-loopback requires
--allow-remoteand--auth-token(Authorization: Bearer). Details in docs/design.md.
hook-harness mcp runs a stdio MCP server so agents consume events as tools. Log in first with hook-harness login (or set HOOK_HARNESS_URL and HOOK_HARNESS_TOKEN).
# Claude Code
claude mcp add hook-harness -- npx -y hook-harness mcp# Codex (~/.codex/config.toml)
[mcp_servers.hook-harness]
command = "npx"
args = ["-y", "hook-harness", "mcp"]| Tool | What it does |
|---|---|
wait_for_events |
Blocks like wait (timeout_seconds default 240, max 600; settle_seconds default 5) and returns a JSON batch. |
get_events |
One non-blocking poll; returns {events, gap, cursor}. |
filter_help |
Returns EventFilter fields and examples. |
The server is stateless: pass the returned cursor back as after (or pass cursor_name to use a local cursor file). owner accepts a comma list; gap: true means sweep the GitHub API to catch up. Keep timeout_seconds under your client's tool-call cap (e.g. MCP_TOOL_TIMEOUT in Claude Code).
To read events in-process instead of starting the CLI, add hook-harness as a dependency and import hook-harness/client (ESM, Node 24+; its types need @types/node). This export is a stable contract: a breaking change to it ships as a major version.
import { pollEvents, resolveClient } from "hook-harness/client";
const client = await resolveClient(); // saved `hook-harness login`, or HOOK_HARNESS_URL / HOOK_HARNESS_TOKEN
for await (const batch of pollEvents({
...client,
owner: ["acme", "acme-labs"],
on: ["ejection"],
signal,
})) {
if ("error" in batch) continue; // transient: retried with backoff (count these to detect an outage)
handle(batch.events);
save(batch.cursor); // pass back as `after` to resume
}| Export | What it does |
|---|---|
resolveClient(env?) |
Returns {url, token} from client.json (hook-harness login), with HOOK_HARNESS_URL / HOOK_HARNESS_TOKEN overriding each field. Throws NotLoggedInError when either is missing. |
fetchEventsPage(options) |
One GET /events request; returns the EventsPage (events, cursor, more, gap) as the relay sent it. Pages repeat events from the 60 seconds before after, and filters past 50 entries or 4000 characters are not sent, so filter and dedupe yourself or use pollEvents. after wins over since; with neither, reads from the start of the 24h retention. |
pollEvents(options) |
Long-polls one owner or several until signal aborts. Yields {owner, events, cursor, gap} once per owner's poll (empty or not): each event once, only events matching filters/on; gap is that owner's. With several owners, cursor covers all of them. It uses the same format as hook-harness wait's, so either can resume the other, single- or multi-owner. Each owner starts at its position in after, else since, else now. |
pollPages(options) |
The raw page loop under pollEvents, for one owner: yields {page} per poll, follows a cut-short page at once. |
Options: url (https:, or http: only to localhost, 127.0.0.1 or [::1]; anything else throws TypeError so the token is never sent in cleartext), token, owner (pollEvents also takes an array), and optionally repos, filters (EventFilter[]), on (preset names as --on takes them), payload (default true), after, since (Date), limit, signal, fetch, and for the pollers intervalMs (default 5000) and delay. An unknown preset throws TypeError. A pollEvents after that is not a cursor from pollEvents or wait/tail throws InvalidCursorError; fetchEventsPage passes after to the relay as is, so a bad one there is a BadRequestError.
HTTP errors carry status:
UnauthorizedError(401) andOutOfScopeError(403, withownerand the token'sscopeswhen the relay names them) extendAuthError. Retrying cannot help, so the pollers throw them.BadRequestError(400) is a missingowneror a badafterorfilters, with the relay's reason in the message. It extendsRelayError, and the pollers throw it too.RelayErroris any other HTTP status. It and network errors (TypeError) are transient: the pollers yield{error}and retry with exponential backoff capped at 5 minutes, without end. There is no separate outage signal: count consecutive{error}batches, or bound the wait withsignal.- With several owners, an error the pollers throw stops every owner's poll.
- Aborting
signalends the pollers without yielding an error for the request it cut short.
Envelope, EventFilter and EventsPage are exported as types.
Requires Node 24+.
Installs the MCP server and the hook-harness skill from jongleberry/ratchet-stack:
# Claude Code
claude plugin marketplace add jongleberry/ratchet-stack
claude plugin install hook-harness@ratchet-stack
# Codex
codex plugin marketplace add jongleberry/ratchet-stack --ref main
codex plugin add hook-harness@ratchet-stacknpx hook-harness deploy # run any command without installing
pnpm add -g hook-harness # or install globally, then: hook-harness <command>- Deploy the relay with
hook-harness deploy(add CloudWatch alarms withhook-harness update --alarm-email you@example.com). - Create and install the GitHub App, then mint a scoped reader token (
hook-harness token create --repos '<org>/*' --login) — see docs/github-app.md.
~$0.12–$4.80/month on DynamoDB On-Demand (PAY_PER_REQUEST, the default) from a personal repo up to a 20,000-webhook/day org — or $0/month on AWS Always Free tiers with --billing-mode PROVISIONED (25/25). See docs/costs.md for the breakdown, On-Demand vs. Provisioned trade-offs, and knobs to cut spend.
- docs/design.md — architecture, relay endpoints, envelope,
serve, CLI, and package layout - docs/costs.md — AWS cost model, workload estimates, and tuning knobs
- docs/github-app.md — GitHub App setup, permissions, tokens, and trust notes
- docs/publishing.md — releasing
hook-harnessto npm
MIT