---
title: "AGENTS.md and CLAUDE.md: what coding agents read first · CloudSat"
description: "How Codex, Claude Code, OpenCode, Cline and Aider load AGENTS.md, CLAUDE.md and rules files, what research found about them, and how to write one that helps."
url: https://cloudsat.io/learn/agents-md-and-context-files-for-coding-agents
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

# AGENTS.md and CLAUDE.md: what coding agents read first

How Codex, Claude Code, OpenCode, Cline and Aider load AGENTS.md, CLAUDE.md and rules files, what research found about them, and how to write one that helps.

CloudSat team November 18, 2026 6 min read

Before a coding agent reads your prompt, it reads files you may have forgotten exist: instruction files in your home directory, at the root of the repository and in subfolders. Their content lands in every session and shapes every decision the agent makes. When an agent keeps running the wrong test command or ignores a rule you swear you gave it, the cause is usually one of these files. Here is what each tool loads, what the evidence says, and how to write a file that earns its place.

## What each agent loads

| Agent | Files it reads | Order and scope | Limits |
| --- | --- | --- | --- |
| Codex CLI | `AGENTS.override.md` or `AGENTS.md` in `~/.codex`, then the same names in each directory from the project root down to where you started | One file per directory, joined root first; files closer to your working directory come later and override earlier guidance | Stops adding files at `project_doc_max_bytes`, 32 KiB by default |
| Claude Code | Managed policy file, `~/.claude/CLAUDE.md`, `./CLAUDE.md` or `./.claude/CLAUDE.md`, personal `CLAUDE.local.md`, and `.claude/rules/` | Files above the working directory load at launch; files in subdirectories load when the agent touches files there | Docs advise under 200 lines per file |
| OpenCode | `AGENTS.md` from the workspace upward, plus `~/.config/opencode/AGENTS.md` | Global first, then project files; all are combined, conflicts are not resolved | Falls back to `CLAUDE.md` where no `AGENTS.md` exists |
| Cline | `.clinerules` files | Picked up by the CLI, the VS Code extension and the JetBrains plugin |  |
| Aider | Nothing automatic | Load a conventions file with `--read` or a `read:` entry in `.aider.conf.yml` | Loaded read-only |

Two details catch people. Claude Code reads `AGENTS.md` only when no `CLAUDE.md` or `CLAUDE.local.md` exists in the working directory or above it (from version 2.1.277), so adding a personal `CLAUDE.local.md` silently stops it from reading your team's `AGENTS.md`. And Codex stops adding files once their combined size reaches its cap, so instructions past 32 KiB never reach the model.

## One file for every agent

The Agentic AI Foundation, part of the Linux Foundation, now looks after `AGENTS.md` as an open format, and the format's website names more than twenty tools that read it, among them Zed, opencode, Cursor, Codex and GitHub Copilot's coding agent. Make it the single source of truth and point the other tools at it.

For Claude Code, a `CLAUDE.md` can import it with the `@path` syntax and add tool-specific lines:

```markdown
@AGENTS.md

## Claude Code only

- Open pull requests with the `gh` CLI.

```

For Aider, add one line to `.aider.conf.yml`:

```yaml
read: AGENTS.md
```

## What the research says

In February 2026, researchers at ETH Zurich and LogicStar.ai published "Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents?" Their abstract reports that providing context files did not generally improve task success rates while increasing inference cost by over 20% on average, for both LLM-generated and developer-written files. Agents did follow the instructions. The parts that failed to help were repository overviews, the very section that many templates put first. The authors found context files useful for specifying non-standard practices.

The lesson is not "delete the file". It is "keep only what the agent cannot discover by itself".

## What belongs in the file

- **Exact commands** for install, build, a single test, lint and format, with the flags you really use.
- **Non-standard tooling**: `uv` instead of `pip`, `pnpm` instead of `npm`, a `Makefile` target instead of a raw command.
- **Rules the code does not reveal**: generated folders that must not be edited, append-only migrations, a public API that must stay backward compatible.
- **How to check the work** before declaring it done.

A complete example fits on one screen:

```markdown
## Commands

- Install: `uv sync`
- Test one file: `uv run pytest tests/test_api.py -q`
- Lint and format: `uv run ruff check --fix . && uv run ruff format .`

## Rules

- Use `uv`, never `pip install`.
- Do not edit `src/generated/`; run `make codegen` instead.
- Migrations are append-only: add a new file, never change an old one.

## Before you finish

- Run the tests for every module you touched.

```

