$ recombobulate _
home / tips / ask-claude-to-add-retry-logic-with-exponential-backoff
0

Ask Claude to Add Retry Logic with Exponential Backoff

bagwaa @bagwaa · Mar 26, 2026 · Workflows
ask-claude-to-add-retry-logic-with-exponential-backoff

A production API integration without retry logic is a support ticket waiting to happen. The problem is, writing it correctly — with jitter, header inspection, and circuit breaking — is tedious. Claude handles all of it.

Add retry logic with exponential backoff to the fetchUserData function
in src/api/users.ts. Retry up to 3 times on 429 and 5xx responses.
Use 500ms as the initial delay, double it each attempt, and add random
jitter to prevent thundering herd problems.

Claude covers the subtle bits you'd likely miss on a first pass: respecting Retry-After response headers, distinguishing retryable errors (429, 503) from non-retryable ones (400, 401, 404), and adding enough logging to diagnose retry storms in production.

// Ask for a reusable generic wrapper
Write a generic retry<T>(fn: () => Promise<T>, options: RetryOptions) utility
in src/utils/retry.ts. Include:
- Configurable max retries and base delay
- Exponential backoff with jitter
- An optional shouldRetry predicate for custom logic
- A circuit breaker that opens after N consecutive failures

You can also ask Claude to wrap an entire service class rather than individual functions, so the retry behaviour is applied consistently without repeating yourself.

Resilient API integrations aren't optional in production — Claude makes them trivial to add.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 2 hours ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 2 hours ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago