Skip to main content

How to Create the Perfect AGENTS.md (incl. Template)

Learn how to create a perfect AGENTS.md file for AI agents. Including universal template, tool compatibility, and best practices.

FHFinn Hillebrandt
AI Programming
How to Create the Perfect AGENTS.md (incl. Template)
Links marked with * are affiliate links. If a purchase is made through such links, we receive a commission.

Maybe you know the feeling:

Your AI coding assistant just doesn't understand your project properly. You switch from Claude to Cursor, then to Continue.dev, and have to start from scratch with explanations each time.

Or even worse: You've written an elaborate CLAUDE.md. Claude Code loads it natively, while support in other tools varies. Before switching tools, check which rules the new tool actually loads.

One possible shared base is AGENTS.md. The Markdown file can collect project rules, but support differs by tool.

In this article, I'll show you how to create a clear AGENTS.md and check your tool's current support in its documentation.

TL;DRKey Takeaways
  • AGENTS.md is a plain Markdown file with no special syntax that collects project instructions for AI coding tools, much like a README.
  • Which tools load it differs. Claude Code reads AGENTS.md itself since version 2.1.277, but by default only when no CLAUDE.md is involved. Codex uses it as its main file.
  • Put in what the AI needs to know about your project: common tasks, recurring mistakes, quirks of your setup, and your standards.

1. What Is an AGENTS.md File?

AGENTS.md is a Markdown convention for AI coding instructions. Think of it like a README file aimed at a supporting tool.

The format is now stewarded by the Agentic AI Foundation under the Linux Foundation. According to the official AGENTS.md site, more than 60,000 open-source projects use it.

The genius of it:

It is simple Markdown without special syntax or frontmatter. A tool must explicitly support AGENTS.md or be configured for it before it will load the instructions.

AGENTS.md can be practical for shared rules.

Some tools support instructions in subdirectories or a hierarchy. Others load only a fixed file. Verify this behavior before using several AGENTS.md files.

2. Which Tools Support Which Standard?

The AI coding landscape is fragmented. Each tool does its own thing. Here you can see at a glance which configuration standards are supported by which tools:

