/ratchet-backend:event-handlersfrom ratchet-backend
Use when writing or reviewing code that acts on an event or a state change - a serverless function, a queue consumer, a scheduled task, or a deploy or config hook - and above all one that sleeps or waits before it acts. React to the change instead of waiting a fixed time, de-duplicate by reading current state, and defer work the target is not ready for without losing it.
Ships in ratchet-backend. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Read every applicable AGENTS.md first. Repository-local policy overrides these defaults.
These rules are for code that runs in production. How a test waits for an event is in
ratchet-code:test-authoring. A GitHub Actions workflow follows
ratchet-github:github-actions-authoring, which applies the same rule to workflow steps.
Do not sleep or wait a fixed time before acting in a handler, a job, or a step. A fixed wait guesses how long something else takes:
# Wrong: guesses that other changes have settled after five minutes
def handler(event, context):
time.sleep(330)
redeploy(services_for(event))
Inside a handler, treat a sleep loop that reads remote state, or a provider's waiter, the same
way. It holds the handler idle until something else finishes. A timeout caps the cost but does
not make the wait event-driven. A workflow step follows ratchet-github:github-actions-authoring
instead.
def handler(event, context):
changed_at = parse_time(event.get("time")) # None when missing or unparseable
for service in services_for(event):
primary = primary_deployment(service)
if (changed_at is not None
and primary.created_at > changed_at
and primary.rollout_state in ("IN_PROGRESS", "COMPLETED")):
continue # the serving deployment started after the change and has not failed
redeploy(service)
Skip only on positive evidence that the work is done or under way: the deployment that will serve started after the change and is rolling out or has succeeded. A newer deployment that failed or rolled back, one that is not primary, or an event with no readable time or version is not that evidence, so act.
Make the action safe to repeat. The source can deliver an event twice or out of order, and the state read above is not a lock: two handlers can both read "not done" and both act. Key the action by target and event, or use an operation that is a no-op when its result already exists.
Size the timeout to the work. If a handler needs a longer timeout to fit a wait, remove the wait.
When a precondition is not met, such as a lease another process holds or a dependency that is not up yet, do not sleep and retry inside the handler. Defer the work without losing it:
Some delays are real requirements: a grace period before deleting, a debounce that turns a burst into one action, or a provider rate limit.
Before removing a delay, find why it was added: the commit, the pull request, and any incident it cites. When a reason exists, meet it with an event, a state check, or a scheduled delay. When none can be found, say so in the change and replace the delay with a state check.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub jongleberry/ratchet-stack --plugin ratchet-backend18 skills in this plugin
/bounded-iterationUse when writing or reviewing a sweep, scheduled job, reconciler, cleanup, dispatcher, backfill, or export - any loop that reads rows. Covers bounding the rows each run reads, sweeps that re-select their own writes, and effects that repeat on every run./error-handlingUse when writing or reviewing code that throws, catches, or matches an error, turns a failure into a response, or reports errors to a tracker such as Sentry, including a review of a diff that does. Covers one defined list of error codes, matching on type or code instead of message, details as attributes on the error, and reporting only errors someone can act on./expand-contract-migrationsUse when renaming or dropping a column or table, changing a column type, making a column NOT NULL, renaming an API or event field, splitting or merging tables, or changing a config shape that running code reads. Change a shape in separate deploys so old and new code never disagree./feature-rolloutUse when adding or reviewing a feature flag, a flag's default, rollout or rollback steps, or a change that adds a table, migration, service, or write path. Ship new behavior behind a flag that starts off, treat deploying and enabling as separate steps, and add no table or service that no entry point reaches./glide-mqUse when writing or reviewing a queue producer, worker, dispatcher, scheduler, or flow, choosing which queue or lane a job belongs in, deciding what a job payload carries, or handling a request that waits on a job's result. Design glide-mq queues, jobs, lanes, concurrency, rate limits, and replay safety./http-api-designUse when writing or reviewing an endpoint, route handler, service layer, or an edge or CDN worker in front of an API, choosing identifiers in URLs, storing tokens or one-time codes, or setting cache headers. Shape an HTTP API around resources, thin route handlers, user-facing identifiers, and one owner each for secret storage and cache headers.