Join our Newsletter — 33% off our NHI Course
Home› Guides› AI Coding Agent Config Files: What AGENTS.md, CLAUDE.md…
Guide AI Platforms

AI Coding Agent Config Files: What AGENTS.md, CLAUDE.md and Cursor Rules Do and What to Put in Them

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 14 min read
On this page

AI coding agent config files are plain Markdown files, such as AGENTS.md, CLAUDE.md, Cursor rules and copilot-instructions.md, that a coding agent reads at the start of a session as standing instructions about a repository. They tell the agent how to build and test the code, which conventions to follow and what to avoid, so the team does not repeat the same guidance in every prompt. Most teams now have several of these files, often copied between tools, with no agreement on what belongs in them. This guide explains what each file does, where each tool looks for it and how files combine, then sets out what to put in them, what to keep out, and how to manage them as reviewed, owned repository assets. It is for developers, platform teams and AppSec engineers; the attack side, where these files are abused, is covered in Coding Agent Configuration File Attacks.

Tools are listed alphabetically throughout; the order is not a ranking. Details are from each vendor's documentation as checked in November 2026.

Key takeaways

  • They are context, not controls. An instruction file is text the model reads; it can be ignored or overridden. Anything that must always hold belongs in permissions, sandboxing, hooks or CI, not in a sentence.
  • AGENTS.md is the shared format. It is plain Markdown with no required fields, stewarded by the Agentic AI Foundation under the Linux Foundation, and read by many agents, so it is the natural single source for cross-tool guidance.
  • Every tool merges files differently. Some concatenate from the repository root down, some take the nearest file, some scope rules by glob. Know the order before you rely on a nested override.
  • Short, concrete and verifiable works best. Build and test commands, layout, conventions and named do-not rules; vendor guidance points to roughly 200 to 500 lines at most per file.
  • Treat them like CI config. They change agent behaviour for everyone who clones the repository, so give them owners, review and change monitoring, and never put secrets in them.

What these files are and why they exist

A coding agent starts each session knowing nothing about your repository beyond what it can read. Config files give it durable project knowledge: the command that runs the tests, the package manager in use, the directory where API handlers live, the rule that migrations are never edited after release. Without them, developers repeat this in prompts and the agent guesses. With them, the agent's first attempt is closer to what a reviewer would accept.

The files are not configuration in the strict sense. They do not grant or remove capability. Anthropic's Claude Code documentation states this plainly: CLAUDE.md content is delivered as a message after the system prompt, compliance is not guaranteed, and actions that must be blocked regardless of the model's decision should use a PreToolUse hook or managed settings such as permissions.deny. The same principle applies to every tool here. OWASP makes the related point for LLM applications: a system prompt should not be treated as secret or used as a security control (LLM07:2025 System Prompt Leakage).

Many tools also have separate, structured settings files (permissions, MCP servers, hooks) beside the instruction files. This guide is about the instruction files. The settings files carry more direct risk and are covered in the per-tool security guides linked below.

The files at a glance

