/routing-middleware
Vercel Routing Middleware guidance — request interception before cache, rewrites, redirects, personalization. Works with any framework. Supports Edge, Node.js, and Bun runtimes. Use when intercepting requests at the platform level.
$ npx -y skills add vercel-labs/vercel-plugin --skill routing-middleware --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/routing-middleware
Context preview
The summary Claude sees to decide when to auto-load this skill.
Vercel Routing Middleware guidance — request interception before cache, rewrites, redirects, personalization. Works with any framework. Supports Edge, Node.js, and Bun runtimes. Use when intercepting requests at the platform level.
SKILL.md
routing-middleware.SKILL.mdname: routing-middleware
description: Vercel Routing Middleware guidance — request interception before cache, rewrites, redirects, personalization. Works with any framework. Supports Edge, Node.js, and Bun runtimes. Use when intercepting requests at the platform level.
metadata:
priority: 6
docs:
- "https://nextjs.org/docs/app/building-your-application/routing/middleware"
- "https://vercel.com/docs/routing-middleware"
sitemap: "https://nextjs.org/sitemap.xml"
pathPatterns:
- 'middleware.ts'
- 'middleware.js'
- 'middleware.mts'
- 'middleware.mjs'
- 'proxy.ts'
- 'proxy.js'
- 'proxy.mts'
- 'proxy.mjs'
- 'src/middleware.ts'
- 'src/middleware.js'
- 'src/middleware.mts'
- 'src/middleware.mjs'
- 'src/proxy.ts'
- 'src/proxy.js'
- 'src/proxy.mts'
- 'src/proxy.mjs'
- 'vercel.json'
- 'apps/*/vercel.json'
- 'vercel.ts'
- 'vercel.mts'
bashPatterns:
- '\bnpx\s+@vercel/config\b'
validate:
-
pattern: 'NextResponse.*from\s+[''"]next/server[''"]|from\s+[''"]next/server[''"].*NextResponse'
message: 'Next.js middleware.ts is renamed to proxy.ts in Next.js 16 — rename the file and use the Node.js runtime. Run Skill(nextjs) for proxy.ts migration guidance.'
severity: recommended
upgradeToSkill: nextjs
upgradeWhy: 'Guides migration from middleware.ts to proxy.ts with correct file placement, Node.js runtime, and Next.js 16 patterns.'
skipIfFileContains: 'proxy\.ts|runtime.*nodejs'
retrieval:
aliases:
- request interceptor
- middleware
- rewrite rules
- redirect rules
intents:
- intercept requests
- add middleware
- configure rewrites
- set up redirects
entities:
- middleware
- rewrite
- redirect
- personalization
- Edge
chainTo:
-
pattern: 'from\s+[''""]next-auth[''""]'
targetSkill: auth
message: 'Auth logic in middleware — loading Auth guidance for Clerk/Auth0 integration patterns.'
-
pattern: 'NextResponse.*from\s+[''"]next/server[''"]|from\s+[''"]next/server[''"].*NextResponse'
targetSkill: nextjs
message: 'middleware.ts with next/server imports detected — loading Next.js guidance for proxy.ts migration (Next.js 16 renames middleware.ts to proxy.ts with Node.js runtime).'
skipIfFileContains: 'proxy\.ts|runtime.*nodejs'
-
pattern: 'from\s+[''""](jsonwebtoken)[''""]|jwt\.(verify|decode)\('
targetSkill: auth
message: 'Manual JWT verification in middleware — loading Auth guidance for managed auth middleware patterns (Clerk, Descope).'
skipIfFileContains: 'clerkMiddleware|@clerk/|@auth0/'Vercel Routing Middleware
You are an expert in Vercel Routing Middleware — the platform-level request interception layer.
What It Is
Routing Middleware runs **before the cache** on every request matching its config. It is a **Vercel platform** feature (not framework-specific) that works with Next.js, SvelteKit, Astro, Nuxt, or any deployed framework. Built on Fluid Compute.
- **File**: `middleware.ts` or `middleware.js` at the project root
- **Default export required** (function name can be anything)
- **Runtimes**: Edge (default), Node.js (`runtime: 'nodejs'`), Bun (Node.js + `bunVersion` in vercel.json)
CRITICAL: Middleware Disambiguation
There are THREE "middleware" concepts in the Vercel ecosystem:
| Concept | File | Runtime | Scope | When to Use | |---------|------|---------|-------|-------------| | **Vercel Routing Middleware** | `middleware.ts` (root) | Edge/Node/Bun | Any framework, platform-level | Request interception before cache: rewrites, redirects, geo, A/B | | **Next.js 16 Proxy** | `proxy.ts` (root, or `src/proxy.ts` if using `--src-dir`) | Node.js only | Next.js 16+ only | Network-boundary proxy needing full Node APIs. NOT for auth. | | **Edge Functions** | Any function file | V8 isolates | General-purpose | Standalone edge compute endpoints, not an interception layer |
**Why the rename in Next.js 16**: `middleware.ts` → `proxy.ts` clarifies it sits at the network boundary (not general-purpose middleware). Partly motivated by CVE-2025-29927 (middleware auth bypass via `x-middleware-subrequest` header). The exported function must also be renamed from `middleware` to `proxy`. Migration codemod: `npx @next/codemod@latest middleware-to-proxy`
**Deprecation**: Next.js 16 still accepts `middleware.ts` but treats it as deprecated and logs a warning. It will be removed in a future version.
Bun Runtime
To run Routing Middleware (and all Vercel Functions) on Bun, add `bunVersion` to `vercel.json`:
{
"bunVersion": "1.x"
}Set the middleware runtime to `nodejs` — Bun replaces the Node.js runtime transparently:
export const config = {
runtime: 'nodejs', // Bun swaps in when bunVersion is set
};Bun reduces average latency by ~28% in CPU-bound workloads. Currently in Public Beta — supports Next.js, Express, Hono, and Nitro.
Basic Example
// middleware.ts (project root)
import { geolocation, rewrite } from '@vercel/functions';
export default function middleware(request: Request) {
const { country } = geolocation(request);
const url = new URL(request.url);
url.pathname = country === 'US' ? '/us' + url.pathname : '/intl' + url.pathname;
return rewrite(url);
}
export const config = {
runtime: 'edge', // 'edge' (default) | 'nodejs'
};Helper Methods (`@vercel/functions`)
For non-Next.js frameworks, import from `@vercel/functions`:
| Helper | Purpose | |--------|---------| | `next()` | Continue middleware chain (optionally modify headers) | | `rewrite(url)` | Transparently serve content from a different URL | | `geolocation(request)` | Get `city`, `country`, `latitude`, `longitude`, `region` | | `ipAddress(request)` | Get client IP address | | `waitUntil(promise)` | Keep function running after response is sent |
For Next.js, equivalent helpers are on `NextResponse` (`next()`, `rewrite()`, `redirect()`) an
Read more
name: routing-middleware
description: Vercel Routing Middleware guidance — request interception before cache, rewrites, redirects, personalization. Works with any framework. Supports Edge, Node.js, and Bun runtimes. Use when intercepting requests at the platform level.
metadata:
priority: 6
docs:
- "https://nextjs.org/docs/app/building-your-application/routing/middleware"
- "https://vercel.com/docs/routing-middleware"
sitemap: "https://nextjs.org/sitemap.xml"
pathPatterns:
- 'middleware.ts'
- 'middleware.js'
- 'middleware.mts'
- 'middleware.mjs'
- 'proxy.ts'
- 'proxy.js'
- 'proxy.mts'
- 'proxy.mjs'
- 'src/middleware.ts'
- 'src/middleware.js'
- 'src/middleware.mts'
- 'src/middleware.mjs'
- 'src/proxy.ts'
- 'src/proxy.js'
- 'src/proxy.mts'
- 'src/proxy.mjs'
- 'vercel.json'
- 'apps/*/vercel.json'
- 'vercel.ts'
- 'vercel.mts'
bashPatterns:
- '\bnpx\s+@vercel/config\b'
validate:
-
pattern: 'NextResponse.*from\s+[''"]next/server[''"]|from\s+[''"]next/server[''"].*NextResponse'
message: 'Next.js middleware.ts is renamed to proxy.ts in Next.js 16 — rename the file and use the Node.js runtime. Run Skill(nextjs) for proxy.ts migration guidance.'
severity: recommended
upgradeToSkill: nextjs
upgradeWhy: 'Guides migration from middleware.ts to proxy.ts with correct file placement, Node.js runtime, and Next.js 16 patterns.'
skipIfFileContains: 'proxy\.ts|runtime.*nodejs'
retrieval:
aliases:
- request interceptor
- middleware
- rewrite rules
- redirect rules
intents:
- intercept requests
- add middleware
- configure rewrites
- set up redirects
entities:
- middleware
- rewrite
- redirect
- personalization
- Edge
chainTo:
-
pattern: 'from\s+[''""]next-auth[''""]'
targetSkill: auth
message: 'Auth logic in middleware — loading Auth guidance for Clerk/Auth0 integration patterns.'
-
pattern: 'NextResponse.*from\s+[''"]next/server[''"]|from\s+[''"]next/server[''"].*NextResponse'
targetSkill: nextjs
message: 'middleware.ts with next/server imports detected — loading Next.js guidance for proxy.ts migration (Next.js 16 renames middleware.ts to proxy.ts with Node.js runtime).'
skipIfFileContains: 'proxy\.ts|runtime.*nodejs'
-
pattern: 'from\s+[''""](jsonwebtoken)[''""]|jwt\.(verify|decode)\('
targetSkill: auth
message: 'Manual JWT verification in middleware — loading Auth guidance for managed auth middleware patterns (Clerk, Descope).'
skipIfFileContains: 'clerkMiddleware|@clerk/|@auth0/'Vercel Routing Middleware
You are an expert in Vercel Routing Middleware — the platform-level request interception layer.
What It Is
Routing Middleware runs **before the cache** on every request matching its config. It is a **Vercel platform** feature (not framework-specific) that works with Next.js, SvelteKit, Astro, Nuxt, or any deployed framework. Built on Fluid Compute.
- **File**: `middleware.ts` or `middleware.js` at the project root
- **Default export required** (function name can be anything)
- **Runtimes**: Edge (default), Node.js (`runtime: 'nodejs'`), Bun (Node.js + `bunVersion` in vercel.json)
CRITICAL: Middleware Disambiguation
There are THREE "middleware" concepts in the Vercel ecosystem:
| Concept | File | Runtime | Scope | When to Use | |---------|------|---------|-------|-------------| | **Vercel Routing Middleware** | `middleware.ts` (root) | Edge/Node/Bun | Any framework, platform-level | Request interception before cache: rewrites, redirects, geo, A/B | | **Next.js 16 Proxy** | `proxy.ts` (root, or `src/proxy.ts` if using `--src-dir`) | Node.js only | Next.js 16+ only | Network-boundary proxy needing full Node APIs. NOT for auth. | | **Edge Functions** | Any function file | V8 isolates | General-purpose | Standalone edge compute endpoints, not an interception layer |
**Why the rename in Next.js 16**: `middleware.ts` → `proxy.ts` clarifies it sits at the network boundary (not general-purpose middleware). Partly motivated by CVE-2025-29927 (middleware auth bypass via `x-middleware-subrequest` header). The exported function must also be renamed from `middleware` to `proxy`. Migration codemod: `npx @next/codemod@latest middleware-to-proxy`
**Deprecation**: Next.js 16 still accepts `middleware.ts` but treats it as deprecated and logs a warning. It will be removed in a future version.
Bun Runtime
To run Routing Middleware (and all Vercel Functions) on Bun, add `bunVersion` to `vercel.json`:
{
"bunVersion": "1.x"
}Set the middleware runtime to `nodejs` — Bun replaces the Node.js runtime transparently:
export const config = {
runtime: 'nodejs', // Bun swaps in when bunVersion is set
};Bun reduces average latency by ~28% in CPU-bound workloads. Currently in Public Beta — supports Next.js, Express, Hono, and Nitro.
Basic Example
// middleware.ts (project root)
import { geolocation, rewrite } from '@vercel/functions';
export default function middleware(request: Request) {
const { country } = geolocation(request);
const url = new URL(request.url);
url.pathname = country === 'US' ? '/us' + url.pathname : '/intl' + url.pathname;
return rewrite(url);
}
export const config = {
runtime: 'edge', // 'edge' (default) | 'nodejs'
};Helper Methods (`@vercel/functions`)
For non-Next.js frameworks, import from `@vercel/functions`:
| Helper | Purpose | |--------|---------| | `next()` | Continue middleware chain (optionally modify headers) | | `rewrite(url)` | Transparently serve content from a different URL | | `geolocation(request)` | Get `city`, `country`, `latitude`, `longitude`, `region` | | `ipAddress(request)` | Get client IP address | | `waitUntil(promise)` | Keep function running after response is sent |
For Next.js, equivalent helpers are on `NextResponse` (`next()`, `rewrite()`, `redirect()`) an
Comprehensive Vercel ecosystem plugin — relational knowledge graph, skills for every major product, specialized agents, and Vercel conventions. Turns any AI agent into a Vercel expert.
Repo: vercel-labs/vercel-plugin
Other skills on vercel.
- /benchmark-agents
Advanced AI agent benchmark scenarios that push Vercel's cutting-edge platform features — Workflow DevKit, AI Gateway, MCP, Chat SDK, Queues, Flags, Sandbox, and multi-agent orchestration. Designed to stress-test skill injection for complex, multi-system builds.
Open skill - /benchmark-e2e
End-to-end benchmark suite for vercel-plugin. Runs realistic projects through skill injection, launches dev servers, verifies everything works, analyzes conversation logs, and produces an improvement report for overnight self-improvement loops.
Open skill - /benchmark-sandbox
Run vercel-plugin eval scenarios in Vercel Sandboxes instead of local WezTerm panels. Provisions ephemeral microVMs with Claude Code + plugin pre-installed, runs benchmark prompts, extracts hook artifacts, and produces coverage reports.
Open skill - /benchmark-testing
Create and launch benchmark test projects to exercise vercel-plugin skill injection across realistic scenarios. Sets up isolated directories, installs the plugin, and spawns WezTerm panes running Claude Code with crafted prompts.
Open skill - /plugin-audit
Audit vercel-plugin performance on real-world projects. Extracts tool calls from Claude Code conversation logs, tests hook matching against actual inputs, identifies pattern coverage gaps, and checks plugin cache staleness. Use when asked to audit, test, or investigate plugin
Open skill - /release
Release vercel-plugin — run gates, bump version, generate artifacts, commit, and push. Use when asked to "release", "ship", "bump and push", or "cut a release".
Open skill

