Rules files are the simplest way to make AI coding tools behave like a senior developer on your team. Instead of repeating context in every prompt, you create a single file that the AI reads automatically on every chat and edit. This tutorial walks you through creating an AGENTS.md file—a standard that Cursor, GitHub Copilot, and other assistants now support.
Step 1: Create an AGENTS.md file
Start at the root of your repository. The name matters: many tools also recognize CLAUDE.md or .cursorrules, but AGENTS.md is the emerging cross-tool standard, so use that.
touch AGENTS.md
Once the file exists, every AI request will automatically load it as context—no need to @-mention it each time.
Step 2: Start with the essentials
List your tech stack, package manager, and test commands. This prevents the AI from guessing or using outdated commands.
# AGENTS.md
## Stack
- Next.js 14 (App Router) with TypeScript
- Tailwind CSS for styling
- Prisma + PostgreSQL
## Commands
- Dev: `npm run dev`
- Build: `npm run build`
- Test: `npm test`
- Lint: `npm run lint`
Step 3: Encode code style and architecture
Tell the AI how you write components, handle state, or structure folders. Be specific enough that the AI can apply these rules without asking for clarification.
## Style
- Server components by default; use "use client" only when needed.
- Use functional components, not classes.
- Never use `any`; prefer `unknown` and narrow types.
## Architecture
- Place shared UI components in `/components/ui`
- API routes live in `/app/api/*`
- Use Zod for validation
Include examples, not just abstract rules. For instance, show a good versus bad component snippet if you have a very specific pattern.
Step 4: Add constraints and don'ts
Explicitly show what to avoid. This is where you save hours of fixing bad suggestions that don't match your project's principles.
## Don'ts
- Do not modify generated migration files.
- Do not use Redux; use TanStack Query for server state.
- Do not import server-only modules into client components.
Step 5: Test and iterate
Ask the AI to perform a small task and check if it follows the rules. Tweak wording until it works consistently. A good test is to ask it to refactor a small component.
"Fix the button component to match our conventions as described in AGENTS.md"
Check the output against the rules you set. If it breaks a rule, adjust the wording to be clearer. Iterate until the AI behaves predictably.
rules/testing.md or rules/accessibility.md, and reference them from AGENTS.md with @rules/testing.md so you don't overload the main file.
That's it. Go create your AGENTS.md now and watch your AI assistant start following your rules from the very first prompt.
The trick is making rules specific enough to matter but not so rigid they break on edge cases. I'd love to see examples of teams iterating on these files.