Home › Next.js › Next.js Server Actions Copilot path instructions

Next.js Server Actions Copilot path instructions

Path-specific Copilot instructions for Next.js Server Actions and route handlers: validation, auth, and revalidation.

GitHub CopilotNext.js

How to use

Save this as .github/instructions/server-actions.instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.github/instructions/server-actions.instructions.mdDownload  
---
applyTo: "app/**/actions.ts,actions/**/*.ts,app/**/route.ts"
description: Rules for Next.js server mutations
---

# Server Actions and route handlers

- Files with actions start with `"use server"`. Export only async functions.
- Every action follows the same order:
  1. Parse input with a zod schema (`schema.safeParse(Object.fromEntries(formData))`).
  2. Get the session; return an unauthorized result if missing.
  3. Check the user may act on the target record (ownership or role).
  4. Perform the mutation through `lib/server/*`.
  5. Revalidate (`updateTag`/`revalidateTag`/`revalidatePath`) and/or `redirect()`.
- Return a typed result (`{ ok: true, data } | { ok: false, errors }`) for forms used with `useActionState`. Don't throw for validation errors.
- `redirect()` throws by design; call it outside `try/catch`.
- Never accept prices, roles, or user ids from the client as truth.
- Route handlers (`route.ts`) export `GET`/`POST` etc., return `Response.json(...)` with explicit status codes, and verify webhook signatures using the raw body (`await req.text()`).
- Rate-limit public mutations (login, signup, contact forms).
- Log errors server-side with context; return generic messages to the client.

More: all Next.js rules · all GitHub Copilot rules

Related rules

Next.js 16 rules (Cache Components, proxy.ts)

Cursor rules for Next.js 16 App Router: Cache Components with "use cache", proxy.ts, async request APIs, Turbopack.

CursorNext.js

Next.js AGENTS.md

AGENTS.md for Next.js 16 App Router projects: commands, folder layout, data access, auth, and done criteria.

AGENTS.mdNext.js

Next.js App Router (TypeScript) rules

Cursor project rules for Next.js 15 App Router apps with TypeScript, Server Components, and Tailwind.

CursorNext.js

Next.js CLAUDE.md

A CLAUDE.md for Claude Code working in a Next.js + Prisma + Tailwind codebase.

Claude Code (CLAUDE.md)Next.js

Next.js Windsurf rules

Windsurf (Cascade) workspace rules for Next.js + shadcn/ui projects.

WindsurfNext.js

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.