## What to leave out

- **Directory tours and project overviews.** The agent can list files and read the README.
- **Generic advice** such as "write clean, well-tested code". It adds tokens and changes nothing.
- **Style rules a formatter enforces.** Point to the formatter's config instead.
- **Secrets and internal URLs.** Everything in the file is sent to the model provider with every request.
- **Instructions for a single task.** Put those in the prompt.

## Big repositories: scope instead of growing

When one file starts to sprawl, split it by location rather than adding sections. In a monorepo, give each package its own short `AGENTS.md`: tools that follow the format read the nearest file, so the frontend package can say `pnpm test` while the API package says `go test ./...`. The agents.md site notes that OpenAI's main repository carries 88 of them. Claude Code goes one step further with `.claude/rules/`: a rule file can declare the paths it covers, and it loads only when Claude works with matching files.

Then measure. Run the same small task twice, once with the file and once without it, and compare the result, the tokens spent and the number of wrong commands. If a section changes nothing, delete it.

## When context backfires

- **Stale commands.** A renamed test script means the agent fails, guesses and burns tokens before it finds the right one. Update the file in the same commit as the change.
- **Contradictions between levels.** Claude Code's docs warn that when two instructions conflict, Claude may pick one arbitrarily, and OpenCode combines its files without resolving conflicts. Search your global and project files together when behavior surprises you.
- **Treating context as enforcement.** These files are context, not configuration. To block an action no matter what the model decides, use the agent's permission rules or hooks. Claude Code's docs recommend a `PreToolUse` hook for this.
- **Untrusted repositories.** A cloned repository's instruction files are instructions you did not write. Claude Code's docs add that a non-interactive `claude -p` run executes hooks from the project's `.claude/settings.json` and connects servers from its `.mcp.json` without a trust prompt, unless you pass `--bare`. Read those files before pointing an agent at someone else's code.

## Shared servers and team defaults

On a development server, the agent runs as your Unix user, so your global files apply to every repository you open there. Keep them in a dotfiles repository so every machine gets the same version. For a team box, Claude Code also reads a managed policy file at `/etc/claude-code/CLAUDE.md` on Linux, which applies to every user of the machine and suits shared rules such as "never push to main". A small [Cloud VPS](https://cloudsat.io/cloud-vps) used as a shared agent box can carry that one file for the whole team.

## FAQ

### Should I let the agent write its own AGENTS.md?

Commands like `/init` produce a reasonable draft, but the study above found that generated files did not help on average. Keep the commands and the non-obvious rules, and delete the overview.

### Does Claude Code read AGENTS.md now?

Yes, from version 2.1.277, when no `CLAUDE.md` or `CLAUDE.local.md` exists in the working directory or above it. Otherwise import it from your `CLAUDE.md` with `@AGENTS.md`.

### How long should a context file be?

As short as it can be while still listing the commands and rules. Claude Code's docs suggest under 200 lines per file, and Codex stops reading at 32 KiB combined unless you raise `project_doc_max_bytes`.

### Where do personal preferences go?

In your user-level file (`~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md` or `~/.config/opencode/AGENTS.md`), or in a gitignored `CLAUDE.local.md` for one project. Keep the shared file free of personal habits.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

- [Choosing an AI coding agent: terminal, IDE or self-hosted](https://cloudsat.io/learn/choose-an-ai-coding-agent): AI and machine learning Choosing an AI coding agent: terminal, IDE or self-hosted 6 min read
- [Browser IDE with an AI coding agent: code-server on a VPS](https://cloudsat.io/learn/browser-ide-with-ai-coding-agent-on-a-vps): DevOps Browser IDE with an AI coding agent: code-server on a VPS 6 min read
- [Run AI agents unattended on a VPS: services, timers, limits](https://cloudsat.io/learn/run-ai-agents-unattended-on-a-vps): AI and machine learning Run AI agents unattended on a VPS: services, timers, limits 6 min read
- [Design to code with AI: MCP, screenshots or prompts](https://cloudsat.io/learn/design-to-code-with-ai-agents): DevOps Design to code with AI: MCP, screenshots or prompts 7 min read
