---
title: "CLAUDE.md, AGENTS.md and rules files: lasting context for your agent"
description: "CLAUDE.md, AGENTS.md, Cursor and Copilot rules: which file each agent reads, what to put in it, what to avoid, and a template ready to copy."
url: "https://vibe-code.blog/en/agent-context-files"
lang: "en"
author: "Thierry Gustin"
published: "2026-12-04"
updated: "2026-12-04"
---

# CLAUDE.md, AGENTS.md and rules files: lasting context for your agent

> **Key takeaways** — A context file (CLAUDE.md for Claude Code, AGENTS.md for most other agents, .cursor/rules for Cursor, copilot-instructions.md for Copilot) is a Markdown file your coding agent reads at the start of every session. It holds the project's commands, conventions and rules so the agent doesn't reinvent them. The simplest setup as of November 21, 2026: one short, specific AGENTS.md, plus a CLAUDE.md that imports it if needed.

CLAUDE.md, AGENTS.md and rules files all do the same job: they give your coding agent context that survives from one session to the next. They are plain Markdown files in your project that the agent reads automatically before it starts working. Written well, they stop the AI from reinventing your conventions in every conversation; written badly, they get ignored or make things worse.

## Why your agent needs a context file

A coding agent has no memory between sessions. Claude Code's documentation says it plainly: each session begins with a fresh context window. What you explained yesterday ("prices are stored in cents," "run tests with `npm test`") is gone unless it's written somewhere the agent rereads.

