Next.js AGENTS.md
Next.js agents mix server and client code when the file they copied was a client component. This file tells the agent to keep data loading on the server, to mark a client component only when it needs state or a browser API, and to run the project's lint before it finishes.
The App Router and the Pages Router are different trees. Say which one this repository uses, and point at an example page.
What to tell the agent
Do
- Point at one existing page that shows the pattern you want copied.
- Name the directory for server actions or route handlers.
- Say whether CSS is Tailwind, CSS modules, or a global file.
- Remind the agent that a client component still renders on the server once.
Leave alone
- Putting "use client" on a layout to silence an import error.
- Reading cookies or headers in a component that you then cache as static.
- Adding a new data library when the project already has one.
AGENTS.md to copy
Save this as AGENTS.md at the root of the repository, or next to the package it covers. Replace the commands with the ones in this repo. See which agents read the file.
# Next.js ## Router - This project uses the App Router under app/. Do not add a pages/ route for a new screen. - A page and a layout are Server Components. Add "use client" only on a component that needs state, effects, or a browser API. - Do not import a server-only module (the database, a secret) into a client file. ## Data - Fetch on the server. Pass the serializable result to a client component as props. - Keep route handlers thin: validate the input, call a function, return the response. ## Checks - Run the lint script. - Run the typecheck or the build when the change touches a route, a layout, or generated types. - Do not claim a page works because it compiled. Name the URL you would open. ## Leave alone - Do not upgrade next or react as a side effect. - Do not edit .next or other generated output.
Checks named in the file
Confirm each command exists here before you rely on it. Delete the ones this repository does not use.
- Lint.
pnpm lint - Production build.
pnpm build
Questions
What is the Next.js AGENTS.md for?
It keeps a Next.js agent on the App Router boundaries and on the lint and build scripts the project already runs.
When should an agent add use client in the App Router?
When the component uses state, effects, or a browser-only API. Data loading stays in a Server Component, and the client child receives the values as props.
Does a successful Next.js compile mean the page is right?
It means the types and the build accepted the files. The instruction file should still name the route a person would open, and the lint script the project runs in CI.