Which Format Should Own Repo Context: Cursor .mdc Rules or AGENTS.md?
AGENTS.md should own baseline repository context for every team using more than one AI coding agent, while .cursor/rules/*.mdc should own only file-pattern and manual IDE rules. Cursor reads both formats natively, whereas OpenAI Codex CLI, Google Antigravity, and Claude Code read AGENTS.md and ignore .mdc frontmatter completely. Splitting ownership by scope eliminates duplicate prose and prevents terminal agents from missing critical build or safety rules.
According to the official AGENTS.md specification, the format is used by over 60,000 open-source projects: “Think of AGENTS.md as a README for agents: a dedicated, predictable place to provide the context and instructions to help AI coding agents work on your project.” Use the ownership matrix below to assign every instruction in your repository to exactly one file:
| Repository Context Type | Canonical Owner | Why That Format Wins |
|---|---|---|
| Build, test, lint, and package manager commands | AGENTS.md (repo root) | Every coding agent (Cursor, OpenAI Codex CLI, Google Antigravity, Claude Code) needs identical commands on startup. |
| Directory map & architectural invariants | AGENTS.md (repo root) | Keeps a single readable map across terminal CLIs and editors without duplicating prose across formats. |
| Framework & file-path conventions (e.g., src/app/api/**/*.ts) | .cursor/rules/*.mdc (glob-scoped) | YAML globs inject rules only when matching files open, saving thousands of tokens outside that subsystem. |
| Dangerous migrations & rare runbooks (@-mentioned) | .cursor/rules/*.mdc (manual mode) | Setting alwaysApply: false with no globs keeps rare procedures out of routine context until @-mentioned. |
| Monorepo package-specific overrides | Nested AGENTS.md / AGENTS.override.md | Codex CLI and Antigravity walk from repo root to the active subdirectory; Codex overrides with AGENTS.override.md. |
| Personal review checklists, commit habits & cross-repo workflows | Portable SKILL.md library (Prompttly) | Personal habits pollute team Git diffs; syncing skills to ~/.claude/skills, ~/.codex/skills, and Cursor avoids repo churn. |
Never put the same rule in both an alwaysApply: true .mdc file and a root AGENTS.md file. Cursor injects both into the model context simultaneously, wasting tokens and creating merge-conflict drift whenever one file is edited without the other.
Side-by-Side Architecture: .cursor/rules/*.mdc Frontmatter vs. Plain AGENTS.md
Cursor .mdc rules and AGENTS.md solve different engineering constraints: .mdc optimizes context injection inside the Cursor editor via YAML metadata, while AGENTS.md optimizes tool-neutral portability across IDEs and terminal agents. Choosing between them—or splitting work across both—requires understanding their exact parsing rules, byte caps, and trade-offs.
| Dimension | .cursor/rules/*.mdc | AGENTS.md | Honest Trade-off |
|---|---|---|---|
| File location & extension | .cursor/rules/*.mdc (plain .md ignored in Agents Window) | AGENTS.md in repo root or nested subdirectories | .mdc requires exact extension & directory; AGENTS.md is a single predictable root filename. |
| Frontmatter & syntax | Markdown + YAML frontmatter (description, globs, alwaysApply) | Pure Markdown; zero proprietary frontmatter fields | .mdc gives programmatic activation control; AGENTS.md stays human-readable anywhere. |
| Activation modes | 4 modes: Always Apply, Glob Match, Agent-Selected, Manual @-mention | Directory-walked startup load (per-session or subdirectory entry) | .mdc avoids wasting tokens on irrelevant files; AGENTS.md loads its full body when active. |
| Size & token limits | Recommended <= 500 lines per rule file | Codex 32 KiB cumulative cap; Antigravity 24 KB file / 20k-token total cap | Oversized AGENTS.md files hit silent truncation in Codex CLI and pointer demotion in Antigravity. |
| Cross-agent support | Cursor IDE / Agents Window (ignored by Codex CLI, Claude Code, Terminal UI) | Open standard across 60,000+ OSS repos: Codex, Cursor, Antigravity, Claude Code v2.1.277+ | AGENTS.md owns multi-agent portability; .mdc is editor-bound. |
| Override mechanism | Separate file per concern in .cursor/rules/ subfolders | Nested AGENTS.md or AGENTS.override.md (Codex) closer to working dir | Codex stops appending once 32 KiB fills; .mdc scales cleanly via targeted globs. |
| File references | @file mentions trigger agent tool reads rather than inline injection | Markdown links / paths or Claude Code @path expansion | Cursor keeps referenced templates out of prompt preamble until needed. |
Where .cursor/rules/*.mdc wins decisively is conditional triggering. In a 400-file full-stack TypeScript monorepo, attaching React Server Component rules only when src/app/**/*.tsx opens prevents Tailwind or JSX conventions from polluting backend database migrations. Conversely, where AGENTS.md wins decisively is cross-tool leverage: a single 90-line root file works identically in Cursor, OpenAI Codex CLI, and Google Antigravity without converting YAML schemas. For a deeper look at organizing multi-file .mdc folders, see our guide on Cursor rules directory structure.
How Do Cursor .mdc Activation Modes Differ From AGENTS.md Directory Discovery?
Cursor .mdc files control prompt injection through three YAML frontmatter fields—alwaysApply, globs, and description—that map to four distinct activation modes inside the IDE. By contrast, AGENTS.md uses zero frontmatter and relies on filesystem directory traversal from the project root down to your working directory.
As documented in the official Cursor Rules documentation: “A plain .md file in .cursor/rules is ignored by the rules system because it has no frontmatter to specify description, globs, and alwaysApply.” The same documentation recommends keeping individual rule files under 500 lines and referencing canonical files with @ mentions rather than pasting boilerplate inline.
Meanwhile, OpenAI's Codex CLI AGENTS.md guide specifies a strict directory walk: “Codex skips empty files and stops adding files once the combined size reaches the limit defined by project_doc_max_bytes (32 KiB by default).” Google Antigravity enforces an analogous 24 KB (24,000-byte) per-file limit and a 20,000-token aggregate rules budget across active global and always-on rules, per the Google Antigravity Rules documentation.
Side-by-Side Example: Splitting Repo Commands From API Validation Globs
Instead of stuffing API Zod conventions into AGENTS.md or pasting pnpm commands into .mdc, divide the exact same project into two non-overlapping files:
1. AGENTS.md (Universal Repo Context — ~25 lines, ~950 bytes)
# AGENTS.md
## Build & Verification Commands
- Install dependencies: `pnpm install --frozen-lockfile`
- Typecheck & lint: `pnpm typecheck && pnpm lint`
- Run unit tests: `pnpm vitest run <path>`
## Repository Invariants
- Never modify auto-generated files under `src/generated/`.
- All database schema changes require a reversible SQL migration under `prisma/migrations/`.
- Redact bearer tokens and customer PII from structured logs.2. .cursor/rules/api-handlers.mdc (File-Scoped IDE Rule — loads only on API routes)
---
description: Enforce Zod schema validation and ApiResponse<T> envelopes on route handlers
globs: src/app/api/**/*.ts
alwaysApply: false
---
# Next.js Route Handler Conventions
- Validate request bodies with `Schema.safeParse()` imported from `@/lib/schemas`.
- Return typed `ApiResponse<T>` envelopes instead of throwing raw `Error` objects.
- Keep route handlers under 80 lines; extract domain logic into `@/services/`.Plain .md files placed inside .cursor/rules/ are silently ignored by Cursor's Agents Window because they lack .mdc frontmatter, whereas AGENTS.md in the repository root loads across both Cursor and terminal coding agents. To explore how Codex CLI handles nested overrides in subdirectories, read our Codex CLI AGENTS.override.md and config.toml guide.
What Happens When Both .cursor/rules/*.mdc and AGENTS.md Exist in the Same Repo?
When both .cursor/rules/*.mdc and AGENTS.md live in the same repository, Cursor loads both instruction sources simultaneously while non-Cursor agents ignore .mdc completely. Knowing how each runtime resolves both files prevents silent rule blindness when teammates switch tools.
| Coding Agent Runtime | Reads .cursor/rules/*.mdc? | Reads AGENTS.md? | Runtime Precedence & Caveats |
|---|---|---|---|
| Cursor (Agents Window) | Yes (.cursor/rules/*.mdc) | Yes (root & nested) | Supports all 4 .mdc modes plus AGENTS.md; plain .md inside .cursor/rules/ is ignored. |
| OpenAI Codex CLI | No | Yes ($CODEX_HOME -> root -> CWD) | Reads AGENTS.override.md > AGENTS.md > fallback list; stops at 32 KiB project_doc_max_bytes. |
| Google Antigravity | No | Yes (root & parent folders) | Loads AGENTS.md, GEMINI.md, and .agents/rules/*.md within 24 KB/file and 20,000-token budget. |
| Anthropic Claude Code | No | Yes (v2.1.277+ if no CLAUDE.md) | Defaults to claude-md-or-agents-md; set claude-md-and-agents-md to load both. Ignores AGENTS.override.md. |
Notice two subtle runtime traps documented in primary specifications. First, inside Cursor's own surface split, the Terminal UI does not read .mdc files in .cursor/rules/, reading plain *.md files and AGENTS.md instead—meaning AGENTS.md is the only repository format shared seamlessly between Cursor's editor window and terminal workflows. Second, according to the Claude Code Memory documentation, Claude Code added direct AGENTS.md support in v2.1.277, but skips AGENTS.md by default whenever any CLAUDE.md or CLAUDE.local.md file sits in the directory chain unless instructionFiles is configured to claude-md-and-agents-md.
For teams coordinating all four runtimes in one monorepo, see our multi-agent rules architecture blueprint and our diagnostic guide on AGENTS.md across Codex, Cursor, and Antigravity.
The Sprawl Moment: When Two Formats Drift Apart Across Three Coding Agents
A staff engineer maintains a payments monorepo where half the squad codes in Cursor and the other half runs OpenAI Codex CLI and Google Antigravity in terminal sessions. During a sprint migration from Express to Fastify and Vitest, the engineer updates .cursor/rules/backend-testing.mdc on their primary MacBook to require pnpm vitest run and Fastify schema hooks, forgetting that a six-month-old AGENTS.md file at the repo root still instructs agents to run npm test and write Express middleware. Inside Cursor, every PR looks spotless. On Friday afternoon, a teammate opens the repository on a Linux workstation using Codex CLI while another runs a Google Antigravity refactoring subagent; both agents read only the stale AGENTS.md, scaffold Express routes, execute the legacy test command, and waste two hours debugging why CI rejects code that Cursor accepted.
How Do You Prevent Drift Between .cursor/rules/*.mdc, AGENTS.md, and Personal Skills?
You prevent drift by keeping repository facts in AGENTS.md, limiting .cursor/rules/*.mdc strictly to IDE file globs, and moving all reusable developer workflows out of Git into a single synced skill library. Separating repo-owned invariants from person-owned skills guarantees that switching laptops or tools never strands an instruction in the wrong format.
Prompttly is a skill manager for AI agents — one library for your skills and prompts that syncs into Claude Code, Codex, ChatGPT, and Claude and is one hotkey away on your Mac, so your setup follows you across every machine, repo, and tool.
Separating repository invariants in AGENTS.md from personal reusable skills in Prompttly prevents .cursor/rules/*.mdc from turning into a personal prompt dumping ground that pollutes team pull requests. Here is how a messy dual-format setup collapses into clean ownership:
140+ Lines Repeated Across Files
- •
alwaysApply: true.mdcrepeats test commands already inAGENTS.md - • Personal PR-review prompts committed into
.cursor/rules/ - • Codex CLI and Claude Code miss
.mdcrules on Mac & Linux boxes - • Context burns double tokens in Cursor on every turn
Zero Overlap Across Tools
- •
AGENTS.md(< 4 KB) owns build, test, lint, and repo boundaries - •
.cursor/rules/*.mdcowns onlyglobsand manual@rules - • Prompttly syncs personal skills to
~/.claude/skills&~/.codex/skills - • Mac hotkey palette inserts any prompt into Cursor or browser in <200ms
With Prompttly's two-way Mac sync, version history, MCP write access, and // commands inside ChatGPT and Claude, personal engineering checklists stay consistent whether you are editing in Cursor, running Codex in Ghostty, or reviewing specs in a browser. If you are migrating personal rules across laptops without dirtying Git worktrees, read our guide on syncing Cursor rules across machines or compare broader ecosystems in Claude Skills vs. Cursor Rules and AGENTS.md.
When Should You NOT Use Both Formats (and When Is Prompttly Overkill)?
Do not maintain both .cursor/rules/*.mdc and AGENTS.md unless your repository actively uses Cursor glob scoping alongside multiple AI coding agents. Dual files create a second surface to review in pull requests, so pick the single simplest configuration when your stack fits any of these cases:
- Cursor-only team on one stack: If every contributor works exclusively inside Cursor IDE and relies heavily on file-path
globs(such as*.tsxvs*.sql), keep everything in.cursor/rules/*.mdcand skipAGENTS.md. - Terminal-first or Codex/Antigravity-only repo: If nobody on the team uses Cursor's Agents Window, plain
AGENTS.md(plus nestedAGENTS.override.mdwhere needed) avoids proprietary frontmatter with zero extra tooling. - Small project with fewer than three rules on one machine: A single 40-line
AGENTS.mdchecked into Git is completely sufficient—you do not need a dedicated skill manager like Prompttly until you juggle 10+ reusable workflows across multiple tools or laptops.
POSIX Audit Script: Verify Format Ownership and Byte Caps Before Merging
Run a fast pre-commit shell audit to catch oversized AGENTS.md files approaching Codex's 32 KiB (32,768 bytes) or Antigravity's 24,000-byte ceiling, plain .md files accidentally dropped into .cursor/rules/, and .mdc rules exceeding Cursor's 500-line limit:
#!/usr/bin/env bash
set -euo pipefail
# 1. Catch plain .md files inside .cursor/rules/ (ignored by Cursor Agents Window)
if find .cursor/rules -maxdepth 3 -name '*.md' 2>/dev/null | grep -q .; then
echo "ERROR: Found plain .md files in .cursor/rules/ — rename to .mdc with frontmatter or move to AGENTS.md."
exit 1
fi
# 2. Enforce <= 500 lines on every .cursor/rules/*.mdc file
while IFS= read -r -d '' mdc; do
lines=$(wc -l < "$mdc")
if [ "$lines" -gt 500 ]; then
echo "WARN: $mdc has $lines lines (exceeds 500-line Cursor best practice)."
fi
done < <(find .cursor/rules -name '*.mdc' -print0 2>/dev/null)
# 3. Audit cumulative AGENTS.md byte budget against Antigravity 24 KB & Codex 32 KiB limits
total_bytes=0
while IFS= read -r -d '' doc; do
bytes=$(wc -c < "$doc")
total_bytes=$((total_bytes + bytes))
if [ "$bytes" -gt 24000 ]; then
echo "WARN: $doc is $bytes bytes (exceeds Antigravity 24,000-byte per-file limit)."
fi
done < <(find . -maxdepth 4 \( -name 'AGENTS.md' -o -name 'AGENTS.override.md' \) -print0)
echo "Total AGENTS.md chain size: $total_bytes / 32768 bytes (Codex default project_doc_max_bytes)"Frequently Asked Questions: Cursor .mdc Rules vs. AGENTS.md
Should I use .cursor/rules/*.mdc or AGENTS.md for my repository?
Use AGENTS.md for universal repository facts—build commands, test scripts, architecture invariants, and forbidden edits—so Cursor, OpenAI Codex CLI, Google Antigravity, and Claude Code share one source of truth. Reserve .cursor/rules/*.mdc strictly for path-scoped globs and manual @-mentioned templates inside Cursor.
Does Cursor read AGENTS.md if .cursor/rules/*.mdc already exists?
Yes. Cursor recognizes both .cursor/rules/*.mdc files and AGENTS.md in the same repository. Keep repo-wide defaults in AGENTS.md without duplicating them into an alwaysApply: true .mdc rule so Cursor does not pay double context tokens on every turn.
Why does Cursor ignore plain .md files inside .cursor/rules/?
Cursor project rules in the IDE Agents Window require the .mdc extension because the parser expects YAML frontmatter fields (description, globs, alwaysApply) to determine rule activation. A plain .md file inside .cursor/rules/ is ignored by the IDE rules engine, whereas AGENTS.md is read as plain Markdown.
Can OpenAI Codex CLI or Claude Code read .cursor/rules/*.mdc files?
No. Neither OpenAI Codex CLI nor Anthropic Claude Code parses .cursor/rules/*.mdc YAML frontmatter or glob triggers. Codex CLI reads AGENTS.md and AGENTS.override.md within its 32 KiB project_doc_max_bytes cap, while Claude Code v2.1.277+ reads CLAUDE.md and AGENTS.md natively.
How do you keep .cursor/rules/*.mdc and personal skills synchronized across machines and tools?
Keep repository-specific rules in Git (AGENTS.md plus glob-scoped .mdc files) and store personal workflows in an external skill manager like Prompttly. Prompttly maintains one cloud library that syncs native skill folders into ~/.claude/skills and ~/.codex/skills, pairs with .cursor/rules, and opens from a sub-200ms Mac hotkey.
Related Prompt Resources
Keep personal skills synced alongside clean repo rules
Store repo invariants in AGENTS.md, keep personal workflows out of Git, and sync reusable skills across Claude Code, Codex, and your sub-200ms Mac hotkey palette.