Next.js — Claude Code rules
You are working in a Next.js 15+/16 codebase using the App Router. Stick to the conventions below.
Defaults
- Server Components by default. Add
"use client"only when the component needs interactivity, browser APIs, or React state. Never add it to a layout. - Pages live under
app/. Route segments use lowercase + hyphens. Parallel routes only when justified. - Use
<Link>fromnext/linkfor in-app navigation. Usenext/imagefor raster images. - All
paramsandsearchParamsin page / layout / route handlers are Promises in Next 16. Alwaysawaitthem before destructuring.
Data fetching
- Fetch in Server Components when possible. Pass minimal serialisable data to client components.
- Use
fetch(url, { cache: "no-store" })for dynamic,{ next: { revalidate: N } }for ISR. - Never call client-only libraries (e.g.
localStorage) from server code. - Don't hand-roll loading skeletons — use
loading.tsxsegments where it makes sense.
TypeScript
strict: true,noUncheckedIndexedAccess: true. Don't widen withany— narrow withunknown+ guards.- Component props get explicit type aliases; avoid inline
React.FCand avoidReact.FCaltogether.
Style
- Tailwind is the default styling layer. Don't introduce CSS-in-JS without a strong reason.
- Use
cn()(orclsx) for conditional classes; never string-concatenate Tailwind classes.
What not to do
- Don't use
getServerSideProps/getStaticProps— those are Pages Router. - Don't fetch from the client when the server can do it.
- Don't import server-only modules from a
"use client"file.