Free toolGenerate .mcp.json configs for Claude Code, Cursor & Codex →

Based on Next.js’s official docs, checked

AGENTS.md template for Next.js

Next.js ships its own AGENTS.md guidance. From Next.js 16.2 the framework bundles version-matched docs in node_modules/next/dist/docs/, and from 16.3 next dev writes a managed block into AGENTS.md that tells agents to read them. New create-next-app projects include AGENTS.md by default. The template below keeps that official block word for word and adds the project sections around it.

What Next.js provides officially

  1. 1. Let Next.js write the managed block

    On Next.js 16.3 and later, next dev creates or updates the block when it detects a coding agent, and new create-next-app projects include it. Next.js only edits the text between the BEGIN and END markers and keeps the rest of the file. The Next.js blog says to commit the block as is.

  2. 2. On Next.js 16.1 or earlier, run the codemod

    Older versions don’t bundle the docs. The agents-md codemod downloads a version-matched copy to .next-docs/ and indexes it in AGENTS.md.

    npx @next/codemod@canary agents-md
  3. 3. Turn it off if you need to

    Set agentRules: false in next.config to stop next dev from managing the block (from 16.4 it also removes an existing block). Pass --no-agents-md to create-next-app to skip the files in a new project.

    // next.config.ts
    import type { NextConfig } from 'next'
    
    const nextConfig: NextConfig = {
      agentRules: false,
    }
    
    export default nextConfig

The AGENTS.md template

Save this as AGENTS.md at the repository root. Replace the HTML comments with your project’s details and delete what doesn’t apply.

<!-- BEGIN:nextjs-agent-rules -->

## This is NOT the Next.js you know

This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.

This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.

<!-- END:nextjs-agent-rules -->

# Project overview
<!-- One or two sentences: what this app does, App Router or Pages Router, where the main code lives. -->

## Build and test commands
- `npm run dev` starts the development server (`next dev`, Turbopack by default).
- `npm run build` builds for production (`next build`). Run it before you say a change is done.
- `npm run start` serves the production build (`next start`).
- `npm run lint` runs ESLint; `npm run lint:fix` applies fixes.
<!-- Replace npm with pnpm, yarn or bun if this project uses them. Add your test command here. -->

## Code style
- Follow the conventions in the bundled docs above, not memory of older Next.js versions.
- <!-- Your rules: TypeScript strictness, import alias (default `@/*`), styling approach, component folders. -->

## Testing instructions
- <!-- How to run the test suite and which tests must pass before a PR. -->

## Security considerations
- Never commit `.env*` files or secrets.
- <!-- Auth, data access, and any server-only code rules for this project. -->

Notes

Related

Frequently asked questions

Yes. create-next-app includes AGENTS.md in new projects, and on Next.js 16.3+ next dev adds or updates a managed block when it detects a coding agent.

Sources