Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
86564347
Commit
86564347
authored
Apr 16, 2026
by
Jude Gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "[agents-md] Add `agentRules` next.config option to opt out"
This reverts commit
3b1105b1
.
parent
3b1105b1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
61 deletions
+26
-61
ai-agents.mdx
docs/01-app/02-guides/ai-agents.mdx
+0
-14
config-schema.ts
packages/next/src/server/config-schema.ts
+0
-1
config-shared.ts
packages/next/src/server/config-shared.ts
+0
-11
app-info-log.ts
packages/next/src/server/lib/app-info-log.ts
+0
-4
router-server.ts
packages/next/src/server/lib/router-server.ts
+0
-1
start-server.ts
packages/next/src/server/lib/start-server.ts
+26
-30
No files found.
docs/01-app/02-guides/ai-agents.mdx
View file @
86564347
...
@@ -77,20 +77,6 @@ This version has breaking changes — APIs, conventions, and file structure may
...
@@ -77,20 +77,6 @@ This version has breaking changes — APIs, conventions, and file structure may
You can also add the block by hand with the exact content above.
You can also add the block by hand with the exact content above.
### Opting out
To disable the auto-generation, delete the files and set `agentRules` to `false` in your config:
```ts filename="next.config.ts"
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
agentRules: false,
}
export default nextConfig
```
<details>
<details>
<summary>For earlier versions</summary>
<summary>For earlier versions</summary>
...
...
packages/next/src/server/config-schema.ts
View file @
86564347
...
@@ -428,7 +428,6 @@ export const experimentalSchema = {
...
@@ -428,7 +428,6 @@ export const experimentalSchema = {
export
const
configSchema
:
zod
.
ZodType
<
NextConfig
>
=
z
.
lazy
(()
=>
export
const
configSchema
:
zod
.
ZodType
<
NextConfig
>
=
z
.
lazy
(()
=>
z
.
strictObject
({
z
.
strictObject
({
adapterPath
:
z
.
string
().
optional
(),
adapterPath
:
z
.
string
().
optional
(),
agentRules
:
z
.
boolean
().
optional
(),
allowedDevOrigins
:
z
.
array
(
z
.
string
()).
optional
(),
allowedDevOrigins
:
z
.
array
(
z
.
string
()).
optional
(),
assetPrefix
:
z
.
string
().
optional
(),
assetPrefix
:
z
.
string
().
optional
(),
basePath
:
z
.
string
().
optional
(),
basePath
:
z
.
string
().
optional
(),
...
...
packages/next/src/server/config-shared.ts
View file @
86564347
...
@@ -1650,17 +1650,6 @@ export interface NextConfig {
...
@@ -1650,17 +1650,6 @@ export interface NextConfig {
*/
*/
expireTime
?:
number
expireTime
?:
number
/**
* When `next dev` detects an AI coding agent and no managed
* agent-rules block is present, Next.js auto-generates `AGENTS.md`
* and `CLAUDE.md` at the project root so the agent reads
* version-matched docs from `node_modules/next/dist/docs/` instead
* of stale training data. Set to `false` to disable this behavior.
*
* @default true
*/
agentRules
?:
boolean
/**
/**
* Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
* Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
*/
*/
...
...
packages/next/src/server/lib/app-info-log.ts
View file @
86564347
...
@@ -125,10 +125,6 @@ export function logExperimentalInfo({
...
@@ -125,10 +125,6 @@ export function logExperimentalInfo({
* auto-generate the files so the agent has access to version-matched
* auto-generate the files so the agent has access to version-matched
* docs. Returns the write result when files were generated, or `null`
* docs. Returns the write result when files were generated, or `null`
* when no action was needed.
* when no action was needed.
*
* Callers gate this on `config.agentRules !== false` — disabling is
* done via `agentRules: false` in next.config, not inside this
* function, so the check point stays declarative at the config level.
*/
*/
export
function
ensureAgentRulesForDev
(
dir
:
string
):
AgentFilesResult
|
null
{
export
function
ensureAgentRulesForDev
(
dir
:
string
):
AgentFilesResult
|
null
{
if
(
detectAgent
()
===
null
)
return
null
if
(
detectAgent
()
===
null
)
return
null
...
...
packages/next/src/server/lib/router-server.ts
View file @
86564347
...
@@ -930,6 +930,5 @@ export async function initialize(opts: {
...
@@ -930,6 +930,5 @@ export async function initialize(opts: {
distDir
:
config
.
distDir
,
distDir
:
config
.
distDir
,
experimentalFeatures
,
experimentalFeatures
,
cacheComponents
:
config
.
cacheComponents
,
cacheComponents
:
config
.
cacheComponents
,
agentRules
:
config
.
agentRules
,
}
}
}
}
packages/next/src/server/lib/start-server.ts
View file @
86564347
...
@@ -374,6 +374,32 @@ export async function startServer(
...
@@ -374,6 +374,32 @@ export async function startServer(
// Get env info first (fast, doesn't require config)
// Get env info first (fast, doesn't require config)
const
envInfo
=
isDev
?
getEnvInfo
(
dir
)
:
undefined
const
envInfo
=
isDev
?
getEnvInfo
(
dir
)
:
undefined
// Auto-generate AGENTS.md / CLAUDE.md when an AI coding agent
// is detected but the managed agent-rules block is missing.
if
(
isDev
)
{
const
agentFilesResult
=
ensureAgentRulesForDev
(
dir
)
if
(
agentFilesResult
)
{
const
generated
:
string
[]
=
[]
if
(
agentFilesResult
.
agentsMd
===
'created'
||
agentFilesResult
.
agentsMd
===
'updated'
)
{
generated
.
push
(
'AGENTS.md'
)
}
if
(
agentFilesResult
.
claudeMd
===
'created'
||
agentFilesResult
.
claudeMd
===
'updated'
)
{
generated
.
push
(
'CLAUDE.md'
)
}
if
(
generated
.
length
>
0
)
{
Log
.
info
(
`Generated
${
generated
.
join
(
' and '
)}
with Next.js agent rules`
)
}
}
}
// Log basic startup info immediately (before loading config)
// Log basic startup info immediately (before loading config)
logStartInfo
({
logStartInfo
({
networkUrl
,
networkUrl
,
...
@@ -507,36 +533,6 @@ export async function startServer(
...
@@ -507,36 +533,6 @@ export async function startServer(
experimentalFeatures
:
initResult
.
experimentalFeatures
,
experimentalFeatures
:
initResult
.
experimentalFeatures
,
cacheComponents
:
initResult
.
cacheComponents
,
cacheComponents
:
initResult
.
cacheComponents
,
})
})
// Auto-generate AGENTS.md / CLAUDE.md when an AI coding agent
// is detected but the managed agent-rules block is missing.
// Gated on `agentRules` in next.config (default true). Runs
// after config load so the flag is respected.
if
(
initResult
.
agentRules
!==
false
)
{
const
agentFilesResult
=
ensureAgentRulesForDev
(
dir
)
if
(
agentFilesResult
)
{
const
generated
:
string
[]
=
[]
if
(
agentFilesResult
.
agentsMd
===
'created'
||
agentFilesResult
.
agentsMd
===
'updated'
)
{
generated
.
push
(
'AGENTS.md'
)
}
if
(
agentFilesResult
.
claudeMd
===
'created'
||
agentFilesResult
.
claudeMd
===
'updated'
)
{
generated
.
push
(
'CLAUDE.md'
)
}
if
(
generated
.
length
>
0
)
{
Log
.
info
(
`Generated
${
generated
.
join
(
' and '
)}
so AI agents use version-matched Next.js docs. `
+
`We think this is a good default. If you'd rather not have these files, delete them and `
+
`set \`agentRules: false\` in next.config.`
)
}
}
}
}
}
handlersReady
()
handlersReady
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment