How to Use AGENTS.md With Claude Code

Published:

Updated:

how to use agents md with claude

Disclaimer

As an affiliate, we may earn a commission from qualifying purchases. We get commissions for purchases made through links on this website from Amazon and other third parties.

Part of our AI Tools guides

Claude Code can use AGENTS.md as project guidance, but by default it falls back to that file only when no qualifying project CLAUDE.md is present. A project instruction file is a file that gives a coding agent repository-specific context and working rules. AGENTS.md can hold shared repository context, while a CLAUDE.md in scope can change what Claude Code loads.

That distinction matters when your team uses more than one coding tool. One file can explain how to build, test, and work safely in your repo. The other can add rules for Claude Code. This guide helps you choose a setup, write useful rules, and check what loaded. A deliberate file setup helps you give every coding agent clearer, more consistent direction.

Key Takeaways

  • AGENTS.md is a plain-Markdown file for shared repository guidance.
  • Claude Code uses AGENTS.md as a fallback in its default mode.
  • A qualifying CLAUDE.md can prevent that default fallback.
  • Choose a mode that matches how your team shares instructions.
  • Check the plugin debug log to see which AGENTS.md paths loaded.
  • Use a skill for task-specific steps and a hook to block an action.

What AGENTS.md Adds to a Coding Repo

AGENTS.md gives a coding agent the repository details it needs to work in a way that fits your project. It is practical guidance, not a replacement for a README.md written for people. The format is plain Markdown, with no required schema.

The convention gives an agent useful context before it changes code. You can explain the commands your team uses, choices that keep code consistent, and places the agent should leave alone. Keep human setup and product details in README.md, then put working rules in AGENTS.md.

The AGENTS.md format and purpose support simple repository guidance that can work across coding agents. Teams can use the same file with different tools, rather than writing the same project basics again. You can also add focused files in parts of a large repo.

A useful starter file covers four areas:

  • Build commands the agent should run before making or checking a change.
  • Test commands, including which tests fit a small or broad change.
  • Coding conventions, such as naming, formatting, and error handling.
  • Out-of-scope directories the agent should not edit or inspect.

These points answer what belongs in AGENTS.md documentation: plain text headings and clear Markdown lists are enough. The file does not need a special format, fixed fields, or a tool-specific template. Keep the file focused on instructions an agent can use while working in the repo.

How to Use Agents MD With Claude Code in Your Repo

By default, Claude Code reads AGENTS.md as project instructions only when no qualifying project CLAUDE.md is loaded along your path from the project root to your working directory. This is a fallback, not an automatic merge. In the default mode, a qualifying CLAUDE.md can be at the root or between the root and your working directory.

If Claude Code loads a qualifying CLAUDE.md, it does not also load AGENTS.md through the default fallback. This can surprise teams that keep a shared AGENTS.md at the root and a Claude-specific file inside a package. A root CLAUDE.md alone can prevent Claude Code from using that nested AGENTS.md in the default mode.

The built-in AGENTS.md plugin uses claude-md-or-agents-md as its default mode. In this mode, Claude Code uses AGENTS.md files along the path from the project root to your working directory when no qualifying Claude Code project instruction file is present. It does not combine both file types by default.

For example, a repo might contain a root AGENTS.md and a package-level AGENTS.md. If the project has no qualifying CLAUDE.md, Claude Code can use AGENTS.md as project guidance in the default mode. Add a qualifying CLAUDE.md on the path, and the fallback rule changes what Claude Code loads.

The key detail is the path Claude Code uses for the task. A file outside that path may not affect the instructions for your current working directory. Before changing files, check for CLAUDE.md, .claude/CLAUDE.md, and CLAUDE.local.md in the project path.

Choose an Instruction Files Mode

Choose claude-md-and-agents-md when you need both instruction file types loaded together. The best mode depends on your team’s setup: keep Claude-only behavior, allow a fallback, load both formats, or limit files to managed policy. The mode controls which instruction files Claude Code can use.

The plugin offers four instructionFiles modes. Use the table to match each mode to the way your repo shares project rules.

Mode What loads Use it when
claude-md Only CLAUDE.md Keep the Claude-only behavior
claude-md-or-agents-md CLAUDE.md or AGENTS.md as fallback Use the default without a qualifying CLAUDE.md
claude-md-and-agents-md Both file types Load shared and Claude-specific instructions together
managed-only Organization-managed CLAUDE.md and memory Limit loaded instructions to managed policy

With managed-only, Claude Code drops project, local, and user instruction files. It still keeps the organization’s managed CLAUDE.md and Claude Code memory. This mode suits teams that need one managed policy source.

You can set the plugin through /config under “Project instructions,” or through pluginConfigs in user settings, a –settings file, or managed settings. The user settings path is pluginConfigs → agents-md@builtin → options. The option is per user or settings input, not a shared project setting.

The plugin does not read its options from project .claude/settings.json. You can also run it locally with claude --plugin-dir mods/agents-md. Confirm the mode in /config before you rely on it across a team.

Write AGENTS.md Rules Claude Can Use

A developer checks a project test command on a laptop at a home-office desk. A tablet beside him displays concise AGENTS.md instructions in bullet points, with coding books, a desk lamp, and a potted plant nearby.
Clear AGENTS.md rules give Claude Code the project guidance it needs, including how to run tests and follow coding instructions.

A useful rule tells Claude what to do and how you will know the task is complete. Good instructions name a real action, not a broad wish such as “write clean code.” Pair a command with the check that command should pass.

For example, name your project’s real test command, then say when Claude should run it. You might ask Claude to run the test suite after changing a package, then report any failures. Do not copy a command from another project; use the command your repo actually supports.

A practical AGENTS.md template can stay simple. Start with a short project overview, then list setup commands, testing instructions, coding conventions, and scope limits. This gives an agent a useful path without turning the file into a second handbook.

GitHub examples can help you see how teams group those topics, but copy the structure, not rules that do not fit your repo. Include a command only when it works in your project. Name a directory only when its boundaries matter to the agent’s work.

Give the agent clear tasks and checks

Write rules as actions the agent can follow. “Run the project test command after changing API code” gives a clear task. “Confirm that the API tests pass before reporting the change complete” gives a clear check.

Small details can prevent avoidable errors. If a command needs to run from a package directory, say so. If a change touches generated files, name the source file or command that should create them. Claude then has a better chance of making the right change on its first pass.

Use a short heading for each group of rules. A useful starter structure might include “Project overview,” “Setup,” “Tests,” “Code style,” and “Scope.” The sections should tell the agent where to begin and what success looks like, not retell your whole development process.

Keep project context short and focused

More context does not guarantee better results. A February 2026 ETH Zurich study found that LLM-generated context files reduced task success rates by about 3% compared with no context file. Human-written context files improved task success by only about 4%.

The same study found that context files increased inference costs by over 20%. One useful rule is that each line should prevent a mistake the agent cannot recover from. Keep AGENTS.md under 100 lines as an ideal size, and keep CLAUDE.md under that size too.

The study’s ideal size for SKILL.md is under 500 lines. These are targets, not a reason to cut a rule that protects your repo. Remove repeated background, stale commands, and advice that does not change the agent’s next action.

A short file is easier for your team to review when a command or coding rule changes. Keep only instructions that change a real decision or prevent a repeatable mistake.

Organize Instructions for a Monorepo

A monorepo is easier to guide when shared rules sit at the root and package-specific rules stay close to the code they govern. Root guidance sets shared expectations; nested files add rules for one area. A nested AGENTS.md attaches on qualifying file reads, not simply because its folder exists.

In claude-md-or-agents-md and claude-md-and-agents-md modes, reading a file under the project root can attach AGENTS.md files between the root and that file’s directory. A CLAUDE.md in the same directory can claim the file instead. This behavior gives package work more focused context.

Keep shared rules at the project root

Put rules at the root when they apply across packages. These might cover the shared test approach, code review expectations, or a rule against changing generated files by hand. Root instructions give the coding agent a common base before it works in any one package.

A root file can also explain the repo’s main layout. Keep the detail high enough to help the agent find the right package, but do not list every folder. A short map can point to major areas such as apps, packages, and shared tools.

Add focused rules below the root

For example, a root AGENTS.md can describe repo-wide test rules. A nested apps/api/AGENTS.md can explain API-specific test steps, conventions, and limits. The package file adds detail without making every other package carry it.

In the supported modes, a qualifying nested file can attach when Claude Code reads a file beneath its directory. It does not attach just because Claude Code starts in a repo that contains the folder. A file read in apps/api can bring the relevant nested instructions into context.

Before relying on nested rules, make three checks:

  • Confirm the selected mode loads AGENTS.md.
  • Check whether a CLAUDE.md in the same directory claims the target file.
  • Test by asking Claude Code to read a file in the target directory.

Each qualifying nested AGENTS.md attaches once per agent loop and conversation. After compaction or /clear, the count starts again as Claude Code rebuilds context. Test nested guidance from the same directory where Claude Code will work.

