nextjs - ✅(Solved) Fix agents-md provides non-working command in AGENTS.md instructions [3 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#89772Fetched 2026-04-08 00:21:24
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×3referenced ×2issue_type_added ×1

Fix Action

Fixed

PR fix notes

PR #89774: fix(codemod): ensure agent instruction is executable

Description (problem / solution / changelog)

In the current form, the agents-md command writes an instruction that doesn't actually execute, since the command is only on @canary.

What?

In the current form, the agents-md command writes an instruction that doesn't actually execute. There are two issues. One is that it writes the instruction without @canary and it only exists in canary right now. The second is that, without embedding a version in the instruction, it does version inference logic and in the case of a version range, the command fails.

Why?

I work with agents running in their own sandboxes, not on my laptop where I have done out of band setup work. So the agent needs to be able to clone the repo and do necessary steps from AGENTS.md for things to work.

How?

Fixes #89772 Fixes #89773

Capture the invocation details when it is run and write the instructions to AGENTS.md so that the original command will be re-run.

For the version issue, look for a version in package-lock.json which should always have the correct and precise version.

Changed files

  • packages/next-codemod/bin/agents-md.ts (modified, +8/-0)
  • packages/next-codemod/lib/__tests__/agents-md-unit.test.js (added, +270/-0)
  • packages/next-codemod/lib/agents-md.ts (modified, +46/-2)

PR #90067: fix(codemod): handle semver ranges in agents-md version detection

Description (problem / solution / changelog)

What?

Fix agents-md codemod failing when Next.js version is specified as a semver range in package.json (e.g. ^16, ~16.1.0) and the package is not yet installed.

Why?

getNextjsVersion() only detects the installed version via require.resolve('next/package.json'). When Next.js isn't installed yet (common when running the codemod for the first time, or when an AI agent re-runs the generated command in a fresh sandbox), the function returns null and the codemod fails with:

Could not find documentation for Next.js v16. This version may not exist on GitHub yet.

How?

Added a fallback in getNextjsVersion() that reads the version range from package.json dependencies and extracts a concrete version using a new exported extractVersionFromRange() helper:

  • ^16.1.316.1.3
  • ~16.1.016.1.0
  • ^1616.0.0
  • >=15.0.015.0.0
  • ^16.2.0-canary.1616.2.0-canary.16

The fallback is only used when require.resolve fails and monorepo detection finds nothing.

Checklist

  • Related issues linked using fixes #number
  • Tests added
  • Errors have a helpful link attached — N/A (no new error messages)

Fixes #89773 Fixes #89772

Changed files

  • packages/next-codemod/lib/__tests__/agents-md.test.js (added, +128/-0)
  • packages/next-codemod/lib/agents-md.ts (modified, +64/-12)

PR #90145: docs: fix pnpm new-test example to forward args

Description (problem / solution / changelog)

Summary: Fixes an incorrect example in AGENTS.md that showed pnpm new-test --args .... The correct usage is to forward arguments to the script with --, e.g. pnpm new-test -- --args ....

Changes:

Update the example and add a short note explaining that -- forwards args to the script. Related:

Closes #89772 Verification:

Documentation-only change; verify the example in AGENTS.md shows pnpm new-test -- --args ....

Changed files

  • AGENTS.md (modified, +4/-4)

Code Example

Operating System:
  Platform: linux
  Arch: x64
  Version: #12-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan  9 20:46:52 UTC 2026
  Available memory (MB): 31021
  Available CPU cores: 22
Binaries:
  Node: 24.12.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: standalone
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/emonty/next.js

To Reproduce

Run npx @next/codemod agents-md --output AGENTS.md Inspect the instruction added to AGENTS.md. Execute that command in a clean checkout as-if you are an agent in a sandbox: npx @next/codemod agents-md --output AGENTS.md

Current vs. Expected behavior

I expect the agent being given the instruction to be able to re-run the instruction successfully.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #12-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan  9 20:46:52 UTC 2026
  Available memory (MB): 31021
  Available CPU cores: 22
Binaries:
  Node: 24.12.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

extent analysis

Fix Summary

The codemod agents-md is not idempotent on newer Node versions (Node 24) and fails on a second run because it tries to write AGENTS.md without overwriting or cleaning the previous file.
Two quick fixes:

  1. Run the codemod on a supported Node LTS (v20‑v22).
  2. Make the command idempotent – either delete the file first or add an overwrite flag (if the codemod supports it).

Below are concrete steps and a tiny wrapper script that works on any

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING