Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Tutorial

CLAUDE.md and AGENTS.md: instruction files for coding agents

CLAUDE.md vs AGENTS.md: what to put in each, where Claude Code, Codex, Cursor and Copilot look for them, and how to keep one source of truth without drift.

By Beginner20 min hands-on
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
Quiz at the end
On this page

Every coding agent starts each session knowing nothing about your project beyond what it can read. An instruction file is a Markdown file in the repository that the agent loads automatically at the start of a session, so you do not have to repeat “we use pnpm, run the tests with pnpm test:unit, never edit generated files” every time.

There are two names you will meet. AGENTS.md is an open format, started at OpenAI and now stewarded by the Agentic AI Foundation under the Linux Foundation, and is read by Codex, Cursor, GitHub Copilot, Google’s Antigravity and many others. CLAUDE.md is Claude Code’s own file. This tutorial covers what to write, where each agent looks, and how to maintain one source of truth.

What belongs in the file

The test for every line is: would a capable new team member need to be told this, or could they find it by reading the code? Instructions files are loaded into context on every session, so each line has a cost.

Good content:

  • Commands. How to install, build, run tests (all and one), lint and type-check. Exact commands, not descriptions.
  • Non-obvious conventions. “API handlers return Result objects, never throw.” “Dates are stored in UTC and formatted in the view layer.”
  • Boundaries. Generated directories not to edit, files that need human review, external services not to call in tests.
  • How to check work. “Before finishing, run pnpm check and fix any errors.”
  • Where things live, but only when it is not obvious from the folder names.

Content to leave out:

  • Generic advice (“write clean, maintainable code”). The model already tries to.
  • Anything the agent can read from package.json, the README or the code itself.
  • Long procedures that apply to one kind of task. Those belong in a skill or a path-scoped rule (see below).
  • Secrets, URLs with tokens, or anything you would not put in a public README.

A worked example

Here is a realistic AGENTS.md for a TypeScript web app. It is short on purpose:

# AGENTS.md

