/api-idempotency:api-idempotencyfrom api-idempotency
Designs idempotency keys and safe retries for HTTP APIs, server and client. Use when adding an Idempotency-Key header, fixing duplicate or double-submitted writes, auditing a key implementation for races (atomic claim, in-flight state, replay window), or setting client retry policy, full-jitter backoff, retry budgets and SDK retry defaults.
Ships in api-idempotency. 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.
Read when SKILL.md points to them.
Not for the shape of error responses (api-rest-design), webhook delivery retries or verifying and acknowledging received webhooks (api-webhooks), or Postgres locking and index details (postgres), each if installed. Deduplicating received webhook events by event ID is this skill's job: use the key store and atomic claim below, keyed on the provider's event ID.
A retried write is safe only when both halves exist: a server that collapses duplicates and a client that retries with discipline. Retry guidance without key support, or keys without retry guidance, leaves the guarantee open exactly where a dropped connection tests it.
Exactly-once delivery is impossible over an unreliable network. A key buys effectively-once: at-least-once delivery plus duplicate collapse, within the scope and window where you implement it. Do not write "exactly-once" in code comments or docs.
Idempotency-Key is not a standard. The IETF draft (draft-ietf-httpapi-idempotency-key-header) stopped at revision 07 and is an expired Internet-Draft (checked on datatracker 2026-10-17), so TTL, mismatch behavior, and concurrency handling are whatever you decide. Design them and document them. RFC 9110 defines GET, PUT, and DELETE as idempotent and POST and PATCH as not, and says nothing about the key pattern.
Collect these from the repo, then ask the user only for what the code cannot answer.
(account_id, idempotency_key), never global.order-confirm-<orderId>), which a retry cannot fail to reuse. Next best is request-scoped, then a random UUID generated once and reused. A fresh value per attempt (Date.now(), a regenerated UUID) defeats the mechanism, so document it as the anti-pattern.422 is what the expired IETF draft proposes, and 409 is common in the field. Pick one and keep it distinct from the in-flight response.Check-then-insert is a race: two concurrent retries both see "absent" and both run. Let the storage layer pick the single winner.
(account_id, idempotency_key), with the claim inserted in the same transaction as the business mutation. The loser's INSERT fails or returns no row, and that is its conflict signal.lock_generation on every takeover and include AND lock_generation = <mine> in every phase update, so a stalled executor's writes affect zero rows and it stops. Set the lock timeout longer than the longest phase, including its foreign-call timeout.SETNX with a TTL is not a lock for this purpose. A client paused past its lease can still write after the lock moves on, and without a fencing token nothing stops it. If Redis is all you have, add fencing tokens. A database constraint avoids the problem.The schema, claim query, and state branches are in references/key-lifecycle.md.
A key is a state machine: absent, in-flight, complete.
| Situation | Behavior |
|---|---|
| Never received | Proceed as a first attempt. |
| Claimed, no result yet | Return the in-flight conflict, or resume from the last recovery point once the original lock has expired. |
| Complete, response lost | Replay the stored response verbatim with no re-execution. |
For the in-flight case choose one: reject with 409 and the code idempotency_request_in_progress, which clients retry with the same key (simplest), block for a bounded wait when the caller needs the result synchronously, or return 202 with a status URL for long-running work. Never let the second caller through because the first "seems stuck".
For multi-step requests that call external systems, split the work into atomic phases around each foreign call and persist a recovery point between them. Record intent before the call so a crash between call and response leaves evidence. A retry resumes at the stored phase. A crash after a foreign call but before its phase commits still leaves the call in doubt, so each foreign call must be safe to repeat: send the vendor its own idempotency key derived from (key, phase), or query the foreign system's state before calling again.
Run recovery as background jobs. A completer pushes abandoned in-flight requests to completion using only keys and recovery points. A reaper deletes expired keys and logs what it could not finish for a human. Passive expiry alone leaves half-finished requests half-finished.
Location, body), not a summary, so the replay is indistinguishable from the original.408, 429 (honor Retry-After), 502, 503, 504, connection timeouts or resets, and the in-flight conflict (409 with idempotency_request_in_progress), always with the same key. Treat 500 with care, because some are bugs that fail identically. Never retry other 4xx (including the payload-mismatch response), auth failures, or programming errors.sleep = random(0, min(cap, base * 2^attempt)). It minimizes total client work and server load. Jitterless backoff re-synchronizes a fleet into the spike that caused the failures. Formulas and trade-offs are in references/backoff-jitter.md.python for its reliability guidance and coding for the repo-wide retry policy, each if installed.Integrators have only your docs. State which endpoints accept the key, the header name and maximum length, the recommended derivation, the scope and replay window as concrete numbers, what happens after expiry, both conflict responses with distinct codes, whether a stored failure replays, and a worked retry schedule with numbers. Error body design is in api-rest-design, if installed.
Each item is a finding.
SETNX as the claim.Sources checked: IETF idempotency-key draft revision 07, expired (rechecked 2026-10-17) (datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/), RFC 9110 for method semantics, Marc Brooker, "Exponential Backoff and Jitter" (aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/), Brandur Leach, "Implementing Stripe-like Idempotency Keys in Postgres" (brandur.org/idempotency-keys).
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub adminhead/claude-plugins --plugin api-idempotency