blog / guides

CLAUDE.md, AGENTS.md, GEMINI.md: write project instructions your AI agents actually follow

Which instructions file Claude Code, Codex and Gemini CLI read, what to put in it, what to leave out, and how to keep one AGENTS.md as the single source of truth.

Terminal window showing a short AGENTS.md with commands and a Never section, next to the headline Rules your agents actually follow

Every AI coding agent starts a session knowing nothing about your project. It doesn't know that tests run with pnpm test, that legacy/ is off limits, or that you never commit straight to main. A project instructions file fixes that: a short Markdown file in the repo that the agent reads before it starts working. Write it well and the agent stops guessing.

Which file does each agent read?

The idea is the same everywhere, but the file name depends on the agent:

  • Claude Code reads CLAUDE.md. A file in the project root covers the whole project, ~/.claude/CLAUDE.md holds your personal defaults, and CLAUDE.md files in subfolders get pulled in when the agent works there.
  • Codex reads AGENTS.md. AGENTS.md is meant as a shared, tool-neutral convention, and a growing number of other coding agents read it too.
  • Gemini CLI reads GEMINI.md by default, and it can be configured to read other file names.

Don't keep three copies that slowly drift apart. A common setup is one real AGENTS.md plus a tiny CLAUDE.md that points to it. Claude Code supports @path imports, so the whole file can be:

@AGENTS.md

For Gemini CLI, point its settings at AGENTS.md. One source of truth, every agent reads it.

Diagram: Claude Code reads CLAUDE.md, Codex reads AGENTS.md and Gemini CLI reads GEMINI.md, all pointing to one AGENTS.md with commands, folder map, conventions, gotchas and hard rules, plus nested files for big repos

What to put in

Write onboarding notes for a sharp new colleague who takes everything literally. Give them what they can't work out quickly on their own:

  1. How to run, test and lint. The exact commands, including the one for a single test file. An agent that can check its own work makes far fewer mistakes.
  2. A folder map. One line per important directory.
  3. Conventions. Only the ones that aren't visible from reading a couple of files: how errors are handled, where shared types live, naming rules, commit message format.
  4. Gotchas. The traps that already cost someone an afternoon. "The dev server caches env vars, so restart it after editing .env."
  5. What never to do. Hard rules, written as rules: don't edit generated files, don't add dependencies without asking, never run migrations against production.

Write instructions as short, direct imperatives. "Run pnpm test before you report a change as done" works better than a paragraph about the value of testing.

What to leave out

The file is loaded into the agent's context every session, so every line costs attention. Cut:

  • Long prose. Background and history belong in your regular docs.
  • Things the code already says. The agent can read package.json, your types and your folder names.
  • Secrets. No API keys, tokens or passwords: the file is committed and read by tools. Tell the agent where configuration comes from (for example "copy .env.example to .env"), never the values.
  • Wishes. "We plan to migrate to a new router" just confuses the agent about what is true today.

A compact example

A complete file for a made-up recipe app, short on purpose:

# Recipe Box

Next.js app for saving and sharing recipes. Postgres via Prisma.

## Commands
- Install: `pnpm install`
- Dev server: `pnpm dev` (http://localhost:3000)
- Tests: `pnpm test` (one file: `pnpm test src/recipes/scale.test.ts`)
- Lint + types: `pnpm lint && pnpm typecheck`; run both before saying you're done

## Folders
- `src/app/` routes and pages
- `src/recipes/` recipe domain logic (pure, unit-tested)
- `src/db/` Prisma client and queries; the only place that touches the DB

## Conventions
- Server code validates input with zod at the route; trust it inside
- Shared types live in `src/types/`; never copy a type between files

## Gotchas
- After editing `prisma/schema.prisma`, run `pnpm prisma generate`
- Tests use a separate DB from `.env.test`; never point them at `.env`

## Never
- Never edit files in `src/generated/`
- Never run `prisma migrate reset`
- Don't add a dependency without asking first

An agent can act on every line of it.

Keep it short and current

A short true file beats a long half-stale one:

  • Treat a wrong instruction as a bug. If you rename a script or move a folder, update the file in the same commit.
  • Add a line when the agent makes the same mistake twice.
  • Delete lines that no longer earn their place.
  • Use nested files for big repos. Put a short instructions file in a subfolder (api/AGENTS.md, mobile/CLAUDE.md) for rules that only apply there. The root file stays general, and the agent picks up the local rules when it works in that folder.

Review it like code

The file shapes every change an agent makes. Commit it, change it in pull requests, and read the diff. Watch for rules that contradict each other, commands that no longer exist, and vague lines like "write clean code" that nobody can follow. Now and then, ask a fresh session to summarise the rules back to you; whatever it gets wrong is a line to rewrite.

Running several agents on one repo with Bettr

Once one AGENTS.md serves every agent, you can run them side by side. Bettr is a desktop terminal for exactly that: Claude Code, Codex, Gemini CLI or any other CLI agent each get their own pane in one window, split right or down, all in view.

When you want to check what the agents are being told, pick All docs from Docs in the project's top nav, or press ⌘⇧D (Ctrl+Shift+D on Windows and Linux). The Docs reader shows every Markdown file in the project as a folder tree with a filter and an outline, so your AGENTS.md, CLAUDE.md and nested instruction files are a click away. Edit (⌘E on macOS) opens a live-preview editor and ⌘S saves. If an agent changed the file in the meantime, Bettr asks before overwriting it.

Frequently asked questions

Do I need both CLAUDE.md and AGENTS.md? Only if you use Claude Code alongside other agents. Keep the real content in AGENTS.md and make CLAUDE.md a one-line @AGENTS.md import, so both read the same rules and nothing drifts.

How long should a project instructions file be? As short as it can be while still covering commands, a folder map, conventions, gotchas and hard rules. Usually a few dozen lines; past a couple of screens, move detail into nested files.

Can the agent write the file for me? It can write a first draft. Claude Code's /init command, for example, scans the repo and generates a starting CLAUDE.md. Treat that draft like any generated code: cut what the code already says, then add the gotchas and rules only you know.

// keep reading

Git worktrees for AI coding agents: a practical guide

Two agents in one checkout will collide. How git worktrees give each agent its own branch and folder: commands, naming, env files, merging, cleanup, pitfalls.

How to review what an AI coding agent changed before you commit

A practical checklist for reviewing AI agent changes: diff per turn, spot deleted tests, new dependencies and secrets, check blast radius, run the tests, commit small.

Keep your API keys away from your AI coding agent

How API keys leak through AI coding agents via prompts, .env and MCP configs, the habits that stop it, and what to do when a key gets out.

$ bettr

Give your agents a better terminal.

Free to download. Checks for updates itself. Runs on your machine — no telemetry.

macOS

Universal — Apple silicon & Intel

.dmg · 230 MB

Windows

64-bit installer

.exe · 120 MB

Linux

x86-64 · AppImage or Debian / Ubuntu

AppImage · 158 MB · .deb · 103 MB

v1.42.1 · free · checks for updates itself