That's one of the [12 mistakes that sink vibe coding projects](https://vibe-code.blog/en/vibe-coding-mistakes): leaving the AI without memory. A context file is the simplest fix, and it pairs well with [a proper PRD](https://vibe-code.blog/en/prd-for-ai-builders) or a [spec-driven development](https://vibe-code.blog/en/spec-driven-development) workflow. If you're just starting out, our [complete guide to vibe coding](https://vibe-code.blog/en/vibe-coding-complete-guide) covers the basics.

## Which file does each agent read?

Every tool has its own format, but AGENTS.md has become the common denominator. Here is the state of play as of November 21, 2026, based on each tool's official documentation.

| Tool | Main file | Scoped rules | Reads AGENTS.md? |
| --- | --- | --- | --- |
| Claude Code | `CLAUDE.md` (root or `.claude/`) | `.claude/rules/*.md` with `paths` | Yes, when no CLAUDE.md exists (or via import) |
| OpenAI Codex | `AGENTS.md` | `AGENTS.md` in subfolders | Yes, native format |
| Cursor | `.cursor/rules/*.mdc` | `globs` in the frontmatter | Yes |
| GitHub Copilot | `.github/copilot-instructions.md` | `.github/instructions/*.instructions.md` with `applyTo` | Yes |
| Gemini CLI | `GEMINI.md` | Files in subfolders | Configurable |

### AGENTS.md: the shared format

[AGENTS.md](https://agents.md/) describes itself as "a README for agents": a predictable place for build steps, tests and conventions. It's standard Markdown with no required fields. Contributed by OpenAI, it is one of the three founding projects of the Agentic AI Foundation, set up under the Linux Foundation in December 2025, alongside Anthropic's MCP and Block's goose. According to the Linux Foundation, more than 60,000 open-source projects and agent frameworks use it.

The precedence rule is simple: the agent reads the AGENTS.md closest to the file it's editing. In a project with an `api/` folder and a `web/` folder, each can have its own. And instructions you give in the chat override everything.

For [Codex](https://openai.com/codex/), the documentation spells out the details: Codex first reads a global file in `~/.codex`, then project files from the root down to the current folder. An `AGENTS.override.md` replaces AGENTS.md in a folder. Codex stops adding files once the total reaches 32 KiB by default (the `project_doc_max_bytes` setting).

### CLAUDE.md: Claude Code's format

[Claude Code](https://www.anthropic.com/claude-code) reads several levels of CLAUDE.md and concatenates them:

- `~/.claude/CLAUDE.md`: your personal preferences, for every project.
- `./CLAUDE.md` or `./.claude/CLAUDE.md`: project rules, shared through Git.
- `./CLAUDE.local.md`: your preferences for this project; add it to `.gitignore`.
- A "managed" CLAUDE.md deployed by your organization's IT team.

Three features are worth knowing. The `/init` command generates a first CLAUDE.md by analyzing your code. The `@path/to/file` syntax imports another file (up to four levels deep). The `.claude/rules/` folder holds rules by topic, and a rule with a `paths` field only loads when Claude works on matching files.

On AGENTS.md, the documentation says Claude Code reads it directly when the project has no CLAUDE.md. If there is one, put `@AGENTS.md` at the top of your CLAUDE.md to include it.

### Cursor rules

[Cursor](https://cursor.com/) stores project rules in `.cursor/rules/`, as `.mdc` files with required frontmatter (a plain `.md` file in that folder is ignored). Three fields control loading:

- `alwaysApply: true`: the rule applies to every chat.
- `description`: the agent decides whether the rule is relevant.
- `globs`: the rule attaches when matching files are involved.

With none of these fields, the rule only applies when you @-mention it. Cursor recommends keeping each rule under 500 lines. It also reads an AGENTS.md at the root or in subfolders, as a simpler alternative.

### GitHub Copilot instructions

[GitHub Copilot](https://github.com/features/copilot) reads `.github/copilot-instructions.md` for the whole repository, plus `.github/instructions/NAME.instructions.md` files whose `applyTo` frontmatter targets specific files (for example `"**/*.ts,**/*.tsx"`). For agent instructions, GitHub's docs accept one or more AGENTS.md files, or instead a single CLAUDE.md or GEMINI.md at the root.

### GEMINI.md

Gemini CLI reads a global `GEMINI.md` (`~/.gemini/GEMINI.md`) and then the project's files, and its `context.fileName` setting can point it to AGENTS.md instead. One caveat: the Gemini CLI documentation states that for unpaid tier and Google One users, Gemini CLI was replaced by Antigravity CLI on June 18, 2026. Check the docs for the tool you actually use.

## What belongs in a context file?

Everything the agent can't work out by reading the code, and nothing else. Claude Code's documentation recommends staying under 200 lines per CLAUDE.md: longer files use more context and are followed less reliably.

| Include | Avoid |
| --- | --- |
| Exact commands (install, run, test) | Generic advice ("write clean code") |
| Project structure, in 5 to 10 lines | A description of every file |
| Non-obvious conventions ("amounts in cents") | What the code already shows |
| Hard rules ("never edit existing migrations") | Contradictory rules |
| What to check before each commit | API keys, passwords, private URLs |

Claude Code's docs show the right level of detail: "Use 2-space indentation" instead of "Format code properly"; "Run `npm test` before committing" instead of "Test your changes."

> **Never put secrets in these files** — A context file is versioned and shared. GitGuardian's 2026 report counted about 28.65 million new secrets exposed in public GitHub commits in 2025. Keep keys in environment variables and only write their names in the file.

## A copy-ready AGENTS.md template

Here's a starting point for a typical web app. Replace every line with what's true for your project.

```markdown
# AGENTS.md

## Project
Booking app for a hair salon.
Front end: React + Vite. Back end: Supabase (Postgres, Auth). Hosting: Vercel.

## Commands
- Install: `npm install`
- Run locally: `npm run dev`
- Tests: `npm test` (run before every commit)

## Structure
- `src/pages/`: one page per route
- `src/lib/supabase.ts`: the only place that talks to the database
- `supabase/migrations/`: SQL migrations, one per change

## Rules
- Amounts are stored in cents (integer), never as decimals.
- Every new table has RLS enabled and one policy per role.
- No secret keys in `src/`: only public `VITE_` variables.
- Never edit an existing migration: create a new one.
- One feature per change. Explain the plan before editing more than 3 files.

## Before saying "done"
- `npm test` passes.
- You listed the files you changed and what I should check by hand.
```

If you also use Claude Code and want Claude-specific instructions, add a CLAUDE.md next to it:

```markdown
@AGENTS.md

## Claude Code specifics
- Use plan mode for any task that touches authentication.
```

The RLS and keys rules are there for a reason: they cover the two most common holes in vibe-coded apps, explained in [our Supabase RLS guide](https://vibe-code.blog/en/supabase-rls-security) and [why API keys must never live in your front end](https://vibe-code.blog/en/api-keys-security).

## A simple strategy for your situation

- **If** you use a single tool, **then** use its native format and keep it short.
- **If** you switch tools or work with others, **then** write one shared AGENTS.md, and have a CLAUDE.md import it if anyone uses Claude Code.
- **If** your file goes past 200 lines, **then** split it: scoped rules by folder or file type (`.claude/rules/` with `paths`, `globs` in Cursor, `applyTo` in Copilot).
- **If** the agent ignores a rule, **then** rewrite it so it can be checked, and look for a conflicting rule elsewhere.
- **If** an important decision gets made in chat, **then** ask the agent to add it to the file right away.

To compare the agents that read these files, see [Cursor vs Claude Code vs Codex](https://vibe-code.blog/en/cursor-vs-claude-code-vs-codex), and to get started, read [our beginner's guide to Claude Code](https://vibe-code.blog/en/claude-code-beginners-guide). A context file describes your project; plugging the agent into your tools (database, tickets, docs) is the job of MCP, explained for vibe coders.

## Frequently asked questions

### What's the difference between CLAUDE.md and AGENTS.md?

Both are Markdown instruction files for coding agents. CLAUDE.md is Claude Code's own format, with extras such as imports and path-scoped rules. AGENTS.md is an open format read by Codex, Cursor, Copilot and many other tools. Claude Code reads AGENTS.md when the project has no CLAUDE.md, or through an `@AGENTS.md` import.

### Where should I put AGENTS.md?

At the project root for general rules. You can add more in subfolders (for example `api/` and `web/`): the agent reads the file closest to the one it's editing, which takes precedence. Instructions given directly in the chat still override every file.

### How long should a context file be?

Short. Claude Code's docs recommend under 200 lines per CLAUDE.md, Cursor suggests under 500 lines per rule, and Codex stops loading AGENTS.md files beyond 32 KiB by default. The longer the file, the less each instruction gets followed. Move specific rules into scoped files.

### Does the .cursorrules file still work?

Cursor's current documentation describes project rules in the `.cursor/rules/` folder, as `.mdc` files with frontmatter, plus support for AGENTS.md. If your project still uses an old `.cursorrules` file, the safest move is to migrate its content to `.cursor/rules/` or to an AGENTS.md.

### Why does my agent ignore my instructions?

Three common causes: an instruction too vague to check, two contradictory instructions in different files, or a file that's too long. Rewrite each rule in concrete terms ("run `npm test`" rather than "test"), remove duplicates and trim. Also make sure the file sits in the right place with the exact name the tool expects.

## Sources

- [How Claude remembers your project — Claude Code Docs](https://code.claude.com/docs/en/memory)
- [AGENTS.md — agents.md](https://agents.md/)
- [Custom instructions with AGENTS.md — OpenAI Codex](https://learn.chatgpt.com/docs/agent-configuration/agents-md)
- [Rules — Cursor Docs](https://cursor.com/docs/context/rules)
- [Adding repository custom instructions for GitHub Copilot — GitHub Docs](https://docs.github.com/en/copilot/how-tos/configure-custom-instructions/add-repository-instructions)
- [Provide context with GEMINI.md files — Gemini CLI](https://geminicli.com/docs/cli/gemini-md/)
- [Linux Foundation Announces the Formation of the Agentic AI Foundation — Linux Foundation](https://www.linuxfoundation.org/press/linux-foundation-announces-the-formation-of-the-agentic-ai-foundation)
- [The State of Secrets Sprawl 2026 — GitGuardian](https://blog.gitguardian.com/the-state-of-secrets-sprawl-2026/)

— Thierry Gustin, Formateur en intelligence artificielle (GustinAI) · December 4, 2026
