Next.js API Route Optimizer skill for Claude and Codex
Writes a Next.js API route built for speed around your data layer: cache headers or in-memory caching, streaming, batching, or minimal latency, with the…
Install it once and Claude or Codex runs it for you. When your request matches, your AI loads the skill, asks for anything it is missing, and works through the template itself. Prefer to fill it in by hand? See the full prompt template.
Download the skill (.zip) · View SKILL.md
When it is used
Use when an API route that hits Prisma or Mongo or Supabase needs to be built for speed with caching, streaming, batching, or lowest latency as the goal. Do not use for a basic CRUD route with no performance target, or finding a bug in a slow route. Related topics: coding, next.js.
What it will ask you for
- Endpoint path (free text, e.g. "/api/example")
- HTTP method (choose one: GET, POST, PUT, DELETE, PATCH)
- Request payload schema (longer free text)
- Response structure (longer free text)
- Database interaction (choose any: Prisma, MongoDB, Supabase, None)
- Middleware needed (choose any: Auth, Rate limiting, Validation, CORS, None)
- Performance focus (choose one: Caching, Streaming, Batching, Minimal latency)
How it works
- Reuse one database client across invocations and select only the fields the response needs, so connection setup and over-fetching are gone.
- Implement the chosen focus: cache headers plus a TTL map, chunked streaming, batched queries in request order, or latency short-circuits.
- Wrap the handler with the selected middleware in the order auth, rate limit, CORS, validation.
- Comment every section with its purpose and the trade-off it accepts, then output the full JavaScript route.
What you get
One JavaScript code block with the full route: client setup, middleware wrappers, the handler implementing the chosen performance focus, and inline comments on each section's trade-off.
What it watches out for
- Creating a new database client on every request, which costs more than any caching trick saves.
- Caching a response that varies by user without the user in the cache key, which leaks data across sessions.
- Setting headers after the first streamed chunk, which throws because the headers are already sent.
- Batching into one transaction that fails entirely on the first bad item without saying which item failed.
How to install
Claude.ai and the Claude desktop app
- Download the skill .zip.
- Open Settings, then Capabilities, and find Skills.
- Choose Upload skill and select the .zip.
- Ask Claude for help with the task. It loads the skill when your request matches.
Claude Code
- Download the skill .zip.
- Unzip it into ~/.claude/skills/ (or .claude/skills/ inside a project).
- Start a new session. Claude Code loads the skill when your request matches.
Codex
- Download the skill .zip.
- Unzip it into ~/.agents/skills/ (or .agents/skills/ inside a project).
- Codex picks it up on its own. Type $ and the skill name to use it, or just ask for the task.
Cursor
- Download the Cursor rule (.mdc).
- Save it in .cursor/rules/ inside your project.
- Cursor's agent applies the rule when your request matches its description.
AGENTS.md (Codex, Cursor, and other coding agents)
- Copy the AGENTS.md section.
- Paste it into AGENTS.md at the root of your repository, creating the file if needed.
- Coding agents that read AGENTS.md follow it when your request fits.