How Next.js supports AI coding agents
AI coding agents may rely on training data that predates the Next.js version installed in a project. To help agents use current APIs and verify their work, Next.js provides and evaluates version-matched documentation, managed project instructions, agent-guided upgrades, runtime tools, structured errors, reusable Skills, and optional agent feedback. See the results in the Next.js agent evaluations.
For more background, read about the AI tooling introduced in Next.js 16.2 and Next.js 16.3.
Version-matched documentation
Next.js 16.2 and later include documentation that matches the installed framework version. The documentation is available at node_modules/next/dist/docs/ and mirrors the structure of the Next.js documentation site:
The bundled copy gives coding agents access to the APIs and patterns supported by the project without a network request or external lookup. Upgrading Next.js also updates the bundled documentation.
Managed documentation instructions
Next.js makes the bundled documentation discoverable through managed instructions in AGENTS.md at the project root. Coding agents such as Claude Code, Codex, Cursor, and GitHub Copilot read this file when they start a session.
create-next-app creates the agent files for new projects. When next dev detects a coding agent, it creates or updates the managed instructions for existing projects. The block directs the agent to the documentation installed with the project:
Next.js updates only the content between the agent rules markers and preserves the rest of AGENTS.md.
Research comparing AGENTS.md with knowledge Skills found a 100% pass rate with bundled documentation, compared with up to 79% for Skill-based approaches. See the current Next.js agent evaluation results.
Managed documentation instructions are enabled by default in Next.js 16.3 and later. See the agentRules API reference to configure or disable them.
Version support
Next.js 16.3 and later include bundled documentation and support managed agent instructions. Next.js 16.2 includes the bundled documentation but does not generate instructions automatically.
Next.js 16.1 and earlier do not include the bundled documentation. The legacy agents-md command downloads a version-matched copy to .next-docs/ and indexes it in AGENTS.md:
Docs over the network
The Next.js documentation is also available as Markdown over the network for agents that fetch pages instead of reading node_modules. Every page on nextjs.org/docs has a plain Markdown version at its .md URL, and clients that send an Accept: text/markdown header receive Markdown. This includes the per-error pages under /docs/messages, which are not bundled.
The index at /docs/llms.txt and the single-file /docs/llms-full.txt follow the llms.txt convention, so agents that already read llms.txt for other tools can discover the Next.js docs the same way.
Automatic agent feedback
Automatic agent feedback lets coding agents keep track of potential Next.js issues without interrupting the current user request. Before the final response, the agent evaluates those issues and opens each qualifying report in a separate review form in your default browser.
Before opening a form, the agent attempts to anonymize the report by replacing customer and project details with generic descriptions and omitting source code, logs, paths, URLs, secrets, and personal information. Review the draft and remove anything you don't want to include. Nothing is sent until you select Send feedback.
With the option enabled, next dev adds the following managed feedback instructions to the agent file when it detects an AI coding agent:
Next.js updates only the content between the agent feedback markers and preserves the rest of the file.
Automatic agent feedback is experimental, disabled by default, and available only when Next.js Telemetry is enabled. It does not run in CI. See the agentFeedback API reference to enable it.
Agent-guided upgrades
next upgrade --agent checks for an available upgrade, gathers the version-matched migration guides, and hands the task to a coding agent. The agent applies the changes and verifies the app:
The experimental agentUpgrade option shows security upgrade reminders during next dev and next build by default. See Upgrade with a coding agent for the available policies and workflow.
Runtime visibility
Agents need both framework and browser state to verify a running application. Next.js and its supporting tools expose these complementary views as structured text.
First, next dev forwards browser console errors and warnings to the terminal (the logging.browserToTerminal config), so the output agents already read carries the client-side failures they're asked to fix.
next dev also writes its PID, port, and URL to .next/dev/lock. If you run next dev while another development server is already running for the project, the command prints the existing server's URL and PID, along with a command to stop it. Continue with the existing server when possible to avoid interrupting the active development session.
The framework's view comes from the Next.js MCP server at /_next/mcp, which exposes the running dev server's routes, server logs, and compilation issues. Its get_compilation_issues and compile_route tools report whether the code compiles straight from the dev server, so an agent doesn't have to run a full next build to find out.
The next-dev-loop skill adds the browser's view through agent-browser, a CLI that exposes the DOM, console, network, and Web Vitals as structured text. The Skill opens agent-browser with React DevTools enabled, which also exposes the component tree and pending Suspense boundaries. An agent can run a command such as react tree and use the structured output to decide what to inspect next.
Together with the Next.js MCP server, next-dev-loop combines the framework's and the browser's perspectives into one edit-and-verify loop.
Built-in guidance for errors
With Cache Components enabled, a blocking error presents labeled fixes, each making a different trade-off. The dev overlay adds a Copy prompt button that packages the chosen fix into a paste-ready prompt. The prompt walks the agent through reading the matching error page, applying the canonical pattern, and verifying the result at runtime.
The same menu prints in the next dev terminal and in next build output, so an agent reading CI logs sees it too:
next dev shows all validation errors with source-mapped stacks in the overlay and terminal. Production builds minify server code and stop after a route fails. Use next build --debug-prerender to enable server source maps and continue checking other routes.
The Learn more link resolves to a per-error page under /docs/messages written for agents to read. Each page follows the same shape, with the canonical patterns for every fix, the trade-offs against the other fixes, and the gotchas an agent is likely to miss on a first attempt. The Instant navigation guide walks through the full loop an agent runs on these errors, from reading the insight to writing an instant() test that fails before the fix and passes once it's in place.
Skills for multi-step workflows
Framework knowledge comes from the bundled docs, not from Skills. Benchmark results show that always-available context outperforms on-demand retrieval. Skills cover the tasks that are workflows rather than lookups, such as adopting Cache Components or Partial Prefetching across an app. Next.js Skills package these as structured instructions an agent installs and follows, sequencing the work and pointing at the relevant docs and runtime tooling along the way.
You can browse the source for these Skills in the Next.js repository and find them on skills.sh.
The Skills serve three different workflow types:
- Runtime foundations such as
next-dev-loopgive any coding task a repeatable inspect, edit, and verify cycle. - Interactive workflows make broader changes with user checkpoints, such as adopting Cache Components or Partial Prefetching across an app.
- Unattended loops work toward a verifiable goal and stop only for genuine decisions.
next-dev-loop
The next-dev-loop runtime foundation verifies changes against a running dev server using the MCP server and browser.
Then give the agent this prompt:
next-bundle-optimizer
The next-bundle-optimizer skill uses Turbopack's bundle analyzer to identify sources of large client-side bundles that impact your site's initial load performance.
In audit-only mode, it produces a report without making any changes:
You can also tell your agent to fix any issues, and it will optimize your site based on its findings. Or have it focus on a specific route by providing the route in the prompt.
next-cache-components-adoption
The next-cache-components-adoption Skill migrates an app to Cache Components:
- Turns the flag on and finds the routes that can't prerender.
- Fixes them one feature at a time, checking in with you before moving on.
- Confirms a feature against
next devandnext buildbefore leaving it.
The Skill supports both a series of pull requests and a single-branch migration.
Then give the agent this prompt:
next-cache-components-optimizer
The next-cache-components-optimizer Skill expands a target route's static shell to include the useful UI you want available on an initial load:
- Writes a failing
instant()test for the static-shell UI you named. - Refactors the route until it passes, often by moving a data read below a
<Suspense>boundary. - Commits the passing test with the refactoring, so it catches future regressions.
Use it after adopting Cache Components to optimize an initial load or client navigation. To prefetch URL-specific content for an already-instant destination, use the next-partial-prefetching-optimizer instead.
Then give the agent a prompt like:
next-partial-prefetching-adoption
The next-partial-prefetching-adoption Skill moves an app onto Partial Prefetching, where links share one App Shell:
- Audits existing
<Link prefetch={true}>navigations and identifies the prefetched UI to preserve. - Captures that UI in passing
instant()tests before enabling Partial Prefetching, then migrates each destination until the same tests pass unchanged. - Enables the flag, resolves the URL-data insights it surfaces, and marks optional per-link prefetching candidates for later.
It needs Cache Components already adopted and a production-like build it can run for prefetch verification.
Then give the agent this prompt:
next-partial-prefetching-optimizer
The next-partial-prefetching-optimizer Skill takes a target navigation or set of navigations and works toward the UI you want ready before each click:
- Turns the requested behavior for each navigation into a contract for what is prefetched, what waits for navigation, and when prefetching begins.
- Captures each contract in an
instant()test. - Applies the Optimizing prefetching patterns and keeps the passing tests as regression coverage.
It needs Cache Components and Partial Prefetching already adopted.
Then give the agent a prompt like:
Version History
| Version | Changes |
|---|---|
v16.4.0 | next-bundle-optimizer skill added. |
Next Steps
Learn more about the APIs and tools described in this guide.
Next.js MCP Server
Upgrading
agentRules
agentFeedback
agentUpgrade
Last updated