Tool or formatProject instruction filesPersonal or globalScoping
AGENTS.md (open format)AGENTS.md at the repository root, nested files in subprojectsDefined by each toolNearest file in the directory tree
Claude Code./CLAUDE.md or ./.claude/CLAUDE.md; .claude/rules/*.md; CLAUDE.local.md (personal, gitignored)~/.claude/CLAUDE.md, ~/.claude/rules/paths frontmatter on rules; subdirectory CLAUDE.md loads on demand
Cursor.cursor/rules/*.mdc; AGENTS.mdUser Rules (Customize, Rules)alwaysApply, description, globs frontmatter
GitHub Copilot.github/copilot-instructions.md; .github/instructions/*.instructions.md; AGENTS.md, or a root CLAUDE.md or GEMINI.mdPersonal instructionsapplyTo globs; optional excludeAgent
OpenAI CodexAGENTS.override.md, AGENTS.md, plus names in project_doc_fallback_filenames~/.codex/AGENTS.md or AGENTS.override.md (or CODEX_HOME)One file per directory, root to working directory

How each tool finds and combines files

AGENTS.md (open format)

The AGENTS.md site describes the file as a README for agents: build steps, tests and conventions that would clutter a human README. It has no required fields. Put one at the root and, in a monorepo, nested files in subprojects; agents read the nearest file to the code being edited, and an explicit user prompt overrides it. The site lists support across a long list of agents and editors, including the four tools in this guide. To migrate an existing tool-specific file, the site suggests renaming it to AGENTS.md and symlinking the old name.

Claude Code

Claude Code loads CLAUDE.md and CLAUDE.local.md from the working directory and every directory above it at launch, concatenated from the filesystem root down, so instructions nearer the launch directory are read last; CLAUDE.local.md is appended after CLAUDE.md in each directory. Subdirectory files load when Claude works in that subdirectory. Files in .claude/rules/ without paths frontmatter load at launch; with paths globs they load only for matching files. @path imports pull other files in, up to four hops deep, and imports from outside the working directory in project files trigger a one-time approval. By default Claude Code reads AGENTS.md only when no CLAUDE.md is present; to share one file, the documentation suggests starting CLAUDE.md with @AGENTS.md. Guidance: under 200 lines per file, concrete and verifiable instructions. /memory lists loaded files and /init drafts a starting file. See the Claude Code Security Guide.

Cursor

Cursor has four rule sources: Project Rules as .mdc files in .cursor/rules (a plain .md file there is ignored because it has no frontmatter), User Rules, Team Rules and AGENTS.md. Frontmatter decides when a rule applies: alwaysApply: true for every chat, a description for Apply Intelligently (the agent decides relevance), globs for Apply to Specific Files, or none of these for Apply Manually via an @-mention. Nested AGENTS.md files combine with parents, with more specific instructions taking precedence. Where rules conflict, Team Rules win over Project Rules, which win over User Rules, and admins can enforce Team Rules so users cannot disable them. Rules do not affect Cursor Tab. Guidance: keep each rule under 500 lines and split larger ones. An @file mention in a rule is read on demand, not inlined. See the Cursor Security Guide.

GitHub Copilot

Copilot uses a repository-wide .github/copilot-instructions.md and path-specific NAME.instructions.md files under .github/instructions/, each with applyTo globs such as "**/*.ts,**/*.tsx"; when both match, both are used. The optional excludeAgent field ("code-review" or "cloud-agent") keeps a file away from one of those features. For agent instructions, AGENTS.md files can sit anywhere, with the nearest taking precedence, or a single root CLAUDE.md or GEMINI.md can be used. Personal instructions take priority over repository instructions, which take priority over organisation instructions, and all relevant sets are sent. Copilot code review reads instructions from the pull request's head branch, a detail worth knowing when a pull request edits them, and the setting "Use custom instructions when reviewing pull requests" controls this per repository. See the GitHub Copilot Security Guide.

OpenAI Codex

Codex first reads a global file from ~/.codex (or CODEX_HOME): AGENTS.override.md if present, otherwise AGENTS.md. It then walks from the project root, usually the Git root, down to the working directory, taking at most one file per directory in the order AGENTS.override.md, AGENTS.md, then any names in project_doc_fallback_filenames set in ~/.codex/config.toml. Files are concatenated root first, so closer files come later and override earlier guidance, and empty files are skipped. Combined content stops at project_doc_max_bytes, 32 KiB by default, so a bloated root file can crowd out a nested one. The chain is built once per run. To check what loaded, the documentation suggests asking Codex to summarise its current instructions from the repository root and from a subdirectory.

What belongs in an instruction file

Write for a capable new colleague who has never seen the repository and will follow instructions literally. The AGENTS.md site's suggested sections are a sound skeleton.

SectionGood contentWeak content
Project overviewOne paragraph: what the service does, main languages, where the entry points areMarketing description or history
Build and test commandsExact commands: pnpm install, pnpm test --filter api, how to run one test"Make sure the tests pass"
Code style and conventionsVerifiable rules: "2-space indentation", "use the shared logger, never console.log""Write clean code"
LayoutWhere handlers, migrations, generated code and fixtures live; which folders are generated and must not be editedA full directory dump
Testing instructionsWhich tests to add for which change, how to update snapshots, which suites need servicesCoverage targets with no method
Security considerationsNamed rules: validate input with the shared schema library, use parameterised queries, never log tokens, load secrets only from the secrets manager client, never weaken lint or security checks to make a build pass"Be secure"
Commit and pull request guidelinesMessage format, branch naming, what a PR description must includeTeam etiquette
  • Scope rules to where they apply: use path-scoped files (Claude Code paths, Cursor globs, Copilot applyTo, nested AGENTS.md) so frontend rules do not load for database work.
  • Prefer pointers to procedures: long runbooks belong in docs or tool-specific skill features, referenced from the instruction file, so the always-loaded text stays short.
  • Keep instructions consistent: every tool here notes that conflicting instructions are combined or followed unpredictably. One source of truth, imported or symlinked, avoids drift.

What must stay out

  • Secrets and credentials: API keys, tokens, connection strings or passwords. The files are committed, shared, copied into model context and often into logs and transcripts. Point to how the agent obtains credentials at run time instead. See the Git Secret Scanning Guide.
  • Security controls written as prose: "never push to main" or "do not delete files" is a hope. Enforce with branch protection, tool permissions, sandboxing and hooks, and keep the sentence only as a hint.
  • Internal detail an outsider should not learn: hostnames, internal URLs for admin systems, customer names, incident details. Assume anything in a public repository's instruction file is public.
  • Instructions to fetch and follow remote content: "read the latest rules from this URL" hands control of the agent to whoever controls that URL.
  • Personal preferences in shared files: put them in personal files (CLAUDE.local.md, user rules, personal instructions, global AGENTS.md) so they do not change behaviour for the whole team.
  • Hidden or unreadable content: HTML comments, invisible Unicode or encoded blocks. Some tools strip HTML comments before injection, others do not, and hidden text is a known attack technique.

Managing config files across a team

  1. Inventory: find every instruction file in each repository: AGENTS.md, AGENTS.override.md, CLAUDE.md, CLAUDE.local.md, .claude/rules/, .cursor/rules/, .github/copilot-instructions.md, .github/instructions/, plus any configured fallback names.
  2. Pick a primary: make AGENTS.md the shared source and import or symlink it from tool-specific files, keeping only genuinely tool-specific content in those files.
  3. Assign owners: add the instruction paths to CODEOWNERS so changes need review from the platform or AppSec owner, the same as CI workflow files.
  4. Check in CI: lint for secrets, invisible or bidirectional Unicode, URLs outside an allow-list and size over your limit (for example the 32 KiB Codex default or 500 lines).
  5. Use organisation layers for baseline rules: where a tool provides an organisation or managed instruction layer, put shared security guidance there so every repository starts from the same baseline.
  6. Verify what loads: use each tool's own view (/memory in Claude Code, the references list in Copilot Chat, a summary prompt in Codex) after changes.
  7. Roll back like code: revert the commit; personal files and global files are outside the repository, so include them in developer onboarding and offboarding notes.

Small teams can stop at one AGENTS.md per repository with CODEOWNERS. Larger organisations benefit from organisation-level baseline rules and a central lint in CI, because hundreds of repositories otherwise drift into conflicting guidance. For governance of the pull requests agents raise, see the AI Coding Agent Pull Request Governance Guide.

Where identity fits

An agent following these files usually acts with a developer's credentials or a CI token. That is why credentials must never sit in the files and why the identity the agent runs as should be scoped to the task: short-lived tokens, least privilege on repositories and cloud roles, and separate identities for headless or cloud agents. See the AI Coding Agents Security Guide for the identity model.

Detection and measurement

  • Coverage: share of active repositories with a reviewed primary instruction file and CODEOWNERS entry.
  • Change review rate: percentage of instruction file changes merged with an owner's approval (target 100 per cent).
  • Lint findings: secrets, hidden Unicode and unapproved URLs found in instruction files per month, trending to zero.
  • Drift: repositories where tool-specific files contradict or duplicate the primary AGENTS.md.
  • Size: files over your line or byte limit, since long files reduce adherence and can truncate later files.

Common failure patterns

  • Treating a rule as a control, for example "never run destructive commands", with no permission or sandbox setting behind it.
  • Copy-pasted files per tool that drift apart until the agents receive contradictory guidance.
  • Tokens pasted in to "help the agent" and then committed, cloned and exposed.
  • Assuming a nested file overrides the root when the tool concatenates, or hitting a size cap so the nested file never loads.
  • Unreviewed changes in pull requests: instruction edits merged as documentation, without the review given to CI files, even though they change agent behaviour for everyone.
  • A Cursor rule saved as .md in .cursor/rules, which Cursor ignores because it has no frontmatter, so the team believes a rule is active when it is not.

Framework mapping

PracticeNIST SP 800-53 Rev 5NIST CSF 2.0OWASP and MITRE ATLAS
Reviewed, owned instruction files with change controlCM-3 Configuration Change Control, CM-2 Baseline ConfigurationPR.PS-01LLM01:2025 Prompt Injection (poisoned instructions)
Security rules in instruction files, enforcement elsewhereSA-8 Security and Privacy Engineering PrinciplesPR.PS-06LLM07:2025 System Prompt Leakage (not a control)
No credentials in instruction filesIA-5 Authenticator ManagementPR.AA-05LLM02:2025 Sensitive Information Disclosure
Hidden-instruction linting in CISI-4 System MonitoringDE.CM-09AML.T0051 LLM Prompt Injection

Practitioner checklist

  • Inventory instruction files across repositories and record which tools read each.
  • Make AGENTS.md the shared source and import or symlink it from tool-specific files.
  • Write concrete, verifiable instructions: exact commands, layout, named security rules.
  • Keep each file short (about 200 to 500 lines) and use path-scoped rules for areas.
  • Never include secrets, internal hostnames or remote "follow this URL" instructions.
  • Enforce must-hold rules with permissions, sandboxing, hooks, branch protection and CI.
  • Add instruction paths to CODEOWNERS and lint them in CI for secrets, hidden Unicode and URLs.
  • Set organisation-level baseline instructions where the tool supports them.
  • Verify loaded instructions with each tool's own view after every change.

Standards and references

Related NHI Mgmt Group resources: Coding Agent Configuration File Attacks · AI Coding Agents Security Guide · AI IDE and Coding Agent Security Guide · AI Coding Agent Pull Request Governance Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.