AGENTS.md for Next.js
A complete, production-ready AGENTS.md example for Next.js projects — token-optimized to 365 tokens, ready to drop into your repo. Plus a free generator that tailors it to your exact stack in 3 questions.
What is AGENTS.md?
AGENTS.md is a machine-readable specification file that tells AI coding assistants (Claude Code, Cursor, GitHub Copilot, Windsurf) exactly how to work in your codebase — the real commands to run, the permission boundaries, and code style rules they must follow. Unlike documentation written for humans, AGENTS.md is optimised for agents: every line prevents a concrete mistake.
AGENTS.md example for Next.js
Here is a complete AGENTS.md for a Next.js project, optimized to 365tokens using MDPilot's 5-pass optimizer:
# AGENTS.md: Coding Assistant Instructions for Next.js Project
This document outlines the guidelines for AI coding assistants to follow when contributing to this Next.js project.
## Environment Setup
To ensure consistency, run the following commands in your terminal:
```bash
npm install
npm run next lint --fix
```
## Build and Test Commands
For file-scoped builds and tests, use the following commands:
```bash
npm run next build
npm run next test
```
## Code Style Rules
This project uses TypeScript in strict mode and Tailwind CSS for styling. Ensure all code is formatted according to the following rules:
* Use absolute imports with the `@/` prefix
* Adhere to TypeScript strict mode
* Utilize Tailwind CSS classes for styling
## Key Project Paths
* `pages/`: Client-side routes
* `app/`: Server-side routes
* `components/`: Shared UI components
* `public/`: Static assets
## Permission Boundaries
The following boundaries are established for AI coding assistants:
### Allowed
* Automatically fixing linting errors
* Generating new components in the `components/` directory
* Updating existing component props
### Approve
* Renaming or removing existing components
* Modifying server-side routes in `app/`
* Updating `next.config.js` file
### Never
* Modifying `package.json` file
* Running `npm install` or `npm update` commands
## PR Format
All pull requests must follow the standard GitHub guidelines and include a clear description of changes made.Why Next.js projects need AGENTS.md
When working with Next.js projects, it's essential to consider the distinction between App Router and Pages Router, as well as the differences between server and client components. The `next dev`, `next build`, `next start`, and `next lint` scripts must also be used accordingly. To avoid common pitfalls, such as incorrectly configuring Vercel deployment or misusing TypeScript strict mode, AGENTS.md provides a clear set of guidelines for AI coding assistants to follow. By adhering to these guidelines, developers can ensure their Next.js projects are properly set up and maintainable.
Generate your own AGENTS.md for Next.js
Answer 3 questions about your project and MDPilot generates a AGENTS.md grounded in your exact stack — real commands, real paths, no hallucinated scripts.
Generate AGENTS.md free →Frequently asked questions
What is AGENTS.md?
AGENTS.md is an open standard for AI coding assistant instructions that provides guidelines for contributing to a project.
How do I set up my Next.js project according to AGENTS.md?
To set up your Next.js project, run the commands outlined in the Environment Setup section of AGENTS.md, such as `npm install` and `npm run next lint --fix`.
Can I use relative imports instead of absolute imports with the `@/` prefix?
No, this project requires the use of absolute imports with the `@/` prefix to ensure consistency and avoid import errors.
How do I handle TypeScript strict mode warnings in my Next.js project?
To handle TypeScript strict mode warnings, review the warnings and address them accordingly, ensuring that all code is properly typed and formatted.