Connect AGENTS.md and CLAUDE.md Without Drift

A computer screen displays a Claude Code file titled AGENTS.md, with a desk of stationery, a potted plant, and a steaming coffee mug in front. Tech professionals collaborate beside the screen in an office with large windows overlooking a tree-lined suburban street.
Keep AGENTS.md and CLAUDE.md aligned to prevent conflicting guidance, so Claude Code and your team can work from the same instructions.

If both files hold rules your team expects Claude Code to follow, make their relationship explicit. Two files do not always mean two sets of loaded rules: in the default mode, CLAUDE.md takes precedence. Use an import when Claude Code should read shared AGENTS.md rules too.

In claude-md-and-agents-md mode, the plugin loads AGENTS.md files alongside CLAUDE.md files throughout the directory tree. If a CLAUDE.md already includes or links to an AGENTS.md, the plugin does not load that file twice in this mode.

The table shows three common setups and their results.

Repository setup What Claude Code loads Practical choice
AGENTS.md only AGENTS.md under the default fallback Keep it simple without a qualifying CLAUDE.md
Both files, no import CLAUDE.md by default Review whether the files need to be combined
CLAUDE.md with @AGENTS.md Both files through the import Use one shared file plus Claude-specific additions

An @AGENTS.md line in CLAUDE.md is a direct way to include shared rules. This lets AGENTS.md serve several coding tools while CLAUDE.md adds setup that only Claude Code needs.

For example, keep shared test commands and code conventions in AGENTS.md. Then use CLAUDE.md for Claude Code details, such as a relevant import or tool-specific workflow. Avoid copying the same rule into both files, since one update could leave the other behind.

A team can still choose to maintain separate guidance when the tools behave differently. Give each file a clear role, then review changes to shared rules as part of normal repo work. Review shared rules in one place so separate tools do not quietly follow different instructions.

Know When Instructions Need a Skill or Hook

Put rules that apply to every task in project instructions, and move task-specific or must-block behavior to a better-fit tool. Persistent context is not the answer to every need. A skill can give Claude task steps, while a hook can block an action before it runs.

Use the tool that matches how often the rule applies and how firmly it must be enforced. AGENTS.md or CLAUDE.md suits standing project guidance. A skill suits a repeatable procedure for certain tasks. A hook suits an action that must not run under set conditions.

Use a skill for task-specific guidance

AGENTS.md and CLAUDE.md provide persistent project context. Skills provide task-level capability and load when relevant. This keeps the main project instructions from carrying every step for tasks that only happen now and then.

Anthropic’s skills repository defines a skill as a self-contained folder with a SKILL.md file. That file includes instructions and metadata. Its two required frontmatter fields are name and description, which help Claude identify what the skill does.

Use a unique, lowercase skill name with hyphens instead of spaces. A skill for reviewing API changes, for example, can hold the review steps, examples, and checks that matter for that task. Keep its instructions in the skill folder rather than adding them to every project task.

If you are comparing wider options for building and using agents, this guide to AI agent builders for non-technical teams covers no-code and developer-focused tools. Claude Code fits a developer workflow, while other builders can support sales, support, and research work.

Use a hook when an action must be blocked

An instruction file can ask Claude not to run a command, but that request is still guidance. A hook can block an action before it runs. Use a hook when the team needs a technical stop, rather than a reminder the agent may miss.

Place each kind of guidance where it fits:

  • AGENTS.md or CLAUDE.md for standing project guidance.
  • A skill for a task-specific procedure that Claude loads when relevant.
  • A hook for an action that must be blocked before it runs.

Skills can support a more careful coding workflow, but they do not remove the need to review changes. New developers can also learn how to use AI code assistants with care, including testing outputs for bugs and security issues. Treat written guidance as direction, not as a technical block on an action.

Check Which Instructions Claude Code Loaded

Check the plugin’s debug log for loaded AGENTS.md paths instead of relying on /memory. The debug log shows the paths the plugin loaded, while /memory does not list AGENTS.md files. Use the log to confirm the actual paths for your current project.

A file in a nested directory may attach when Claude Code reads a file there. The plugin does not report that path in the conversation transcript. If you only check what Claude says, you may miss the file that entered the working context.

Nested AGENTS.md files attach once per agent loop and conversation. When context is recomputed after compaction or /clear, the count starts over, so a qualifying file may attach again.

Check the paths after starting work in the target project and reading a file in the relevant directory. This can reveal a missing file or a path that differs from your expectation. Repeat the check after changing the mode or moving to a different project root.

Compare AGENTS.md, CLAUDE.md, and SKILL.md

