VercelVercel
Menu

Getting started with Routing Middleware using a coding agent

Last updated February 24, 2026

If you use a coding agent like Claude Code, Cursor, or Cline, you can set up Routing Middleware by describing what you need instead of writing the configuration by hand.

For step-by-step manual setup, see the manual quickstart.

Describe the behavior you want and let your agent create the middleware file. Here are example prompts for common use cases:

Prompt
Add routing middleware that redirects /old-blog to /blog and
/legacy-docs/* to /docs/*. Use permanent redirects. Only run
on non-static paths.
Prompt
Add routing middleware that checks for an auth token cookie.
If the cookie is missing, redirect to /login. Skip the check
for /login, /api/auth/*, and static assets.
Prompt
Add routing middleware that reads the user's country from the
x-vercel-ip-country header and rewrites /pricing to
/pricing/eu for European countries or /pricing/us for the US.

Next.js 16 users: Next.js 16 renamed the middleware file from middleware.ts to proxy.ts and changed the function export from middleware to proxy. When using Next.js 16 or later, use proxy.ts instead of middleware.ts. The proxy function runs on Node.js only (Edge runtime is not supported). See the Next.js proxy documentation for details.

DetailValue
File locationmiddleware.ts in project root (or proxy.ts for Next.js 16+)
Exportexport default function middleware(request: Request) (or export function proxy for Next.js 16+)
Config exportexport const config = { matcher: [...] }
Default runtimeedge (set runtime: 'nodejs' in config for Node.js)
Bun runtimeSet bunVersion in vercel.json and runtime: 'nodejs' in config
Request objectStandard Request API
Geo headersx-vercel-ip-country, x-vercel-ip-country-region, x-vercel-ip-city
Path matchingSupports regex, named params, and wildcards in the matcher config

Was this helpful?

supported.