Skip to main content
rule CX Codex

async-api-routes — Claude Code rule: what it does, how to install

async-api-routes prevents sequential waterfall requests in API routes and Server Actions. It instructs the assistant to launch independent promises immediately rather than chaining awaits.

MIT ★ 7,191 updated 2026-10-24

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/async-api-routes.md
Open on GitHub

What async-api-routes does

The rule targets backend endpoints where standalone tasks wait unnecessarily behind unrelated awaits. It enforces starting independent async calls right away: session checks and configuration fetches trigger side by side, synchronizing later via Promise.all.

For complex dependency trees, the rule suggests adopting better-all to schedule tasks automatically. If your project avoids extra packages, you will have to wire those multi-step dependencies by hand with standard promises.

What it helps with

  • eliminate waterfall awaits in route handlers
  • run auth checks and config loading in parallel
  • speed up Server Actions response times
  • restructure nested async calls with Promise.all

Example prompts for the agent

  • Refactor this API route to eliminate async waterfalls
  • Check our Server Actions for sequential awaits on independent data
  • Update this GET handler so config loads alongside the session check

How to install async-api-routes

Manually: put the files in place

.claude/rules/async-api-routes.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about async-api-routes

How to install async-api-routes in Claude Code?

Add the instruction file to your project at .claude/rules/async-api-routes.md.

What does async-api-routes do?

It stops sequential await calls on independent operations inside API routes. The agent initiates independent promises immediately and resolves them using Promise.all.

What is recommended for complex dependency chains?

For multi-tiered asynchronous tasks, the rule suggests using better-all to organize parallel execution based on dependencies.

Source text

async-api-routes.md · MIT
---
title: Prevent Waterfall Chains in API Routes
impact: CRITICAL
impactDescription: 2-10× improvement
tags: api-routes, server-actions, waterfalls, parallelization
---

## Prevent Waterfall Chains in API Routes

In API routes and Server Actions, start independent operations immediately, even if you don't await them yet.

**Incorrect (config waits for auth, data waits for both):**

```typescript
export async function GET(request: Request) {
  const session = await auth()
  const config = await fetchConfig()
  const data = await fetchData(session.user.id)
  return Response.json({ data, config })
}
```

**Correct (auth and config start immediately):**

```typescript
export async function GET(request: Request) {
  const sessionPromise = auth()
  const configPromise = fetchConfig()
  const session = await sessionPromise
  const [config, data] = await Promise.all([
    configPromise,
    fetchData(session.user.id)
  ])
  return Response.json({ data, config })
}
```

For operations with more complex dependency chains, use `better-all` to automatically maximize parallelism (see Dependency-Based Parallelization).

© tech-leads-club · MIT · tech-leads-club/agent-skills

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set130

The whole set →
js-hoist-regexp js-hoist-regexp — a Claude rule that keeps RegExp construction out of the render path: define the pattern at module scope or wrap it in useMemo(). CX Codex +1 ★ 7,191repo stars rendering-hoist-jsx rendering-hoist-jsx extracts static JSX elements outside components to prevent element re-creation on every render pass. CX Codex +1 ★ 7,191repo stars rerender-transitions The rerender-transitions rule marks frequent, non-urgent state changes as transitions. It fits React code where updates such as scroll tracking should keep the interface responsive. CX Codex +1 ★ 7,191repo stars advanced-use-latest advanced-use-latest — a Claude rule file on reaching fresh callback values inside a React effect and keeping the dependency array down to state. CX Codex +1 ★ 7,191repo stars js-early-exit The js-early-exit rule recommends returning as soon as a function’s result is clear. It fits checks where continuing after the first error serves no purpose. CX Codex +1 ★ 7,191repo stars rerender-memo rerender-memo — a rule that guides your agent to extract expensive computations into memoized components, enabling early returns without triggering child logic. Speeds up React re-render paths. CX Codex +1 ★ 7,191repo stars bundle-preload bundle-preload directs the agent to preload heavy JavaScript chunks on user intent like hover or focus. This cuts perceived interface latency. CX Codex +1 ★ 7,191repo stars client-swr-dedup The client-swr-dedup rule recommends SWR to share requests between component instances and reuse cached data. It fits React projects that fetch data on the client. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open