N Next.js 中文
原文 ↗

agentRules

配置 Next.js 是否为 AI 编码代理创建指令。

更新于 2026-09-22Next.js 16.4.6

agentRules 选项控制 next dev 是否为检测到的 AI 编码代理创建并更新与版本匹配的文档指令。该选项默认启用。

将 agentRules 设置为 false 即可禁用此行为:

TypeScript

next.config.tsts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  agentRules: false,
}

export default nextConfig

JavaScript

next.config.jsjs
/** @type {import('next').NextConfig} */
const nextConfig = {
  agentRules: false,
}

module.exports = nextConfig

生成的代理指令

当 agentRules 已启用且 next dev 检测到 AI 编码代理时,Next.js 会在 AGENTS.md 中创建或更新此托管块:

AGENTS.mdmd
<!-- 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 -->

该托管块会引导代理查阅与所安装 Next.js 版本捆绑的文档。Next.js 仅更新标记之间的内容,并保留文件的其余部分。

禁用代理规则

将 agentRules 设置为 false 可阻止 next dev 创建或更新该托管块。下次运行 next dev 时会移除现有的代理规则块并保留所有其他内容,即使未检测到代理也是如此。如果文件中仅包含该托管块,Next.js 会删除该文件,而不是让其保持为空。

要防止 create-next-app 在新项目中创建代理文件,请传入 --no-agents-md 选项。

agentRules 与 experimental.agentFeedback 相互独立。更改其中一个选项不会影响另一个。

版本历史

版本 变更
v16.4.0 将 agentRules 设置为 false 会在运行 next dev 时移除现有的托管块。
v16.3.0 新增 agentRules 配置选项。
  • AI 编码代理:了解 Next.js 如何帮助 AI 编码代理使用当前的框架指南、检查应用、验证更改并报告问题。
  • agentFeedback:为 AI 编码代理生成的 Next.js 问题报告启用审查流程。