How to set up your Next.js project for AI coding agents

Learn how to configure your Next.js project so AI coding agents use up-to-date documentation instead of outdated training data.

Next.js ships version-matched documentation inside the next package, allowing AI coding agents to reference accurate, up-to-date APIs and patterns. An AGENTS.md file at the root of your project directs agents to these bundled docs instead of their training data.

How it works

When you install next, the Next.js documentation is bundled at node_modules/next/dist/docs/. The bundled docs mirror the structure of the Next.js documentation site:

node_modules/next/dist/docs/
├── 01-app/
│   ├── 01-getting-started/
│   ├── 02-guides/
│   └── 03-api-reference/
├── 02-pages/
├── 03-architecture/
└── index.mdx

This means agents always have access to docs that match your installed version — no network request or external lookup required.

The AGENTS.md file at the root of your project tells agents to read these bundled docs before writing any code. Most AI coding agents — including Claude Code, Cursor, GitHub Copilot, and others — automatically read AGENTS.md when they start a session.

Getting started

New projects

create-next-app generates AGENTS.md and CLAUDE.md automatically. No additional setup is needed:

pnpm create next-app@canary
npx create-next-app@canary
yarn create next-app@canary
bun create next-app@canary

If you don't want the agent files, pass --no-agents-md:

npx create-next-app@canary --no-agents-md

Existing projects

On Next.js 16.3 or later, just run next dev. When an AI coding agent is detected in the environment and no managed block is present, Next.js auto-generates AGENTS.md and CLAUDE.md at the project root. Existing AGENTS.md or CLAUDE.md files are upserted — content outside the managed block is preserved:

AGENTS.md
<!-- 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/` before writing any code. Heed deprecation notices.
 
<!-- END:nextjs-agent-rules -->
CLAUDE.md
@AGENTS.md

Opting out

We believe leaving auto-generation on is a good default—benchmark results on nextjs.org/evals show agents do better when they read the bundled docs. If you really want to opt out, set agentRules to false in your config:

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

For earlier versions

On version 16.1 and earlier, use the legacy agents-md command, which downloads the docs to .next-docs/ in the project root:

npx @next/codemod@canary agents-md

Understanding AGENTS.md

The default AGENTS.md contains a single, focused instruction: read the bundled docs before writing code. This is intentionally minimal — the goal is to redirect agents from stale training data to the accurate, version-matched documentation in node_modules/next/dist/docs/.

The <!-- BEGIN:nextjs-agent-rules --> and <!-- END:nextjs-agent-rules --> comment markers delimit the Next.js-managed section. You can add your own project-specific instructions outside these markers without worrying about them being overwritten by future updates.

The bundled docs include guides, API references, and file conventions for the App Router and Pages Router. When an agent encounters a task involving routing, data fetching, or any other Next.js feature, it can look up the correct API in the bundled docs rather than relying on potentially outdated training data.

Good to know: To see how bundled docs and AGENTS.md improve agent performance on real-world Next.js tasks, visit the benchmark results.

On this page