Back to Guides
Tool-Specific

CLAUDE.md for Next.js App Router

CLAUDE.md is the first thing Claude Code reads before writing a line. Get the structure right and Claude will write Next.js code that matches your project from day one.

Last updated: 2026-07-01

What CLAUDE.md does

CLAUDE.md is automatically read by Claude Code at the start of every session. It is the equivalent of onboarding documentation for your AI agent -it tells Claude your tech stack, folder structure, coding conventions, and project-specific rules before it touches any code. Without it, Claude falls back on generic React patterns that may conflict with your Next.js App Router setup.

What to include for App Router projects

App Router projects have specific patterns Claude should know: the server-first component model, how route groups work, where server-only code lives, and how data fetching is done without getServerSideProps. The CLAUDE.md should make these explicit so Claude doesn't revert to Pages Router assumptions.

Ready-to-use CLAUDE.md template

Drop this at the root of your Next.js project and customize the stack section.

CLAUDE.md
# Project Overview
This is a Next.js 16 App Router project using TypeScript.

## Tech Stack
- Framework: Next.js 16 (App Router)
- Language: TypeScript (strict mode)
- Styling: Tailwind CSS v4
- UI Components: shadcn/ui
- State: Zustand (client UI state only)
- Data Fetching: Next.js fetch() with cache options / React Query for client
- Auth: [your auth provider]
- Database: [your database/ORM]

## Folder Structure
```
src/
├── app/           # Routes only. Thin pages that import from features/.
├── components/    # Shared UI used across 2+ routes.
├── features/      # Business-domain modules (auth/, dashboard/, billing/).
│   └── [feature]/ # Each has: components/, hooks/, actions/, types/, index.ts
├── hooks/         # Shared client-side custom hooks (use* prefix).
├── lib/           # Server-only clients (Prisma, auth, Stripe). Import 'server-only'.
├── store/         # Zustand stores. UI state only -no server data.
├── types/         # Global TypeScript types and Zod schemas.
└── utils/         # Pure helpers usable on client and server.
```

## Component Rules
- Default to Server Components. Add "use client" only when needed (event handlers, browser APIs, hooks).
- Never use useEffect to fetch data. Fetch in async Server Components.
- Named exports only. No default exports for components.
- Props typed with interfaces. No implicit any.

## Naming Conventions
- Files: kebab-case. Components: PascalCase. Hooks: useCamelCase.
- Boolean variables: isX, hasX, canX prefix.
- Event handlers: handleX prefix. Prop callbacks: onX prefix.
- Constants: UPPER_SNAKE_CASE.

## Key Rules
- Do NOT create files in pages/ -this project uses App Router exclusively.
- Always add loading.tsx and error.tsx for route segments with async data.
- All external data validated with Zod at the boundary. Infer types with z.infer<>.
- Route handlers: app/api/[route]/route.ts. One file per HTTP method group.
- Server-only files must import 'server-only' at the top.

Generate a tailored CLAUDE.md for your Next.js project

standarx generates a CLAUDE.md customized to your exact stack -App Router, your state library, your component library -in under 3 minutes.

Generate my rules file