next.js
AGENTS.md144k starsChanged 7 months agoMITView on GitHub
This is a pnpm monorepo containing the Next.js framework and related packages. The main Next.js framework lives in packages/next/. This is what gets published as the next npm package. Source code is in packages/next/src/. Key entry points: Compiled output goes to packages/next/dist/ (mirrors src/ structure). Before editing or creating files in any subdirectory (e.g., packages/*, crates/*), read all README.md files in the directory path from the repo root up to and including the target file's directory. This helps identify any…
- Reads credentials
Trending
Less talk lately.about the whole repository
Who's talking about vercel/next.js
- A Hacker News story“RCE Vulnerability in React and Next.js”Hacker News · Dec 3, 2025 · 628 points
- getsentry/sentry-javascript“Next.js Turbopack Support”GitHub · May 11, 2023 · 365 reactions
- react/react“eslint-plugin-react-hooks & "Flat Config" (ESLint 9)”GitHub · Feb 13, 2024 · 296 reactions
- sveltejs/kit“Add incremental static regeneration”GitHub · Mar 25, 2021 · 183 reactions
- payloadcms/payload“feat: next.js 16 support”GitHub · Nov 3, 2025 · 163 reactions
The biggest 5 of 92 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 92
Talked about on Bluesky, GitHub and Hacker News (92 times).
On Bluesky · 50
- Jan 17, 2025📦 vercel / next.js ⭐ 128,623 (+39) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social6 likes and reposts
- Apr 27, 2025📦 vercel / next.js ⭐ 131,376 (+38) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social5 likes and reposts
- Dec 2, 2024📦 vercel / next.js ⭐ 127,482 (+35) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social5 likes and reposts
- Oct 8, 2026You can also follow security advisories through GitHub or a dependency monitoring service. On the Next.js repository, choose Watch → Custom… — @nextjs.org4 likes and reposts
- Jun 4, 2026📦 vercel / next.js ⭐ 139,667 (+32) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social4 likes and reposts
45 more on Bluesky
- Jan 12, 2025📦 vercel / next.js ⭐ 128,495 (+43) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social4 likes and reposts
- Nov 15, 2024📦 vercel / next.js ⭐ 127,010 (+42) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social4 likes and reposts
- May 17, 2025📦 vercel / next.js ⭐ 131,846 (+36) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social3 likes and reposts · 1 reply
- Apr 2, 2025📦 vercel / next.js ⭐ 130,747 (+38) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social3 likes and reposts
- Mar 22, 2025📦 vercel / next.js ⭐ 130,452 (+45) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social3 likes and reposts
- Jan 8, 2025📦 vercel / next.js ⭐ 128,373 (+39) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social3 likes and reposts
- Sep 14, 2024📦 vercel / next.js ⭐ 124,905 (+46) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social3 likes and reposts
- Oct 23, 2026📦 vercel / next.js ⭐ 143,195 (+78) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Sep 26, 2026📦 vercel / next.js ⭐ 142,463 (+31) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Sep 17, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 vercel / next.js ⭐ 142,336 (+129) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Aug 4, 2026📦 vercel / next.js ⭐ 141,327 (+45) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Jul 30, 2026📦 vercel / next.js ⭐ 141,186 (+43) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Jul 4, 2026📦 vercel / next.js ⭐ 140,320 (+54) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Jun 29, 2026📦 vercel / next.js ⭐ 140,437 (+36) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Jun 24, 2026📦 vercel / next.js ⭐ 140,207 (+94) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Jun 17, 2026📦 vercel / next.js ⭐ 140,037 (+34) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Dec 14, 2025📦 vercel / next.js ⭐ 136,507 (+34) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Dec 4, 2025📦 vercel / next.js ⭐ 136,067 (+71) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Nov 8, 2025📦 vercel / next.js ⭐ 135,508 (+32) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Sep 16, 2025📦 vercel / next.js ⭐ 134,471 (+46) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Jun 13, 2025📦 vercel / next.js ⭐ 132,413 (+32) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- May 10, 2025📦 vercel / next.js ⭐ 131,707 (+35) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Apr 16, 2025📦 vercel / next.js ⭐ 131,086 (+41) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Mar 18, 2025📦 vercel / next.js ⭐ 130,300 (+50) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Mar 14, 2025📦 vercel / next.js ⭐ 130,174 (+37) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Feb 23, 2025📦 vercel / next.js ⭐ 129,609 (+43) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Feb 14, 2025📦 vercel / next.js ⭐ 129,307 (+47) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Feb 1, 2025📦 vercel / next.js ⭐ 128,951 (+38) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Dec 24, 2024📦 vercel / next.js ⭐ 128,052 (+37) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Dec 20, 2024📦 vercel / next.js ⭐ 127,957 (+39) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Dec 12, 2024📦 vercel / next.js ⭐ 127,744 (+34) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Dec 7, 2024📦 vercel / next.js ⭐ 127,618 (+32) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Oct 15, 2024📦 vercel / next.js ⭐ 125,776 (+44) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Sep 6, 2024📦 vercel / next.js ⭐ 124,675 (+50) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts
- Aug 31, 2024📦 vercel / next.js ⭐ 124,487 (+39) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social2 likes and reposts · 1 reply
- Nov 19, 2026📦 vercel / next.js ⭐ 143,721 (+68) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- Oct 7, 2026📦 vercel / next.js ⭐ 143,230 (+38) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- Sep 26, 2026📦 vercel / next.js ⭐ 142,463 (+31) 🗒 JavaScript The React Framework — @github-trending.bsky.social1 likes and repost
- Aug 27, 2026📦 vercel / next.js ⭐ 141,963 (+38) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- Jul 10, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 vercel / next.js ⭐ 140,578 (+176) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- May 13, 2026📦 vercel / next.js ⭐ 139,406 (+31) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- Apr 10, 2026📦 vercel / next.js ⭐ 138,815 (+63) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- Apr 5, 2026📦 vercel / next.js ⭐ 138,637 (+41) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- Mar 28, 2026📦 vercel / next.js ⭐ 138,508 (+38) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
- Mar 22, 2026📦 vercel / next.js ⭐ 138,434 (+32) 🗒 JavaScript The React Framework — @github-trending-js.bsky.social1 likes and repost
On GitHub · 26
- May 11, 2023Next.js Turbopack Support — getsentry/sentry-javascript365 reactions · 92 comments
- Feb 13, 2024eslint-plugin-react-hooks & "Flat Config" (ESLint 9) — react/react296 reactions · 108 comments
- Mar 25, 2021Add incremental static regeneration — sveltejs/kit183 reactions · 75 comments
- Nov 3, 2025feat: next.js 16 support — payloadcms/payload163 reactions · 25 comments
- Feb 25, 2021Make initial incremental/watch builds as fast normal builds — microsoft/TypeScript140 reactions · 31 comments
21 more on GitHub
- Oct 19, 2022[system] Support new style engine that generates static CSS files at build time — mui/material-ui96 reactions · 32 comments
- Nov 24, 2023Deprecate `setRequestLocale` in favor of `next/root-params` — amannn/next-intl95 reactions · 45 comments
- Feb 8, 2024📈 Tracking: Flat Config support — eslint/eslint91 reactions · 100 comments
- Jan 22, 2024add next.js app router example — mswjs/examples53 reactions · 61 comments
- May 11, 2023feat(client): esm support draft — prisma/orm35 reactions · 5 comments
- Apr 24, 2023RFC: The Next.js "App Router", React Server Component & "SSR with Suspense" story — apollographql/apollo-client-integrations28 reactions · 8 comments
- Jan 9, 2025feat: Key isolation — 47ng/nuqs24 reactions · 6 comments
- Jan 27, 2022fix(nextjs): TypeError: res.once is not a function — getsentry/sentry-javascript22 reactions · 1 comment
- May 2, 2024fix(next-auth): Add support for Next.js basePath configuration — nextauthjs/next-auth18 reactions · 27 comments
- Mar 9, 2024[labs/nextjs, labs/ssr-react, lit/react] Add support for Next.js v14 and App Router — lit/lit18 reactions · 3 comments
- Apr 16, 2021update Next.js example — bugsnag/bugsnag-js18 reactions · 3 comments
- Mar 20, 2026feat(next): prevent admin panel errors when cacheComponents is enabled — payloadcms/payload17 reactions · 11 comments
- Sep 7, 2020Modernize example for nextjs. Adds support for fast refresh, native p… — tailwindlabs/tailwindcss-setup-examples17 reactions · 4 comments
- Jun 24, 2022fix: don't fallback on rendering the html when the page is not found — serverless-nextjs/serverless-next.js15 reactions · 2 comments
- Mar 6, 2025Fix for next 15.2 and renderHTML should not be called in minimal mode — opennextjs/opennextjs-cloudflare12 reactions · 2 comments
- Dec 20, 2024fix: Deprecate `setRequestLocale` and add blog post on `next/root-params` — amannn/next-intl12 reactions · 13 comments
- Jan 28, 2022fix(nextjs): Unwrap `req` and `res` if necessary when instrumenting server — getsentry/sentry-javascript12 reactions · 5 comments
- Aug 12, 2021fix(nextjs): Next 11.1.0 compatibility — nrwl/nx12 reactions · 13 comments
- Oct 4, 2024Update auth.ts to await `params` in NextJS 15 — auth0/nextjs-auth010 reactions · 2 comments
- Mar 16, 2024Turbopack support for Blitz — blitz-js/blitz10 reactions · 12 comments
- Jan 27, 2023feat: bring action up to date — github/issue-labeler10 reactions
On Hacker News · 16
- Dec 3, 2025RCE Vulnerability in React and Next.js628 points · 259 comments
- May 31, 2025Next.js: The "Versatile" React Framework That Can't Handle Dynamic Routes17 points · 20 comments
- Mar 21, 2025Authorization Bypass in Next.js Middleware8 points
- May 7, 2026Six New High Severity CVEs for Next.js and 1 for React4 points · 2 comments
- May 15, 2026Next.js – Server-side request forgery in applications using WebSocket upgrades3 points
11 more on Hacker News
- May 7, 2026New security vulnerabilities disclosed in Next.js (patches released)3 points
- Apr 2, 2025RFC: Deployment Adapters API for Next.js3 points
- Aug 7, 2024Vercel/Next.js memory leak in Fetch API3 points
- Dec 29, 2025Next.js makes many tiny serverless requests for all visible links2 points · 1 comment
- Sep 17, 2025Next.js GET Cache Bypass via Multipart POST – Reproduces on Vercel.com2 points · 1 comment
- May 26, 2025How hardware identifiers work on a PC2 points
- Apr 9, 2025Next.js with Rspack1 point
- Jul 3, 2023Is server component default always a performance win? Or should it be opt-in?1 point
- Mar 29, 2022Next.js: Support SSG (one-time SSR) during runtime1 point
- Nov 3, 2021What libraries do you recommend for a Node.js CRUD web app?1 point · 1 comment
- Jan 19, 2021Unconfigured next.js application with TypeScript does not work in IE111 point
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository42 other files it gives its agents.
- apps/bundle-analyzer/AGENTS.mdAGENTS.md
- crates/AGENTS.mdAGENTS.md
- evals/AGENTS.mdAGENTS.md
- evals/evals/agent-062-pokedex-dev-loop/AGENTS.mdAGENTS.md
- evals/next-upgrade/apps/member-dashboard/next-13/AGENTS.mdAGENTS.md
- evals/next-upgrade/apps/member-dashboard/next-15/AGENTS.mdAGENTS.md
- .github/AGENTS.mdAGENTS.md
- packages/next/AGENTS.mdAGENTS.md
- test/AGENTS.mdAGENTS.md
- turbopack/AGENTS.mdAGENTS.md
- evals/next-upgrade/apps/member-dashboard/next-13/CLAUDE.mdCLAUDE.md
- evals/next-upgrade/apps/member-dashboard/next-15/CLAUDE.mdCLAUDE.md
- authoring-skillsSkill
- backport-prSkill
- create-prSkill
- dce-edgeSkill
- deploy-release-testSkill
- docs-diagramsSkill
- flagsSkill
- gate-testsSkill
- gh-stackSkill
- insight-error-pageSkill
- next-rspackSkill
- pr-status-triageSkill
- react-syncSkill
- react-vendoringSkill
- rebase-prSkill
- router-actSkill
- run-testsSkill
- runtime-debugSkill
- rust-turbopackSkill
- sandbox-benchSkill
- update-docsSkill
- v8-jitSkill
- write-api-referenceSkill
- write-guideSkill
- next-bundle-optimizerSkill
- next-cache-components-adoptionSkill
- next-cache-components-optimizerSkill
- next-dev-loopSkill
- next-partial-prefetching-adoptionSkill
- next-partial-prefetching-optimizerSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
32 rules. About 3 are common, 11 are distinctive, and 18 are very specific to this project.
≈3
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
18
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 45
Before editing or creating files in any subdirectory (e.g., packages/*, crates/*), read all README.md files in the directory path from the …
- Very specific: line 47
Example: Before editing turbopack/crates/turbopack-ecmascript-runtime/js/src/nodejs/runtime/runtime-base.ts, read:
- Very specific: line 74
Default agent rule: If you are changing Next.js source, start pnpm --filter=next dev in a separate terminal session before making edits …
- Very specific: line 104
For type errors only: Use pnpm --filter=next types (~10s) instead of pnpm --filter=next build (~60s).
- Very specific: line 168
Prefer integration tests over unit tests: Use Next.js e2e tests (test/e2e/, test/development/, test/production/) for Next.js features, and …
- Very specific: line 262
Check and see if you are creating a fork PR or a branch PR.
- Distinctive: line 278
Keep the description minimal, but write it so that someone not on the team can understand the PR.
- Very specific: line 279
Use the template's ### What?, ### Why?
- Distinctive: line 281
When linking to a Slack thread, share the details of the conclusion rather than only the link.
- Distinctive: line 282
Add review comments on the PR where needed to explain the logic behind a change to the reviewer.
- Distinctive: line 283
Don't copy the template's HTML comment, or the contributor checklists, into the description.
- Very specific: line 382
Use DEBUG=next:* for debug logging
- Very specific: line 383
Use NEXT_TELEMETRY_DISABLED=1 when testing locally
- Distinctive: line 394
Always treat environment variable values as sensitive unless they are known test-mode flags.
- Common: line 396
Never print or paste secret values (tokens, API keys, cookies) in chat responses, commits, or shared logs.
- Common: line 398
If a required secret is missing locally, stop and ask the user rather than inventing placeholder credentials.
- Common: line 399
Never commit local secret files.
- Distinctive: line 400
When sharing command output, summarize and redact sensitive-looking values.
- Distinctive: line 407
If a Git fetch, push, or partial-clone hydration fails or hangs with an SSH signing error such as:
- Distinctive: line 419
Before a force-push or stack rebase that may hydrate partial-clone objects, prefer a lightweight SSH preflight.
- Very specific: line 425
Use skills for conditional, deep workflows.
- Distinctive: line 445
Do NOT add "Generated with Claude Code" or co-author footers to commits or PRs
- Distinctive: line 446
Keep commit messages concise and descriptive
- Very specific: line 448
Do NOT mark PRs as "ready for review" (gh pr ready) - leave PRs in draft mode and let the user decide when to mark them ready
- Distinctive: line 477
Keep these high-frequency guardrails in mind:
- Very specific: line 481
Use __NEXT_SHOW_IGNORE_LISTED=true when you need full internal stack traces
- Very specific: line 486
If a flag is consumed in pre-compiled runtime internals, also wire runtime env values (next-server.ts/export/worker.ts as needed).
- Very specific: line 488
Keep require() behind compile-time if/else branches for DCE (avoid early-return/throw patterns).
- Very specific: line 495
Test-writing gotchas (PPR under cache components, mode-specific setup, log assertions, stack traces, router act tests) are in …
- Very specific: line 505
If Turbopack produces unexpected errors after switching branches or pulling, check if packages/next-swc/native/*.node is stale.
- Very specific: line 511
When adding highlight={...} attributes to code blocks, carefully count the actual line numbers within the code block
- Very specific: line 528
Read docs/README.md inside that installed package first, then read the relevant pages from its docs/ directory before changing Turborepo …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Next.js Development Guide
Codebase structure
Monorepo Overview
This is a pnpm monorepo containing the Next.js framework and related packages.
next.js/
├── packages/ # Published npm packages
├── turbopack/ # Turbopack bundler (Rust) - git subtree
├── crates/ # Rust crates for Next.js SWC bindings
├── test/ # All test suites
├── examples/ # Example Next.js applications
├── docs/ # Documentation
└── scripts/ # Build and maintenance scriptsCore Package: packages/next
The main Next.js framework lives in packages/next/. This is what gets published as the next npm package.
Source code is in packages/next/src/.
Key entry points:
- Dev server:
src/cli/next-dev.ts→src/server/dev/next-dev-server.ts - Production server:
src/cli/next-start.ts→src/server/next-server.ts - Build:
src/cli/next-build.ts→src/build/index.ts
Compiled output goes to packages/next/dist/ (mirrors src/ structure).
Other Important Packages
packages/create-next-app/- Thecreate-next-appCLI toolpackages/next-swc/- Native Rust bindings (SWC transforms)packages/eslint-plugin-next/- ESLint rules for Next.jspackages/font/-next/fontimplementationpackages/third-parties/- Third-party script integrationspackages/next-mcp/-@next/mcp, MCP servers from App Router route handlers
README files
Before editing or creating files in any subdirectory (e.g., packages/*, crates/*), read all README.md files in the directory path from the repo root up to and including the target file's directory. This helps identify any local patterns, conventions, and documentation.
Example: Before editing turbopack/crates/turbopack-ecmascript-runtime/js/src/nodejs/runtime/runtime-base.ts, read:
turbopack/README.md(if exists)turbopack/crates/README.md(if exists)turbopack/crates/turbopack-ecmascript-runtime/README.md(if exists)turbopack/crates/turbopack-ecmascript-runtime/js/README.md(if exists - closest to target file)
Build Commands
# Build the Next.js package
pnpm --filter=next build
# Build all JS code
pnpm build
# Build all JS and Rust code
pnpm build-all
# Run specific task
pnpm --filter=next exec taskr <task>Fast Local Development
For iterative Next.js source development, default to watch mode plus the explicit test script that matches the mode and bundler being verified.
Default agent rule: If you are changing Next.js source, start pnpm --filter=next dev in a separate terminal session before making edits (unless it is already running). If you skip this, explicitly state why (for example: docs-only, test-only, read-only investigation, or CI-only analysis).
Test-only changes: When changes are confined to test/, do not start pnpm --filter=next dev or rebuild Next.js. Run the relevant mode-specific tests directly; the test harness builds test fixtures as needed. This assumes the workspace is already bootstrapped and framework build outputs are current. Missing or stale framework build outputs still require a build.
1. Start watch build in background:
# Auto-rebuilds on file changes (~1-2s per change vs ~60s full build)
# Keep this running while you iterate on code
pnpm --filter=next dev2. Run focused tests with the matching mode script:
# Development mode with Turbopack
pnpm test-dev-turbo test/path/to/test.ts
# Development mode with Webpack
pnpm test-dev-webpack test/path/to/test.ts
# Production build+start with Turbopack
pnpm test-start-turbo test/path/to/test.ts
# Production build+start with Webpack
pnpm test-start-webpack test/path/to/test.ts3. When done, kill the background watch process (if you started it).
For type errors only: Use pnpm --filter=next types (~10s) instead of pnpm --filter=next build (~60s).
Bootstrapping a new clone or worktree does not require pnpm build-all. pnpm install already pulls in recent published native bindings, so build only what your work changes: pnpm --filter=next build when edits are limited to core Next.js files, pnpm build when changes span multiple JS packages, and pnpm build-all only when changes include Rust/Turbopack code. Test-only changes do not require a framework rebuild before CI push.
Switching branches or pulling can still require a build when it moves JS or Rust source relative to your build outputs: rebuild the affected parts before running tests (pnpm build for JS, pnpm build-all for Rust). If Next.js fails to start afterwards, the published native bindings may lag canary; see Stale Native Binary.
Bundler Selection
Turbopack is the default bundler for both next dev and next build. To force webpack:
next build --webpack # Production build with webpack
next dev --webpack # Dev server with webpackThere is no --no-turbopack flag.
Testing
# Run specific test file (development mode with Turbopack)
pnpm test-dev-turbo test/path/to/test.test.ts
# Run tests matching pattern
pnpm test-dev-turbo -t "pattern"
# Run development tests
pnpm test-dev-turbo test/development/Test commands by mode:
pnpm test-dev-turbo- Development mode with Turbopack (default)pnpm test-dev-webpack- Development mode with Webpackpnpm test-start-turbo- Production build+start with Turbopackpnpm test-start-webpack- Production build+start with Webpack
Other test commands:
pnpm test-unit- Run unit tests only (fast, no browser)pnpm new-test- Generate a new test file from template (interactive)
Generate tests non-interactively (for AI agents):
Generating tests using pnpm new-test is mandatory.
# Use --args for non-interactive mode. It is a `turbo gen` flag, so pass it
# directly, without a `--` separator.
# Format: pnpm new-test --args <appDir> <name> <type>
# appDir: true/false (is this for app directory?)
# name: test name (e.g. "my-feature")
# type: e2e | production | development | unit
pnpm new-test --args true my-feature e2e
# Unit tests are created as a flat test/unit/<name>.test.ts (appDir is ignored)
pnpm new-test --args false my-util unitWriting Tests
Test writing expectations:
- Prefer integration tests over unit tests. Use Next.js e2e tests
(
test/e2e/,test/development/,test/production/) for Next.js features, and Turbopack execution tests (turbopack/crates/turbopack-tests/tests/execution/) for Turbopack features. - Avoid unit tests that map directly to the implementation, except for complicated algorithms. You can temporarily write unit tests to verify an implementation, but don't commit them or add them to the pull request unless they are necessary.
- Use
pnpm new-testto generate new test suites - it creates proper structure with fixture files - Normalize filesystem paths in cross-platform assertions. Windows
path.join()uses backslashes. Normalize paths from mocked filesystem calls, includingcpsources and destinations, before positive or negative checks that use/. Otherwise tests can fail on Windows or pass for the wrong reason. Use
retry()fromnext-test-utilsinstead ofsetTimeoutfor waiting// Good - use retry() for polling/waiting import { retry } from 'next-test-utils' await retry(async () => { const text = await browser.elementByCss('p').text() expect(text).toBe('expected value') }) // Bad - don't use setTimeout for waiting await new Promise((resolve) => setTimeout(resolve, 1000))Do NOT use
check()- it is deprecated. Useretry()+expect()instead// Deprecated - don't use check() await check(() => browser.elementByCss('p').text(), /expected/) // Good - use retry() with expect() await retry(async () => { const text = await browser.elementByCss('p').text() expect(text).toMatch(/expected/) })Prefer real fixture directories over inline
filesobjects// Good - use a real directory with fixture files const { next } = nextTestSetup({ files: __dirname, // points to directory containing test fixtures }) // Avoid - inline file definitions are harder to maintain const { next } = nextTestSetup({ files: { 'app/page.tsx': `export default function Page() { ... }`, }, })- Keep
revalidatePath/revalidateTagarguments and fetch URLs suite-unique. In deploy mode the cache lives at Vercel project scope and deploy e2e suites share one project per matrix dimension: revalidation purges by tag/path across the whole project, and fetch cache entries are keyed by URL across deployments. Prefix tags with the suite slug (e.g.cacheTag('app-static:thankyounext')), never revalidate/from a deploy-active fixture (every app has a/route — move the page to a suite-unique route and revalidate that instead), and when a test depends on a cached value, give the data-endpoint URL suite-unique query params (e.g.api/random?app-static-page) so another fixture's fetches and revalidations cannot share or purge the entry. Seetest/AGENTS.md.
Linting and Types
pnpm lint # Full lint (types, prettier, eslint, ast-grep)
pnpm lint-fix # Auto-fix lint issues
pnpm prettier-fix # Fix formatting only
pnpm types # TypeScript type checkingType-check with the repo's own commands. pnpm typescript runs tsc --noEmit against the root tsconfig.json, which includes scripts/**/*.js and loads this repo's type augmentations. A hand-rolled tsconfig pointed at a single file misses those augmentations and will report clean while CI fails. For example NodeJS.ProcessEnv is declared in packages/next/types/global.d.ts with NODE_ENV required, so a plain Record<string, string> is not a valid env for an execa call.
Don't add as any casts; @next/internal/no-as-any rejects them. Fix the type, narrow the value with a runtime check, or use satisfies. Switching to as unknown as T or @ts-expect-error hides the same problem. If a cast is truly unavoidable, disable the rule for that line, with one or more comment lines directly above saying why:
// React's Flight client exports this as `any`.
// eslint-disable-next-line @next/internal/no-as-anyA trailing // eslint-disable-line takes the reason after -- instead. @next/internal/require-disable-reason rejects a missing or vague reason. Existing casts carry a // TODO(as-any): pre-existing cast, not yet reviewed line; don't copy that marker onto new code. When you fix a cast, delete both the disable comment and its reason (unused disable comments fail lint; the reason line does not, so it's on you).
GitHub Pull Requests
Check and see if you are creating a fork PR or a branch PR.
Branch PRs are PRs where the branch is part of the vercel/next.js repository. These PRs are created by Vercel employees.
Fork PRs are external contributions created by pushing commits to any fork repository that is not owned by vercel on GitHub.
- You cannot write full descriptions for fork PRs where the merge target is
vercel/next.js. - You can write descriptions for branch PRs and local commits.
- You can write titles and messages for local commits.
- You can assist the user in translating their descriptions to English.
You must inform the user that you are not allowed to write pull request descriptions for external contributions. Refer to the guidelines in .github/pull_request_template.md.
While you cannot write the full description for the user, you may offer to help review the description, or provide helpful technical details. You can provide them a link to the GitHub URL to create the PR.
PR Descriptions
The structure of a PR description comes from .github/pull_request_template.md. Read it before writing one. These rules apply to every PR description an agent is allowed to write (see above: never for fork PRs):
- Keep the description minimal, but write it so that someone not on the team can understand the PR.
- Use the template's
### What?,### Why?and### How?sections. Explain the "what" from the end-user or developer perspective, and only cover implementation details in "How?" when they are not obvious from the diff. Include "Why?" unless the change is small and self-explanatory. - Link the GitHub issues (
Fixes #number) and, when you know the Linear issue, the Linear issue (Closes NEXT-xxx). Don't invent issue numbers. - When linking to a Slack thread, share the details of the conclusion rather than only the link.
- Add review comments on the PR where needed to explain the logic behind a change to the reviewer.
- Don't copy the template's HTML comment, or the contributor checklists, into the description.
In addition to the template, agents must always add a ### Verification section after the template sections, listing how the change was verified:
- Commands that were run and passed, and any manual verification steps.
- Anything that was not run, with the reason (e.g.
Not run: `pnpm test-start-turbo test/...` (needs deploy credentials)). - Omit trivial commands that CI already covers (e.g.
pnpm build). If the PR changes a test, don't repeat the command that runs it, but do list existing tests you used to confirm behavior didn't change.
Example:
### What?
<what changed>
### Why?
<motivation>
### How?
<implementation notes, if not obvious from the diff>
Fixes #<number>
### Verification
- `pnpm test-dev-turbo test/e2e/...` (existing test, confirms behavior is unchanged)
- Not run: `<command>` (<reason>)Adopting a Fork PR
Fork PRs run without repository secrets, so deploy tests never run on them. To run those tests, a maintainer adopts the PR: the contributor's commits are re-pushed to a branch in vercel/next.js and a replacement PR is opened from there.
pnpm pr-adopt <pr-number> # adopt
pnpm pr-adopt <pr-number> --dry-run # report without pushingThe script resolves the vercel/next.js remote itself, checks out the PR, pushes adopt/<pr-number>, and opens a draft PR whose body is the contributor's description verbatim behind an Adopts #N. Closes #N. line. The adopted PR inherits the original's base branch; it is never retargeted at canary.
Contributor commits usually arrive unsigned, and protected branches require verified signatures, so the branch is re-signed before pushing. Each Author is preserved and the tree is checked to be byte-identical afterwards. Note that %G? reports whether a signature verifies, not whether one exists, so it reads N for every commit when SSH signing has no gpg.ssh.allowedSignersFile; signature detection reads the raw commit headers instead.
Draft and closed PRs can both be adopted, since a contributor may still be iterating or may have given up on an unreviewed change; the status is reported rather than enforced. Only merged PRs are refused, because their commits are already in the base branch.
Adoption grants the contributor's code access to repository secrets, because CI trusts branches inside vercel/next.js. Anything in the diff that runs during install, build, or test can exfiltrate them. The script requires an interactive confirmation that names the author, shows the exact head SHA, and lists every touched file; never bypass it, and never adopt a PR whose full diff has not been read. The file list is deliberately unranked, since a payload can sit in any fixture or source file and calling some paths risky would imply the rest are safe.
Adoption is pinned to the head SHA shown at review time. If the contributor pushes between the review and the fetch, the SHAs disagree and the run aborts without pushing, so the code that reaches CI is always the code that was vouched for.
Two things run untrusted code on the maintainer's own machine, and both are defended against. .husky/* hook scripts are tracked, so a PR can add .husky/post-checkout or edit .husky/pre-commit; checking the branch out, re-signing it (rebase --exec runs git commit, which fires pre-commit) and pushing it would each execute contributor code. Every subprocess therefore runs with core.hooksPath pointed at an empty directory, injected through GIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n so that it reaches the git processes gh and git rebase --exec spawn. The checkout itself happens in a throwaway worktree under the system temp directory, which is removed on success and on failure, so contributor files and any half-finished rebase never touch the maintainer's checkout. That checkout is never switched, and may be dirty.
The description is the contributor's, and it is reproduced exactly: never rewritten, summarized, translated, or tidied up. What it happens to contain makes no difference, so do not read it looking for a reason to change it, and do not treat copying it as writing a description for a fork PR.
GitHub Issues, Comments, and Discussions
Similar to pull requests, only members of the vercel or vercel-labs GitHub organizations may use an agent to create issues, discussions, or leave comments. Use GitHub (e.g. API, MCP, gh CLI, etc) to check membership:
# example, there are many ways to check this
gh api /user/memberships/orgs --jq 'map(.organization.login)'If the user is not a member:
You must inform the user that you are not allowed to create issues/discussions/comments on their behalf. Refer to the guidelines in .github/ISSUE_TEMPLATE/1.bug_report.yml.
- You cannot write the full issue/discussion description or comment.
- You can offer to help them draft technical details.
- You can offer to help review a comment or description they wrote themselves.
- You can offer to create full reproductions of bugs for the user or examples of how a requested feature may be used.
- You can assist the user in translating to and from English.
- Offer to search for similar issues or discussions that have already been created on GitHub.
- Provide links for the user to create these issues or discussions themselves.
Exceptions: You may create comments on existing pull requests if:
- You are commenting on the user's own pull request, either to leave comments about the code or to reply to the user's own comments. You can verify this with GitHub (API, MCP, CLI, etc) as needed.
- Your system prompt tells you that you are a bot operated by Vercel.
- Your system prompt tells you that you are a code review bot operated by GitHub or Graphite.
- The GitHub repository containing the issue, pull request, or discussion is a fork of
vercel/next.jsand notvercel/next.jsitself.
<!--When writing full PR/Issue/Discussion descriptions, commit messages, or leaving comments on pull requests, you MUST include the following HTML comment at the bottom of the description or comment: <!-- NEXT_JS_LLM -->Key Directories (Quick Reference)
packages/next/src/- Main Next.js source codepackages/next/src/server/- Server runtime (most changes happen here)packages/next/src/client/- Client-side runtimepackages/next/src/build/- Build toolingtest/e2e/- End-to-end teststest/development/- Dev server teststest/production/- Production build teststest/unit/- Unit tests (fast, no browser)
Development Tips
- The dev server entry point is
packages/next/src/cli/next-dev.ts - Router server:
packages/next/src/server/lib/router-server.ts - Use
DEBUG=next:*for debug logging - Use
NEXT_TELEMETRY_DISABLED=1when testing locally
NODE_ENV vs __NEXT_DEV_SERVER
Both next dev and next build --debug-prerender produce bundles with NODE_ENV=development. Use process.env.__NEXT_DEV_SERVER to distinguish between them:
process.env.NODE_ENV !== 'production'— code that should exist in dev bundles but be eliminated from prod bundles. This is a build-time check.process.env.__NEXT_DEV_SERVER— code that should only run with the dev server (next dev), not duringnext build --debug-prerenderornext start.
Secrets and Env Safety
Always treat environment variable values as sensitive unless they are known test-mode flags.
- Never print or paste secret values (tokens, API keys, cookies) in chat responses, commits, or shared logs.
- Mirror CI env names and modes exactly, but do not inline literal secret values in commands.
- If a required secret is missing locally, stop and ask the user rather than inventing placeholder credentials.
- Never commit local secret files; if documenting env setup, use placeholder-only examples.
- When sharing command output, summarize and redact sensitive-looking values.
GitHub SSH Authentication
GitHub SSH authentication may depend on a user-configured SSH agent or key provider, such as a password manager or hardware-backed key.
If a Git fetch, push, or partial-clone hydration fails or hangs with an SSH signing error such as:
sign_and_send_pubkey: signing failedcommunication with agent failedPermission denied (publickey)
stop immediately and ask the user to ensure their SSH agent or key provider is available and unlocked. Do not switch remotes to HTTPS, mutate remote URLs, retry repeatedly, or attempt another authentication workaround unless the user explicitly requests it.
Before a force-push or stack rebase that may hydrate partial-clone objects, prefer a lightweight SSH preflight. If it fails due to the SSH agent or key provider, ask the user to make it available or unlock it before continuing.
Specialized Skills
Use skills for conditional, deep workflows. Keep baseline iteration/build/test policy in this file.
$pr-status-triage- use whenever asked about CI failures, PR reviews, or PR status (incl. reading canary CI)$create-pr- branch, commit, push, and draft PR creation workflow$rebase-pr- rebase a PR onto canary or restack dependent PRs safely$deploy-release-test- validate a commit preview package and trigger the fulltest_e2e_deploy_release.ymlsuite$backport-pr- cherry-pick merged PRs fromcanarytoreleases/lts/activeorreleases/lts/maintenance$flags- feature-flag wiring across config/schema/define-env/runtime env$dce-edge- DCE-saferequire()patterns and edge/runtime constraints$react-vendoring-entry-base.tsboundaries and vendored React type/runtime rules$react-sync- build a local React checkout and sync it into Next.js for testing$runtime-debug- runtime-bundle/module-resolution regression reproduction and verification$next-rspack- @next/rspack-core and @next/rspack-binding maintenance (rspack/ directory)$rust-turbopack- Rust/Turbopack build, test, snapshot, and benchmarking workflow (cargo, nextest, UPDATE=1, clippy, Miri, wasi)$gate-tests-@gate/@force-gatetest directives: replacingit.skip/fake-green skips, conditions, variant-shard fixtures$run-tests- test bootstrap in a fresh checkout, CI env matching, fixture gitignore traps, flaky-test reproduction$authoring-skills- how to create and maintain skills in.agents/skills/
Commit and PR Style
- Do NOT add "Generated with Claude Code" or co-author footers to commits or PRs
- Keep commit messages concise and descriptive
- PR descriptions follow the What?/Why?/How? structure of
.github/pull_request_template.md, plus a Verification section (see PR Descriptions) - Do NOT mark PRs as "ready for review" (
gh pr ready) - leave PRs in draft mode and let the user decide when to mark them ready
Pre-validate before committing to avoid slow lint-staged failures (~2 min each):
# Run exactly what the pre-commit hook runs on your changed files:
pnpm prettier --with-node-modules --ignore-path .prettierignore --write <files>
npx eslint --config eslint.config.mjs --fix <files>Rebuilding Before Running Tests
Rebuild before running Next.js integration tests when framework source files changed, whether from your own edits or from a branch switch or pull that moved JS or Rust source:
- Only edited
test/files, with current framework build outputs? → No framework rebuild or watch build needed; run the relevant tests directly. - Changed only core Next.js files (
packages/next/**)? →pnpm --filter=next build - Changed JS across multiple packages? →
pnpm build - Changed Turbopack or other Rust code? →
pnpm build-all - Next.js fails to start with Turbopack errors? → The published canary native bindings may lag the source; see Stale Native Binary.
Development Anti-Patterns
For runtime internals, use focused skills:
- Feature-flag plumbing and runtime bundle wiring:
$flags(.agents/skills/flags/SKILL.md) - DCE and edge/runtime constraints:
$dce-edge(.agents/skills/dce-edge/SKILL.md) - React vendoring and
entry-base.tsboundaries:$react-vendoring(.agents/skills/react-vendoring/SKILL.md) - Debugging and verification workflow:
$runtime-debug(.agents/skills/runtime-debug/SKILL.md)
Keep these high-frequency guardrails in mind:
- Reproduce module resolution and bundling issues with the normal mode-specific test command so package resolution is exercised.
- Validate edge bundling regressions with
pnpm test-start-webpack test/e2e/app-dir/app/standalone.test.ts - Use
__NEXT_SHOW_IGNORE_LISTED=truewhen you need full internal stack traces
Core runtime/bundling rules (always apply; skills above expand on these with verification steps and examples):
- New flags: add type in
config-shared.ts, schema inconfig-schema.ts, anddefine-env.tswhen used in user-bundled code. - If a flag is consumed in pre-compiled runtime internals, also wire runtime env values (
next-server.ts/export/worker.tsas needed). define-env.tsaffects user bundling; it does not control pre-compiled runtime bundle internals.- Keep
require()behind compile-timeif/elsebranches for DCE (avoid early-return/throw patterns). - In edge builds, force feature flags that gate Node-only imports to
falseindefine-env.ts. react-server-dom-webpack/*imports must stay inentry-base.ts; consume via component module exports elsewhere.app-page.tsis a build template compiled by the user's bundler: Anyrequire()in this file is traced by webpack/turbopack atnext buildtime. You cannot require internal modules with relative paths because they won't be resolvable from the user's project. Instead, export new helpers fromentry-base.tsand access them viaentryBase.*in the template.
Test Gotchas
Test-writing gotchas (PPR under cache components, mode-specific setup, log assertions, stack traces, router act tests) are in test/AGENTS.md. Running tests outside the happy path (fresh-checkout bootstrap, CI env flags, smoke tests, flaky tests, ignored fixture files) is in $run-tests.
Node.js Source Maps
findSourceMap()needs--enable-source-mapsflag or returns undefined- Source map paths vary (webpack:
./src/, tsc:src/) - try multiple formats process.cwd()in stack trace formatting produces different paths in tests vs production
Stale Native Binary
If Turbopack produces unexpected errors after switching branches or pulling, check if packages/next-swc/native/*.node is stale. Delete it and run pnpm install to get the npm-published binary instead of a locally-built one.
pnpm install already pulls in the latest published native bindings, which usually track canary closely. If Next.js still fails to start after that, native binding changes may have landed on canary after the last npm publish. Build the native bindings from source with pnpm build-all.
Documentation Code Blocks
- When adding
highlight={...}attributes to code blocks, carefully count the actual line numbers within the code block - Account for empty lines, import statements, and type imports that shift line numbers
- Highlights should point to the actual relevant code, not unrelated lines like
return (or framework boilerplate - Double-check highlights by counting lines from 1 within each code block
Server Security: Internal Header Filtering
Next.js strips internal headers from incoming requests via filterInternalHeaders() in packages/next/src/server/lib/server-ipc/utils.ts. This runs at the entry point in packages/next/src/server/lib/router-server.ts before any server code executes. Only headers listed in the INTERNAL_HEADERS array are stripped.
When reviewing PRs: if new code reads a request header that is not a standard HTTP header (like content-type, accept, user-agent, host, authorization, cookie, etc.), flag it for security review. The header may be forgeable by an external attacker if it is not in the INTERNAL_HEADERS filter list in packages/next/src/server/lib/server-ipc/utils.ts.
<!-- BEGIN:turborepo-agent-rules -->This is NOT the Turborepo you know
Turborepo configuration, task behavior, and CLI commands can vary between installed versions and may differ from your training data. Resolve the turbo package from this file's directory or relevant workspace; in monorepos, it may not be visible from the repository root. For example, run node -p "require.resolve('turbo/package.json')" from a workspace that depends on turbo.
Read docs/README.md inside that installed package first, then read the relevant pages from its docs/ directory before changing Turborepo configuration or commands. Heed deprecation notices. These bundled docs match the installed package version and are available without network access.
This block is written and re-added by turbo before repository-scoped commands when an AI agent is detected. In the Turborepo source repository, its template is defined in crates/turborepo-cli/src/cli/agent_guidance.rs. Removing the managed block while updates are enabled means a later qualifying invocation will add it again. Set "agentGuidance": false in the root turbo.json or turbo.jsonc to opt out; this does not remove an existing block. Keep the block committed with your work to avoid an uncommitted change on the next agent invocation.
<!-- END:turborepo-agent-rules -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

