What should go in an AGENTS.md or coding rules file?
An AGENTS.md file should hold what a coding agent cannot work out from your code: the exact build, test and lint commands, style rules that differ from the defaults, project conventions, security rules and known traps. Keep it short, specific and checked into git, and move anything that must never be broken into a hook or lint rule.
Cite
CodeLifter Forum, "What should go in an AGENTS.md or coding rules file?", https://codelifter.com/forum/posts/what-should-go-in-an-agentsmd-or-coding-rules-file/, accessed 2026-11-12.- CodeLifter editorsStaffStaff, CodeLifter ·
What is an AGENTS.md file?
AGENTS.md is a plain Markdown file in your repository that coding agents read before they work. The AGENTS.md site (read on 16 October 2026) calls it "a README for agents" and answers the format question in one line: "Are there required fields? No. AGENTS.md is just standard Markdown." The site says the format is now stewarded by the Agentic AI Foundation under the Linux Foundation.
A rules file is the general name for the same idea. Several tools have their own file name as well as, or instead of, AGENTS.md:
Tool File it reads Notes from the vendor docs Codex AGENTS.md, orAGENTS.override.mdfirstConcatenates files from the repo root down; stops at 32 KiB by default ( project_doc_max_bytes)Claude Code CLAUDE.md;AGENTS.mdwhen there is noCLAUDE.mdDocs suggest under 200 lines per CLAUDE.mdGitHub Copilot .github/copilot-instructions.md,AGENTS.md, or a rootCLAUDE.mdorGEMINI.mdPath rules in .github/instructions/NAME.instructions.mdwithapplyToCursor .cursor/rules/*.mdc, andAGENTS.mdDocs suggest keeping each rule under 500 lines Sources: Codex AGENTS.md guide, Claude Code memory docs, GitHub's repository instructions page and Cursor's rules page, all read on 16 October 2026. The coding agents directory covers more tools.
What should you put in it?
The AGENTS.md site lists the popular sections: project overview, build and test commands, code style guidelines, testing instructions and security considerations. Anthropic's Claude Code best practices adds a sharper filter for each line: "Would removing this cause Claude to make mistakes?" If not, cut it. Its include list, which applies to any agent:
- Commands the agent cannot guess, such as
pnpm test --filter webrather than "run the tests". - Code style rules that differ from the language defaults.
- Testing instructions and the preferred test runner.
- Repository etiquette: branch names, commit message format, pull request rules.
- Architectural decisions specific to the project.
- Environment quirks, such as required environment variables (by name, never by value).
- Gotchas that are not obvious from the code.
Be concrete. The Claude Code memory docs give the contrast: write "API handlers live in
src/api/handlers/" instead of "Keep files organized".What should you leave out?
Anthropic's exclude list: anything the agent can figure out by reading the code, standard conventions it already knows, detailed API documentation (link to it instead), information that changes often, long explanations, file-by-file descriptions of the codebase, and self-evident advice such as "write clean code". Cursor's rules page agrees: do not copy entire style guides ("Use a linter instead") and do not document every possible command.
Never put a secret in the file. It is committed to git and read into the model's context every session. The thread on keeping API keys out of a vibe-coded app covers where keys belong.
How long should it be?
Shorter than you think. The Claude Code memory docs say to "target under 200 lines per CLAUDE.md file" because "Longer files consume more context and reduce adherence." Context here means the model's working memory for the session: everything it has read so far, which has a fixed limit. Codex stops reading instruction files once the combined size reaches 32 KiB by default. Cursor suggests under 500 lines per rule.
If one part of the codebase needs its own rules, use nesting. The AGENTS.md site says "The closest AGENTS.md to the edited file wins; explicit user chat prompts override everything." Codex documents the same order: files closer to your working directory come later in the combined prompt and override earlier guidance.
How do you write one?
Create
AGENTS.mdin the repository root. Claude Code can draft aCLAUDE.mdfor you with/init; Copilot's docs include a prompt that asks its cloud agent to draft.github/copilot-instructions.md.Write the commands first: install, build, test, lint, each as an exact command in backticks.
Add only the rules the agent got wrong in past sessions. Cursor's advice: "Add rules only when you notice Agent making the same mistake repeatedly."
Add your security lines, for example:
## Security - Read secrets from environment variables; never write a key, token or password in code. - Write text with textContent, never innerHTML. - Do not add a dependency without naming it and saying why.Commit it, then check it loaded. In Claude Code,
/contextshows what is in context. In Copilot Chat, the instructions file appears in the response's references list.Prune it when the agent ignores a rule. Anthropic: "If Claude keeps doing something you don't want despite having a rule against it, the file is probably too long and the rule is getting lost."
The innerHTML line comes from the innerHTML thread, which also shows a lint rule that backs it up.
Does the agent have to obey it?
No. The Claude Code memory docs say Claude treats these files "as context, not enforced configuration", and point to a PreToolUse hook (a script that runs before each tool call and can block it) for anything that must never happen. Cursor says AI guidance "should not be your only security control." Use the rules file to steer, and use tests, lint rules, hooks and code review to enforce. The review thread covers the last of those.
Short version
- Put in exact commands, non-default style rules, conventions, security rules and known traps.
- Leave out what the agent can read from the code, long docs and anything secret.
- Keep it short: Claude Code suggests under 200 lines, Codex reads 32 KiB by default.
- Nested files in subfolders override the root file for that folder.
- A rules file steers; tests, lint rules and hooks enforce.
- Commands the agent cannot guess, such as
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.
2 answers
- CodeLifter editorsStaffStaff, CodeLifter ·
Do you need both CLAUDE.md and AGENTS.md? Usually one is enough, and which one depends on the tools your team uses. According to the Claude Code memory docs (read 16 October 2026), Claude Code reads
AGENTS.mdonly when there is noCLAUDE.md,.claude/CLAUDE.mdorCLAUDE.local.mdin the working directory or above it. If both exist, it reads theCLAUDE.mdfiles only, so rules you put inAGENTS.mdare silently skipped. The docs give two fixes: keep onlyAGENTS.md, or add a line@AGENTS.mdtoCLAUDE.md, which imports the file at launch. Imports can nest up to four levels deep, and paths are resolved relative to the importing file. The docs note that readingAGENTS.mddirectly needs Claude Code v2.1.277 or later. On the other side, GitHub's instructions page says Copilot can useAGENTS.mdfiles anywhere in the repository, or a singleCLAUDE.mdorGEMINI.mdin the root. For a mixed team, oneAGENTS.mdwith a one-lineCLAUDE.mdimport is the simplest setup that both read. - CodeLifter editorsStaffStaff, CodeLifter ·
What is the difference between Cursor rules and AGENTS.md? Cursor supports both, and they behave differently. Cursor's rules page (read 16 October 2026) says project rules live in
.cursor/rulesas.mdcfiles, and each has frontmatter with three fields:description,globsandalwaysApply. WithalwaysApply: truethe rule is in every chat. Withglobsset, it attaches when a matching file is in context, for examplesrc/**/*.tsx. With only adescription, the agent decides when it is relevant. With none of them, it applies only when you @-mention it. A plain.mdfile inside.cursor/rulesis ignored, because it has no frontmatter. AGENTS.md has none of that machinery: it is plain Markdown in the project root or any subfolder, and nested files combine with their parents, the more specific one winning. Two details are easy to miss. Rules do not affect Cursor Tab, the inline completion feature. And Team Rules, set by admins on team plans, take precedence over project rules, which take precedence over user rules. If you also use other agents, put shared rules in AGENTS.md and keep.mdcfiles for Cursor-only, file-scoped rules.