Choose the file by how widely and how often the instruction should apply. Shared project rules belong in a different place from occasional task steps. AGENTS.md and CLAUDE.md hold persistent project context, while SKILL.md holds task-specific guidance.

The main differences are the intended users, file shape, and when Claude Code needs the content.

File Main role How it is organized When to use it
AGENTS.md Shared project guidance Plain Markdown Rules meant to work across coding agents
CLAUDE.md Claude Code project instructions and imports Markdown with @path imports Claude-specific guidance or shared AGENTS.md rules
SKILL.md Task-specific capability Self-contained folder with YAML frontmatter and Markdown Instructions Claude should load when relevant

AGENTS.md is a plain-Markdown choice for rules that should travel across coding tools. CLAUDE.md can add Claude Code project details or import shared rules with an @path. A skill is a folder for one reusable task procedure.

Anthropic’s skill template uses YAML frontmatter followed by Markdown instructions, examples, and guidelines. The required frontmatter fields are name and description. Skill names should be unique, lowercase identifiers, with hyphens instead of spaces.

You can create a SKILL.md file from that structure rather than looking for a separate file download. Start with the two frontmatter fields, then add the steps, examples, and checks Claude needs for the task. Keep persistent project rules separate from procedures that only matter for certain tasks.

Avoid Common AGENTS.md Setup Mistakes

The most common setup errors come from assuming Claude Code will merge or enforce files automatically. Small settings details can change the result. Check what the selected mode loads before trusting a rule.

Watch for four common mistakes and use the matching fix:

  • Leaving a qualifying CLAUDE.md in place while expecting the default AGENTS.md fallback. Remove or change the file, or choose a mode that loads both.
  • Assuming project .claude/settings.json controls the plugin option. Set the option in user settings, a –settings file, or managed settings.
  • Expecting managed-only to load project instructions. Use a mode that allows project files, since managed-only drops them.
  • Treating a written rule as an enforced block. Use a hook when an action must stop before it runs.

The default mode is claude-md-or-agents-md, so a qualifying CLAUDE.md can change the fallback result. Settings may also differ between teammates because each user can supply different settings. Check the actual mode and loaded paths before asking the agent to act on important work.

Conclusion

A shared AGENTS.md can give coding agents a consistent set of repository rules when Claude Code’s loading mode is set up to match. Use it for rules shared across tools, then make any CLAUDE.md relationship intentional. That choice helps your team avoid split or missing guidance.

Before using the setup for real work, confirm the chosen mode and the paths Claude Code loaded. If a task needs a reusable procedure, keep that guidance in a skill instead of adding it to every project task.

Add or review the file in your repository, then confirm Claude Code loaded the instructions you expect.

FAQ

Does AGENTS.md replace CLAUDE.md in Claude Code?

No. In the default mode, AGENTS.md is a fallback, and a qualifying project CLAUDE.md takes precedence. Claude Code does not automatically merge both files in that mode. You can change the mode to load both, or add an @AGENTS.md import to CLAUDE.md. That makes the relationship clear and lets you keep shared rules in one file.

Does a personal CLAUDE.local.md affect the default fallback?

Yes. A CLAUDE.local.md between the project root and your working directory can prevent the default mode from loading AGENTS.md. That can make two folders in the same repo behave differently. Check the path Claude Code uses for your task, then review the plugin debug log to see which AGENTS.md files loaded.

Can I use AGENTS.md rules for every folder in a monorepo?

Yes, root-level rules can give broad guidance across the repo, while nested AGENTS.md files add rules for specific areas. A nested file attaches on qualifying reads beneath its directory, subject to the selected mode and same-directory CLAUDE.md behavior. A folder’s presence alone does not attach its AGENTS.md file.

Can AGENTS.md import another instruction file?

Yes. An @ import inside AGENTS.md can include another instruction file when the required approval for an external import has already been given. This can help you reuse shared content without copying it into several files. Keep the import path clear, and check the loaded paths when you need to confirm the result.

Does an AGENTS.md instruction guarantee Claude Code will obey a rule?

No. An instruction guides Claude Code, but it does not technically block an action. Use a hook when an action must be stopped before it runs. For less strict rules, clear project guidance may be enough, but you should still review the agent’s work and run the checks your repo requires.

Why can two teammates load different project instructions from the same repo?

The instructionFiles option can come from each user’s settings, a –settings file, or managed settings. It is not read from project .claude/settings.json. Teammates with different settings can therefore load different instruction files from one repo. Compare the active mode and the plugin debug log when a teammate sees different guidance.

About the author

Latest Posts