Next.js (App Router)Rule
by DUOMReport
Rules for Next.js App Router projects: server components first, data fetching, caching, routing and env vars.
Developer toolsLicense: CC0-1.0Updated yesterdayrule/nextjs
Install
Run in your project folder (DuoM CLI: risk check, then write; undo with npx duom@1 undo)
npx duom@1 add rule/nextjs --client claude-code
Writes to CLAUDE.md in your project (where Claude Code reads it). If the project has an AGENTS.md but no CLAUDE.md, DuoM creates CLAUDE.md starting with @AGENTS.md so Claude Code keeps reading it. Only the marked block is added; the rest of the file is left alone, and remove takes out only that block.
Manual: paste into CLAUDE.md
CLAUDE.md
<!-- duom:rule/nextjs --> ## Next.js (App Router) - Components are Server Components by default. Add "use client" only to the smallest component that needs state, effects or browser APIs. - Fetch data in Server Components or route handlers, not in client effects. Never import server-only modules (DB, secrets) into client files. - Use Server Actions for mutations from forms. Validate every action's input on the server; it is a public endpoint. - Routes live in app/: page.tsx, layout.tsx, loading.tsx, error.tsx, route.ts. Keep route segments thin; put logic in lib/. - Only NEXT_PUBLIC_* env vars reach the browser. Never prefix a secret with NEXT_PUBLIC_. - Use next/link for navigation, next/image for images, and the Metadata API instead of hand-written <head> tags. - Next.js changes between major versions. Check the version in package.json and its docs before using an API from memory. - Run the build (next build) before calling a change done: it catches type and server/client boundary errors. <!-- /duom:rule/nextjs -->
The rule
Next.js (App Router)
- Components are Server Components by default. Add "use client" only to the smallest component that needs state, effects or browser APIs.
- Fetch data in Server Components or route handlers, not in client effects. Never import server-only modules (DB, secrets) into client files.
- Use Server Actions for mutations from forms. Validate every action's input on the server; it is a public endpoint.
- Routes live in app/: page.tsx, layout.tsx, loading.tsx, error.tsx, route.ts. Keep route segments thin; put logic in lib/.
- Only NEXT_PUBLIC_* env vars reach the browser. Never prefix a secret with NEXT_PUBLIC_.
- Use next/link for navigation, next/image for images, and the Metadata API instead of hand-written tags.
- Next.js changes between major versions. Check the version in package.json and its docs before using an API from memory.
- Run the build (next build) before calling a change done: it catches type and server/client boundary errors.