## Commands
- Install: `pnpm install`
- Dev server: `pnpm dev` (http://localhost:5173)
- All tests: `pnpm test` · One file: `pnpm vitest run path/to/file.test.ts`
- Type-check and lint: `pnpm check` (run before saying a task is done)

## Conventions
- TypeScript strict mode; no `any` without a comment explaining why.
- Server code lives in `src/server`, never import it from `src/client`.
- Database access only through the repositories in `src/server/db/repos`.
- Use the `logger` from `src/server/log.ts`, not `console.log`.

## Boundaries
- Do not edit `src/server/db/migrations/*` after they are merged; add a new migration.
- `src/generated/` is produced by `pnpm codegen`. Edit the schema, not the output.
- Tests must not call real payment or email APIs; use the fakes in `test/fakes`.

About thirty lines, all specific. An agent reading this knows how to verify its own work and which mistakes are expensive.

Where each agent looks

The details differ by tool. This is the behaviour documented by each vendor as of November 2026:

Agent Reads Notes
Claude Code CLAUDE.md (also .claude/CLAUDE.md), CLAUDE.local.md, ~/.claude/CLAUDE.md, .claude/rules/*.md Reads AGENTS.md instead when there is no CLAUDE.md or CLAUDE.local.md in the working directory or above it (v2.1.277 and later). Supports @path imports.
Codex AGENTS.md from ~/.codex and from the repository root down to the working directory Files are concatenated root first, so deeper files effectively override. Combined size is capped (32 KiB by default, project_doc_max_bytes).
Cursor AGENTS.md in the project root and subdirectories; .cursor/rules/*.mdc Rules can always apply, apply by file glob, or be picked by the agent based on their description.
GitHub Copilot, Antigravity and others AGENTS.md (many also have their own file) Check each tool’s documentation; most now read AGENTS.md.

In all of them, nested files in subdirectories add guidance for that part of the repository. In a monorepo, put shared commands at the root and package-specific notes in packages/api/AGENTS.md and so on.

Keeping one source of truth

If your team uses more than one agent, you do not want two files that slowly disagree. Three patterns work:

1. AGENTS.md only. Recent versions of Claude Code read AGENTS.md when there is no CLAUDE.md, so a repository with just AGENTS.md works in all the major agents. Be aware that if anyone adds a CLAUDE.md or a personal CLAUDE.local.md, Claude Code switches to those and stops reading AGENTS.md by default.

2. CLAUDE.md that imports AGENTS.md. This is the most robust pattern when you also want Claude-specific instructions:

@AGENTS.md

## Claude Code
- Use plan mode for changes under `src/billing/`.

Claude Code expands @AGENTS.md in place, then reads the extra lines. Other agents ignore CLAUDE.md and read AGENTS.md directly. Claude Code never loads the same AGENTS.md twice, so this is safe even where it would also read AGENTS.md on its own.

3. A symlink. ln -s AGENTS.md CLAUDE.md gives one file under two names. Simple, but symlinks are awkward on some Windows setups, and you cannot add anything Claude-specific.

Scoped rules for larger projects

When guidance only matters for part of a codebase, loading it on every session wastes context. Both Claude Code and Cursor support rules scoped by file path.

In Claude Code, put Markdown files in .claude/rules/. A rule with a paths field in its frontmatter loads only when Claude works with matching files:

---
paths:
  - "src/api/**/*.ts"
---

# API rules
- Validate every request body with the schemas in `src/api/schemas`.
- Errors use the problem+json format from `src/api/errors.ts`.

In Cursor, project rules live in .cursor/rules/ as .mdc files with description, globs and alwaysApply in their frontmatter.

For multi-step procedures (“how to add a new API endpoint”), consider an Agent Skill instead: skills load only when the task calls for them, and the same SKILL.md folder works across many agents.

Generate a first draft, then cut

All the major agents can draft the file for you: /init in Claude Code creates a CLAUDE.md, and /init in Codex creates an AGENTS.md. Use the draft as a starting point and then cut hard. Generated files tend to restate the README and include generic advice. A useful exercise is to delete every line and add back only those that would change what the agent does.

Then test it. Give the agent a typical small task in a fresh session and watch whether it uses the right commands without being told. If it runs npm test when you use pnpm, the file is not doing its job.

Pitfalls

Too long. Claude Code’s documentation recommends keeping each CLAUDE.md under about 200 lines. Long files reduce adherence, and imports do not help because imported files are loaded too.

Contradictions. Two rules that disagree (in the root file and a nested one, or in CLAUDE.md and a rule file) leave the agent to choose. Review the set together.

Stale commands. When a script is renamed, update the file in the same pull request. A wrong command is worse than no command.

Instructions as security. “Never read .env” in an instruction file is a request, not a control. Use the agent’s permission settings (deny rules, sandboxing) for anything that must not happen.

Personal preferences in the shared file. Your preferred tone or editor settings belong in ~/.claude/CLAUDE.md, CLAUDE.local.md (git-ignored) or your agent’s user settings, not in the team file.

Next steps

Covers

Check your understanding

CLAUDE.md and AGENTS.md quiz

Where coding agents look for instruction files, what to put in them and how to keep one source of truth.

6 questions · pass mark 70%

Question 1 of 60 answered
  1. What is AGENTS.md?
  • Write a useful AGENTS.md: example, template and test

    An AGENTS.md example and template with build and test commands, conventions and traps, plus a before-and-after task that shows whether the file actually helps.

    WorkflowBeginner30 min6 steps

  • Context engineering techniques: what the model should see

    What to put in a model's context at each step, what to leave out, and how instruction files, retrieval and tools fit.

    TutorialIntermediate30 min

  • AGENTS.md vs Agent Skills: which one you need, and where MCP fits

    AGENTS.md vs Agent Skills: what an instruction file and a skill each do for a coding agent, when to use which, and how MCP servers fit alongside both of them.

    Article

  • AGENTS.md

    An open, tool-neutral Markdown file of instructions for coding agents working in a repository, read by many different agents and editors.

    Glossary

  • CLAUDE.md

    Claude Code's instruction file, read at the start of a session from the project and user directories, so standing rules apply every time.

    Glossary

Back to top