ホーム 暮らし I stopped managing CLAUDE.md and AGENTS.md separately. A single line provided by the official docs fixed it, but it didn't reduce the context.

I stopped managing CLAUDE.md and AGENTS.md separately. A single line provided by the official docs fixed it, but it didn't reduce the context.

真鍋 千夏 真鍋 千夏 • 更新: • 公開: • 読了約 20 分
目次

When using both Claude Code and Codex, you end up writing the same content in both CLAUDE.md and AGENTS.md. At first, I would copy and paste from one to the other whenever I made a change. Naturally, they got out of sync. I only realize there's a rule written in just one of them after the AI ignores that rule and acts accordingly.

In the end, I stopped copying and pasting and switched to a referencing approach. It was solved with a single line mentioned in the official documentation. However, the part where I thought 'this will also lighten the context' was completely off the mark, so I will write about that as well.

What you will learn in this article

na17e84c09a12
  • The fact that Claude Code does not read AGENTS.md and the two solutions provided by the official team

  • Criteria for choosing between @ imports and symlinks

  • The official statement that importing does not reduce context

  • How to handle areas where synchronization doesn't work (when the Codex side lacks corresponding features)

Claude Code does not read AGENTS.md

First, let's start with the premise. Claude Code reads CLAUDE.md, but it does not read AGENTS.md. This is by design. Therefore, in a repository that only contains AGENTS.md, Claude Code is in a state where it hasn't been told anything.

For this situation, the official documentation provides a way for both tools to read the same instructions without duplicating the content. There are two methods.

Method 1: Import from CLAUDE.md

Create a CLAUDE.md and write this on the first line.

@AGENTS.md
Claude Code

Use plan mode for changes under src/billing/.

Lines starting with @ are interpreted as imports, and the contents of AGENTS.md are expanded there. Claude reads the imported file at the start of the session and then appends the rest of the content afterward. In other words, it becomes a structure where common rules are written in AGENTS.md, and only Claude-specific rules can be added to the CLAUDE.md side.

It is also good to keep the detailed specifications of the syntax in mind to avoid accidents.

  • Both relative and absolute paths can be used. Relative paths are resolved relative to the file where the import is written. They are not based on the working directory

  • You can import from within imported files. Up to 4 levels deep

  • Import parsing skips code spans and code blocks. If you just want to write a path as text, enclose it in backticks. ` @README will not be expanded, while @README` written without backticks will be read as a file

  • You can also import from the home directory. If you use multiple git worktrees and have an issue where a gitignored CLAUDE.local.md does not exist for each worktree, you can solve it by referencing a file on your local machine like @~/.claude/my-project-instructions.md

There is one thing to note. If an import from a project memory file points outside the working directory, Claude Code will display an approval dialog the first time. If you decline, the import remains disabled, and the dialog will not be shown again. This is a mechanism to protect you from files committed by others in shared projects, so you should approve it intentionally.

Method 2: Create a symlink

If you don't need to add Claude-specific rules, you can just create a link.

ln -s AGENTS.md CLAUDE.md

Nothing will be output even if it succeeds. In the next session, run /context and check if CLAUDE.md appears in the list of Memory files.

On Windows, creating a symlink requires administrator privileges or developer mode, so using the @AGENTS.md import is safer in that environment.

The criteria for judgment is simple: whether there are rules you want to write only for Claude. If so, use import; if not, use a symlink. We chose import because we wanted to specify where to use plan mode on the Claude Code side.

It didn't reduce context

This is the part I completely misread.

If you want to split CLAUDE.md to keep it short, importing is meaningless. It is clearly stated in the official documentation. Splitting into imports is useful for organization, but does not reduce context. Imported files are loaded into the context at startup along with the referencing CLAUDE.md.

Therefore, "moving it out with @ because it got long" only makes the file look shorter; the token consumption remains the same. It is the correct answer for the purpose of stopping dual management, but it is not a means of lightweighting.

So, what do you do when you really want to make it lighter? The official guide suggests path scope rules. Place a file in .claude/rules/ and write paths in the frontmatter.

---
paths:
  - "src/api//*.ts"
---
API Development Rules

- All API endpoints must include input validation
- Use the standard error response format

Rules written this way only enter the context when Claude reads a file matching the pattern. They are not triggered by every tool use, but at the point a matching file is read. Rules without paths are loaded unconditionally and treated with the same priority as .claude/CLAUDE.md.

Size guidelines are also written. Aim for less than 200 lines per file. Long files consume context and lower instruction adherence.

Accepting areas that cannot be synchronized

Returning to the topic of synchronization, there are points where you get stuck if you try to align everything. There is an asymmetry, such as the Codex side not having anything equivalent to Claude Code's rules feature.

In the Zenn article I used as a reference, they didn't try to align this, but instead treated it as writing only the file list and when to read them in AGENTS.md. It's a compromise of sharing only the location of information rather than reproducing the same behavior.

With the same mindset, MCP settings also have different formats. The Claude side uses JSON in .mcp.json, and the Codex side uses TOML in .codex/config.toml. A strategy was introduced where these are converted to a neutral form with formatting variations removed before comparison, and if there are differences, they are converted to the other side's format. The difference detection method records a fingerprint from the last synchronization rather than using file update times, and when both sides have changed, it doesn't decide automatically but lets a human choose. I think this is a design worth referencing if you are building your own synchronization script.

And it is realistic to design it so that you can choose item by item, such as "MCP is shared, but AGENTS.md and skills are not synchronized." You don't need to combine everything into one.

Summary

  • Claude Code only reads CLAUDE.md. It does not read AGENTS.md

  • There are two ways to stop dual management. If you want to add Claude-specific rules, use @AGENTS.md import; if you don't need to add them, use ln -s AGENTS.md CLAUDE.md

  • Imports are based on relative paths from the file location, up to 4 levels deep, and are not expanded inside code blocks

  • Splitting into imports does not reduce the context. If you want to make it lighter, use the path scope in .claude/rules/. A guideline is less than 200 lines per file.

  • For areas where the Codex side lacks corresponding features, don't try to align them; just write their locations in AGENTS.md and accept the limitation.

After changing the settings, use /context to check Memory files and verify that the intended files are being loaded. Continuing to write rules in files that aren't being read is the biggest waste of time.

Once you have organized the files to be loaded, the next most effective step is to have Claude itself inspect their contents. I have a record of passing the official guide to have the settings rewritten, so if you want to proceed to creating rules, this is the next step.


同じカテゴリの記事

真鍋 千夏
デジタルマーケター 真鍋 千夏
プロフィールを見る →

美容と暮らしの話題を担当。メーカーの公式発表、商品成分の公表資料、専門家の監修記事をもとに事実を整理します。

おすすめの関連記事