Columns:
|
Tool
AGENTS.md
CLAUDE.md
GEMINI.md
Cursor Rules
Native Config
CLI Tools(5 entries)
Claude Code
Anthropic
ConfigurableNativeNoNoCLAUDE.md
Codex CLI
OpenAI
NativeFallbackNoNoAGENTS.md
Gemini CLI
Google
ConfigurableNoNativeNoGEMINI.md
Aider
Open Source
ConfigurableNoNoNo.aider.conf.yml
Factory Droid
Factory.ai
NativeNativeNoNo.factory/droids/*.md
IDE & Editors(6 entries)
Cursor
Cursor Inc.
NativeNativeNoNative.cursor/rules/*.mdc
Windsurf (Devin Desktop)
Cognition
NativeNoNoSimilar.devin/rules/*.md
Amp
Sourcegraph
NativeFallbackNoNoAGENTS.md
Zed Editor
Zed Industries
NativeNativeNativeFallbackAGENTS.md
JetBrains Junie
JetBrains
NativeNoNoNo.junie/AGENTS.md
Replit Agent
Replit
PartialNoNoNoreplit.md
IDE Extensions(9 entries)
GitHub Copilot
Microsoft
NativeNativeNativeNocopilot-instructions.md
Continue.dev
Open Source
ProposedNoNoNo.continue/rules/*.md
Cody
Sourcegraph
NoNoNoNo.vscode/cody.json
Amazon Q
AWS
NoNoNoNo.amazonq/rules/*.md
Tabnine
Tabnine
PartialNoNoNo.tabnine/guidelines/*.md
Supermaven
Cursor (acquired)
NoNoNoNoEditor config
Augment Code
Augment
NativeNativeNoNo.augment/rules/*.md
Cline
Open Source
NativeNoNoNo.clinerules/*.md
Roo Code
Open Source
NativeNoNoNo.roo/rules/*.md
Autonomous Agents(3 entries)
Devin
Cognition
NativeNoNoNoDashboard
Jules
Google
NativeNoNoNoAGENTS.md
Poolside AI
Poolside
NoNoNoNoEnterprise config
Terminal Tools(1 entries)
Warp Terminal
Warp
NativeImportImportImportAGENTS.md
Native supportPartial/WorkaroundNo support
Official AGENTS.md documentation

The official AGENTS.md page describes a dedicated place for project context and instructions.

For the two most widely used terminal agents, the loading behavior is documented in detail. Claude Code has read AGENTS.md itself since version 2.1.277, but by default only when no CLAUDE.md is involved. Since version 2.1.281, per the changelog, this also works on Amazon Bedrock, Google Vertex AI, Microsoft Foundry, through LLM gateways, and with telemetry disabled. Codex treats AGENTS.md as its primary file from the start.

Claude Code
Where the tool looks
At startup in the working directory and every directory above it, in subdirectories when it reads a file there
Multiple files
Default: AGENTS.md only without CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md; both with claude-md-and-agents-md
Requirements and limits
Version 2.1.277 or later; otherwise import AGENTS.md with @AGENTS.md in a CLAUDE.md
Codex
Where the tool looks
First ~/.codex, then from the project root down to the current working directory
Multiple files
At most one file per directory; AGENTS.override.md before AGENTS.md, closer files take precedence
Requirements and limits
Up to 32 KiB by default (project_doc_max_bytes); extra filenames via project_doc_fallback_filenames
Sources: Claude Code Docs, OpenAI Codex Docs
gradually.ai

2.1 My Recommendation for Maximum Compatibility

A controlled approach for several tools:

Copy shared instructions
# Create AGENTS.md only if it does not already exist
if [ -e AGENTS.md ] || [ -L AGENTS.md ]; then
  printf '%s\n' 'AGENTS.md already exists. Merge shared rules manually.'
else
  cp CLAUDE.md AGENTS.md
fi

# Retain CLAUDE.md for Claude Code
# Retain GEMINI.md for Gemini CLI when you use it

# Reconcile shared rules manually in the relevant files

3. Structure and Layout of an AGENTS.md

AGENTS.md is deliberately kept simple. No YAML frontmatter, no special syntax. Just clean Markdown.

After dozens of iterations, this structure has proven optimal:

Optimal AGENTS.md Structure
# Project Name

Brief description of the project and its main goals.

## Development Environment
- Build commands and scripts
- Testing instructions
- Important dependencies

## Code Style Guidelines
- Formatting rules
- Naming conventions
- Architecture patterns

## Project Context
- Important files and their purpose
- Unusual patterns or gotchas
- Performance-critical areas

## Testing Instructions
- Test runner commands
- Coverage requirements
- CI/CD processes

What you should avoid:

  • Too many details (Codex reads only 32 KiB by default, and Anthropic recommends keeping CLAUDE.md under 200 lines)
  • Outdated information (nothing is worse than wrong instructions)
  • Tool-specific syntax (stick to standard Markdown)
  • Sensitive information (no secrets or credentials!)

4. Step by Step to the Perfect AGENTS.md

Now it gets practical. I'll show you how to create an AGENTS.md in just a few minutes:

4.1 Project Analysis: What Does the AI Need to Know?

Before you start, ask yourself these questions:

  1. What are the most common tasks in your project?
  2. What mistakes does the AI keep making?
  3. What's unusual about your setup?
  4. What standards are important to you?

The answers to these belong in your AGENTS.md.

4.2 The Universal AGENTS.md Template

Here's my proven template that you can copy and customize directly:

AGENTS.md Universal Template
# [Project Name]

[One-sentence description of what the project does]

## Development Setup

```bash
# Installation
npm install  # or yarn/pnpm

# Development
npm run dev

# Build
npm run build

# Tests
npm test
```

## Tech Layers

- **Framework**: [e.g., Next.js 16, React 19]
- **Language**: [e.g., TypeScript with strict mode]
- **Styling**: [e.g., Tailwind CSS v4]
- **Database**: [e.g., PostgreSQL with Prisma]
- **Testing**: [e.g., Jest + React Testing Library]

## Project Structure

```
src/
├── app/          # Next.js App Router
├── components/   # Reusable UI components
├── lib/          # Utilities and services
├── hooks/        # Custom React hooks
└── types/        # TypeScript type definitions
```

## Code Standards

### General Rules
- Prefer TypeScript over JavaScript
- Use functional components with hooks
- Follow ESLint configuration
- Write tests for new features

### Naming Conventions
- Components: PascalCase (UserProfile.tsx)
- Utilities: camelCase (formatDate.ts)
- Constants: SCREAMING_SNAKE_CASE
- Types/Interfaces: PascalCase with suffix (UserType)

### File Organization
- Colocate tests with source files
- Group related components in folders
- Use index.ts for clean imports

## Important Patterns

### API Calls
Always use the API client from lib/api:
```typescript
import { apiClient } from '@/lib/api'
const data = await apiClient.get('/endpoint')
```

### State Management
- Use React Context for global state
- Prefer local state when possible
- Consider Zustand for complex state

## Testing Guidelines

- Write tests alongside implementation
- Focus on user behavior, not implementation
- Maintain > 80% coverage for critical paths
- Use data-testid for reliable selection

## Common Pitfalls to Avoid

- DON'T: Create new files unless necessary
- DON'T: Use console.log in production code
- DON'T: Ignore TypeScript errors
- DON'T: Skip tests for "simple" features
- DO: Check existing components before creating new ones
- DO: Follow established patterns in the codebase
- DO: Keep functions small and focused

## Performance Considerations

- Lazy load heavy components
- Use React.memo for expensive renders
- Optimize images with next/image
- Monitor bundle size

## Deployment

- Main branch deploys to production
- PR previews on Vercel
- Environment variables in .env.local
- Secrets managed via Vercel dashboard

## Additional Resources

- Architecture decisions: docs/architecture.md
- API documentation: docs/api.md
- Component library: Storybook at localhost:6006

4.3 Customization for Your Project

The template is just the start. Here's my proven process for customization:

  1. Week 1: Use the basic template
  2. Daily: Note when the AI does something wrong
  3. Weekly: Update the AGENTS.md with the learnings
  4. After 1 month: Major revision based on experience

An example from my practice: After 2 weeks, I had added 15 specific rules for my Next.js blog system. The AI error rate dropped by 70%.

5. Avoiding Common Beginner Mistakes

I see these mistakes over and over (and have made some of them myself):

  1. Being too general: "Write good code" doesn't help. Be specific: "Use async/await instead of .then() chains"
  2. Information overload: Long files are hard to maintain and easily become outdated. Keep the rules relevant to the task, and link to documentation for the details.
  3. Forgetting to update: Your project evolves, but the AGENTS.md stays old = chaos
  4. Tool-specific features: Use only standard Markdown for maximum compatibility
  5. No examples: Show the AI how it's done right with code examples
  6. Sensitive data: Never put API keys or passwords in AGENTS.md!

6. Pro Tips for Advanced Usage

Time for the advanced tricks from my daily practice:

6.1 Hierarchical AGENTS.md for Large Projects

Multi-Level AGENTS.md Setup
project/
├── AGENTS.md                 # Global project rules
├── frontend/
│   └── AGENTS.md            # Frontend-specific
├── backend/
│   └── AGENTS.md            # Backend-specific
└── tests/
    └── AGENTS.md            # Test-specific

Some tools load the nearest file, while others do not. Codex walks from the project root down to your working directory and appends the files in that order, so the closer file takes precedence. Claude Code loads a subdirectory's AGENTS.md as soon as it reads a file there and that directory has no CLAUDE.md of its own. For other tools, verify the behavior with a small test project before relying on area-specific rules.

6.2 Dynamic Sections for Different Modes

Context-Dependent Instructions
## Mode: Development
- Use verbose logging
- Include debug statements
- Skip optimization

## Mode: Production
- No console.log statements
- Optimize for performance
- Include error tracking

## Mode: Testing
- Mock external services
- Use test database
- Verbose test output

6.3 Team Synchronization with Git

AGENTS.md belongs in the repository! But with a system:

Team AGENTS.md with Changelog
# Project Guidelines

[... Main content ...]

---
## Changelog
<!-- Document team updates -->
- 2025-09-26: Added TypeScript strict rules (FH)
- 2025-09-20: Updated test coverage requirements (TM)
- 2025-09-15: Initial version (FH)

## Personal Overrides
<!-- Don't commit this section -->
<!-- Move locally to AGENTS.personal.md -->

6.4 Performance Monitoring

Measure the impact of your AGENTS.md:

  • Track AI error rate before/after updates
  • Measure time to correct solution
  • Document recurring problems

Compare results before and after a change on recurring tasks. That shows whether the instructions actually help.

7. Migration from Existing Systems

You already have a CLAUDE.md or another configuration? Move shared rules gradually and retain the native files for the tools you use.

7.1 Copying shared rules from CLAUDE.md

Copy shared rules
# Create AGENTS.md only if it does not already exist
if [ -e AGENTS.md ] || [ -L AGENTS.md ]; then
  printf '%s\n' 'AGENTS.md already exists. Merge shared rules manually.'
else
  cp CLAUDE.md AGENTS.md
fi

# Retain tool-specific rules in their native files
# Test each file using the documentation for the tool you use

If you used a workaround to connect Claude Code to AGENTS.md in the past, you can clean it up. A CLAUDE.md that only imports @AGENTS.md can stay, because Claude Code still reads the file only once. A SessionStart hook that prints AGENTS.md should go, though. Otherwise the content ends up in the context twice.

7.2 From Multiple Configs to One AGENTS.md

Many projects have .cursorrules, .claude/config, etc. Here's how to consolidate:

  1. Collect all existing configs
  2. Identify overlaps
  3. Move common rules into AGENTS.md with a clear structure
  4. Retain native files for the tools you use
  5. Test every tool with a representative task

8. Maintaining the Configuration Over Time

These practices keep your configuration understandable:

  • Check documentation: Read the current tool documentation before changing files
  • Reconcile shared rules: Deliberately apply changes to the files that need them
  • Repeat tests: Check a representative task after a tool update
  • Separate tool-specific rules: Keep native files for their respective tools

My advice: Start with a short, clear file and extend it only after your tool demonstrably uses it.

9. Conclusion: Use AGENTS.md Deliberately

A well-maintained instruction file can make recurring project rules visible and reduce coordination work.

Complete automatic compatibility does not exist. Filenames, load paths, and precedence differ between tools.

Use the template only as a starting point and adapt it to your tool's documentation and workflow.

Frequently Asked Questions

An AGENTS.md is a Markdown file with project instructions for AI coding tools that support this filename. It can collect shared rules in a visible place. Whether and how a tool loads it is defined by that tool's documentation.

AGENTS.md is a cross-tool format for project instructions; CLAUDE.md can hold Claude-specific rules. Claude Code has supported AGENTS.md directly since version 2.1.277. By default, it reads AGENTS.md only when the working directory and its ancestors contain no CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md. Under /config > Project instructions, choose claude-md-and-agents-md to load both formats. For Claude-specific project rules, see our guide to creating a CLAUDE.md file.

In the project root, where most tools expect it. Additional files in subdirectories only make sense when your tool documents nested instructions.

Yes. Current Claude Code versions from 2.1.277 onward can read AGENTS.md directly when the built-in AGENTS plugin is enabled. By default, Claude Code loads AGENTS.md only when there is no CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md in the working directory or its ancestors. Choose claude-md-and-agents-md under /config > Project instructions to load both. Before version 2.1.281, some sessions, including some Bedrock or telemetry-disabled sessions, could not read AGENTS.md directly.

Yes, if you want to share project context across tools, because .claude/agents/ does not replace AGENTS.md. AGENTS.md holds project rules for supporting tools, while .claude/agents/ defines specialized task agents for Claude Code only.

Among others Codex, Cursor, GitHub Copilot, Gemini CLI, Jules, Devin, Windsurf, Junie, Zed, Warp, Aider, Amp, Roo Code, and Augment Code, according to the official AGENTS.md site. Codex reads existing files automatically, and Claude Code does from version 2.1.277 when its built-in plugin is enabled and no CLAUDE.md exists.

There is no universally optimal line count. Keep only the always-needed instructions in the file, move detailed material into other documents, and link to them.

Yes. Move shared rules to AGENTS.md once your tools support it. To make Claude Code load both AGENTS.md and CLAUDE.md, choose claude-md-and-agents-md under /config > Project instructions, or import @AGENTS.md from a short CLAUDE.md. Keep Claude-specific additions in CLAUDE.md.
FH

Finn Hillebrandt

AI Expert & Blogger

Finn Hillebrandt is the founder of Gradually AI, an SEO and AI expert. He helps online entrepreneurs simplify and automate their processes and marketing with AI. Finn shares his knowledge here on the blog in 50+ articles as well as through the AI Business Club.

Learn more about Finn and the team, follow Finn on LinkedIn, join his Facebook group for ChatGPT, OpenAI & AI Tools or do like 17,500+ others and subscribe to his AI Newsletter with tips, news and offers about AI tools and online business. Also visit his other blog, Blogmojo, which is about WordPress, blogging and SEO.