Skip to main content

Fixed: next dev "Generated AGENTS.md for AI agents" in a Next.js App

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

I ran npm run dev from an AI coding assistant, and Next.js 16.4.6 printed ✓ Generated AGENTS.md for AI agents and added an AGENTS.md file to the project — although I had created the app with --no-agents-md. It's the agentRules option of next dev, and agentRules: false in next.config.ts turns it off and removes the file.

What I Was Doing​

In Part 5 of the Microsoft Agent Framework series, the chat app is created with create-next-app 16.4.6 and the option --no-agents-md, which leaves out the instructions file for AI coding assistants. I build and run the series' code from Claude Code, an AI coding assistant with its own terminal, and started the app there:

Terminal
npm run dev

What I Expected​

The usual startup output, and no new files: the app had been created without AGENTS.md.

What I Got​

Output
npm notice run agent-chat-ui@0.1.0 dev
npm notice run next dev
▲ Next.js 16.4.6 (Turbopack)
- Local: http://localhost:3000
- Network: http://192.168.1.10:3000
- Environments: .env.local
✓ Ready in 238ms
✓ Running next.config.ts took 1705ms
- Cache Components enabled
- Partial Prefetching enabled

✓ Generated AGENTS.md for AI agents. Set `agentRules: false` in next.config to disable.

The project folder had a new file next to README.md, AGENTS.md, with this content:

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/` (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 -->

What I Checked​

The option the message names. Next.js bundles its documentation in the next package, the folder the file points to. Its page for agentRules says: The agentRules option controls whether next dev creates and updates version-matched documentation instructions for detected AI coding agents. It is enabled by default. The option arrived in Next.js 16.3.

Why --no-agents-md didn't prevent it. The same page explains that --no-agents-md is a create-next-app option: it stops create-next-app from creating agent files in a new project. next dev decides for itself, every time it starts.

How next dev spots an assistant. Next.js includes Vercel's detect-agent package, which looks at environment variables that assistants set in their terminals: CLAUDECODE for Claude Code, CURSOR_TRACE_ID for Cursor, GEMINI_CLI, CODEX_SANDBOX, COPILOT_MODEL, a general AI_AGENT, and a few more. Claude Code's terminal sets CLAUDECODE. In a terminal without those variables, the same npm run dev started the app without creating AGENTS.md.

Why It Happens​

next dev adds a short instructions block to AGENTS.md whenever it runs inside an AI coding assistant, so the assistant reads the documentation of the exact Next.js version you installed instead of relying on what it learned earlier. That is on by default, and it doesn't depend on how the app was created.

The Fix​

The file is harmless, and the block itself suggests committing it if you keep it. If you'd rather not have it, turn the option off in next.config.ts:

next.config.ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
cacheComponents: true,
partialPrefetching: true,
agentRules: false,
};

export default nextConfig;

The documentation describes what happens next: The next next dev run removes the existing agent rules block and preserves all other content, even when no agent is detected. If the file contained only the managed block, Next.js deletes the file instead of leaving it empty.

After the Fix​

Terminal
npm run dev
Output
npm notice run agent-chat-ui@0.1.0 dev
npm notice run next dev
▲ Next.js 16.4.6 (Turbopack)
- Local: http://localhost:3000
- Network: http://192.168.1.10:3000
- Environments: .env.local
✓ Ready in 218ms
✓ Running next.config.ts took 23ms
- Cache Components enabled
- Partial Prefetching enabled

✓ Removed agent rules from AGENTS.md because `agentRules` is disabled.

AGENTS.md held only the managed block, so Next.js deleted the file. A listing of the project folder no longer showed it.

macOS-style window showing next.config.ts with agentRules set to false, followed by the npm run dev output ending in Removed agent rules from AGENTS.md because agentRules is disabled

Common Mistakes​

MistakeWhat happensDo this instead
Deleting AGENTS.md by handThe next npm run dev in the assistant creates it againSet agentRules: false, or keep the file
Expecting --no-agents-md to stop itThat option only affects create-next-appUse agentRules in next.config.ts
Removing your own notes from AGENTS.md along with the blockYour notes are goneNext.js removes only its managed block and keeps the rest

Troubleshooting​

SymptomLikely causeFix
✓ Generated AGENTS.md for AI agentsnext dev runs inside an AI coding assistantKeep the file, or set agentRules: false
The file comes back after you delete itagentRules is still onSet agentRules: false
No AGENTS.md when you expected onenext dev runs in a terminal without an assistant's variablesRun it from the assistant, or create the file with create-next-app

FAQ​

Is AGENTS.md useful?​

For an AI coding assistant, yes: it sends the assistant to the documentation of the Next.js version you installed. For people, it is just one more file.

Does agentRules affect next build or production?​

No. The documentation describes it as a next dev behavior.

Conclusion​

Generated AGENTS.md for AI agents means next dev saw an AI coding assistant's environment and added version-matched instructions for it. Keep the file and commit it, or set agentRules: false in next.config.ts and let the next npm run dev remove it.

Additional Resources​