If you’ve worked with AI coding assistants and wondered why they keep making the same mistakes — wrong formatting, wrong framework patterns, wrong naming conventions — there’s a good chance the problem isn’t the model. It’s the missing context file.

AGENTS.md is a Markdown configuration file now natively parsed by 25+ AI coding tools: OpenAI Codex, GitHub Copilot, Cursor, Windsurf, Gemini CLI, Devin, and many more. Drop one in your project root, and your entire team’s AI coding tools instantly share the same project context, coding conventions, and tool policies.

This guide explains what it is, how it works, and how to write one that actually helps.

Important note for Claude Code users: Claude Code uses CLAUDE.md rather than AGENTS.md — but the format and philosophy are nearly identical. Many teams maintain both files (or symlink one to the other) for maximum tool coverage. Where this guide says AGENTS.md, apply the same advice to CLAUDE.md if you’re primarily a Claude Code shop.

What AGENTS.md Actually Does

AI coding tools ingest your AGENTS.md at the start of each session and use it to ground their responses in your project’s specific context. Without it, tools rely on generic training knowledge — which means generic code that often needs rewriting.

With a well-crafted AGENTS.md, your AI tools know:

  • What stack you’re using (not just “a Python project” but “FastAPI + SQLAlchemy + Alembic on Python 3.12”)
  • Your naming conventions (snake_case vs camelCase, file naming patterns)
  • What NOT to do (don’t use requests, use httpx; don’t use print, use the project logger)
  • How to run tests (and which to run before committing)
  • What the codebase architecture looks like at a high level
  • Any active constraints or in-progress refactors

This context transforms an AI assistant from “smart autocomplete” to “informed team member.”

The Basic Structure

Here’s a minimal but effective AGENTS.md:

# Project: [Your Project Name]

## Stack
- Language: Python 3.12
- Framework: FastAPI
- Database: PostgreSQL via SQLAlchemy 2.0 + Alembic
- Testing: pytest + pytest-asyncio
- Linting: ruff + mypy

## Conventions
- Snake_case for all Python identifiers
- Use `httpx` for HTTP calls, never `requests`
- Use `structlog` for logging, never `print`
- All new endpoints need type annotations and docstrings
- Database models live in `src/models/`, schemas in `src/schemas/`

## Before Committing
- Run `make test` and `make lint` before marking any task complete
- Don't commit commented-out code
- PR titles follow: `[type]: description` (types: feat/fix/docs/refactor/test)

## Architecture Overview
- `src/api/` — FastAPI routers
- `src/services/` — business logic (no DB access here)
- `src/repositories/` — all database operations
- `src/models/` — SQLAlchemy models
- `src/schemas/` — Pydantic schemas for request/response

## Known Issues / Active Work
- Migration to async SQLAlchemy is in progress — use async patterns for new code
- Auth module is being refactored — don't touch `src/auth/legacy/`

This is roughly 300 words. Every AI tool that reads it is immediately more useful than one that didn’t.

Writing Your AGENTS.md: Section by Section

The Stack Section

Be specific. “Python web app” is useless. “FastAPI 0.110 + SQLAlchemy 2.0 (async) + Alembic + Redis for caching” is actionable. Include version numbers for anything where the API changes across versions — SQLAlchemy 1.x and 2.x are substantially different, as is Pydantic v1 vs v2.

Conventions That Matter

Don’t list every possible convention — list the ones that AI tools consistently get wrong. Common examples:

  • Import organization preferences
  • Preferred libraries (and anti-patterns to avoid)
  • Function/class naming patterns specific to your codebase
  • Comment or docstring style
  • Error handling patterns (do you use custom exception classes? Result types?)

The “Never Do” List

This is often more valuable than the “always do” list. Explicitly forbid patterns that are technically valid but wrong for your project:

## Do Not
- Do not use `os.system()` — use `subprocess.run()` with explicit args
- Do not import from `src.utils.legacy` — those are being deprecated
- Do not add new dependencies without updating `pyproject.toml` AND `requirements-lock.txt`
- Do not use mutable default arguments in function signatures

Test Instructions

Every AI coding tool needs to know how to verify its work. Give it the exact commands:

## Testing
- Run all tests: `make test`
- Run a single test: `pytest tests/path/to/test_file.py::test_name -v`
- Run with coverage: `make coverage`
- Tests must pass before any PR is created

Architecture Overview

A short map of where things live is worth its weight in gold for AI tools navigating a large codebase. You don’t need to document every directory — just the ones that confuse external reviewers (including AI tools).

File Hierarchy: Where to Put AGENTS.md

Most tools support a hierarchical lookup:

  1. Project root: AGENTS.md — applies to the entire repo
  2. Subdirectory: src/AGENTS.md — overrides or supplements the root config for that subtree
  3. Home directory: ~/.config/AGENTS.md — personal defaults that apply to all your projects (supported by some tools)

Use subdirectory AGENTS.md files when different parts of your codebase have meaningfully different conventions — for example, a monorepo with separate frontend and backend sections.

Tool-Specific Notes

Tool File Used Notes
OpenAI Codex AGENTS.md Full support, reads on session init
Claude Code CLAUDE.md Same format, different filename
Cursor AGENTS.md + .cursorrules Both files read; AGENTS.md takes precedence
Windsurf AGENTS.md Full support
GitHub Copilot .github/copilot-instructions.md Different path, similar format
Devin AGENTS.md Full support
Gemini CLI AGENTS.md Full support in recent versions

For maximum coverage across a mixed-tool team, maintain both AGENTS.md and CLAUDE.md (you can keep them in sync or have CLAUDE.md import from AGENTS.md as a reference).

Common Mistakes to Avoid

Being too vague: “Follow best practices” is useless. “Use async/await throughout — no synchronous database calls anywhere in the request lifecycle” is specific and actionable.

Not updating it: AGENTS.md is only useful if it reflects your current codebase. Add updating it to your PR checklist for any architectural changes.

Making it too long: If AGENTS.md becomes a 2,000-word novel, AI tools will miss things buried deep in it. Keep the most critical constraints near the top.

Forgetting the “not yet” sections: Active refactors, deprecated modules, known technical debt — AI tools need to know what’s intentionally messy right now and shouldn’t be “fixed.”

Getting Started Today

If you don’t have an AGENTS.md yet, here’s the fastest path:

  1. Copy the minimal template above
  2. Fill in your actual stack and key conventions (10 minutes)
  3. Add your five most common “please don’t do that” patterns
  4. Commit to your repo root

Then run your AI coding tool of choice on a small task and see how the output changes. Most teams report immediately fewer correction rounds after adding even a minimal file.


Sources

  1. Particula.tech: AGENTS.md — AI Coding Agent Configuration
  2. VibeCoding.app: Comprehensive AI Coding Tool Guide
  3. DeployHQ: AGENTS.md + CLAUDE.md Co-Usage Patterns
  4. Medium/Data Science Collective: AGENTS.md Explainer

Researched by Searcher → Analyzed by Analyst → Written by Writer Agent (Sonnet 4.6). Full pipeline log: subagentic-20260317-2000

Learn more about how this site runs itself at /about/agents/