Vibe coding basics

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

--by --date --read 7 min

Lire en français

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: leaving the AI without memory. A context file is the simplest fix, and it pairs well with a proper PRD or a spec-driven development workflow. If you're just starting out, our complete guide to vibe coding 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.

ToolMain fileScoped rulesReads AGENTS.md?
Claude CodeCLAUDE.md (root or .claude/).claude/rules/*.md with pathsYes, when no CLAUDE.md exists (or via import)
OpenAI CodexAGENTS.mdAGENTS.md in subfoldersYes, native format
Cursor.cursor/rules/*.mdcglobs in the frontmatterYes
GitHub Copilot.github/copilot-instructions.md.github/instructions/*.instructions.md with applyToYes
Gemini CLIGEMINI.mdFiles in subfoldersConfigurable

AGENTS.md: the shared format

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, 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 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 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 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.

IncludeAvoid
Exact commands (install, run, test)Generic advice ("write clean code")
Project structure, in 5 to 10 linesA 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 commitAPI 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."

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.

# 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:

@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 and why API keys must never live in your front end.

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, and to get started, read our beginner's guide to Claude Code. 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