跳到正文
DEV Community· Beyen·· 45 分鐘前AI 評分66

如何讓 AGENTS.md、CLAUDE.md 與 Cursor Rules 保持同步

Keeping AGENTS.md, CLAUDE.md, and Cursor Rules in Sync

AI 導讀

這份指南建議以根目錄 AGENTS.md 作為共用指令來源,並由 CLAUDE.md 匯入,以同步多種編碼 Agent 的專案規則。Codex 的 32 KiB 限制按整條目錄鏈累計,而 Claude Code 會在啟動時展開 @path 匯入,並不延後載入。

正文

If you run Claude Code in the terminal while someone else opens the same repository in Cursor or Codex, instruction files drift apart fast.

Copy-pasting a 400-line style guide into every tool's config file doesn't just double your maintenance. Depending on the client, it can silently truncate nested package rules or add thousands of static tokens to every turn.

Here is how each instruction format actually loads, three traps worth avoiding, and a minimal layout that keeps one source of truth.

TL;DR

  • Root AGENTS.md -> put shared build, test, and repo conventions here (read natively by Codex, Cursor, Windsurf, Cline, and Copilot)
  • CLAUDE.md -> keep it tiny with a single @AGENTS.md import plus Claude-only notes
  • .cursor/rules/*.mdc -> reserve for path-scoped globs rules that shouldn't load globally
  • SKILL.md -> use for occasional multi-step workflows so only the short metadata loads at startup

🗂️ How each file loads

File Read by Loading behavior & budget
AGENTS.md Codex, Cursor, Windsurf, Cline Loaded along directory chain (root -> cwd); 32 KiB cumulative cap in Codex
CLAUDE.md Claude Code Loaded in full at session start (@path imports expand immediately)
.cursor/rules/*.mdc Cursor (v0.45+) Loaded conditionally when active files match YAML globs
SKILL.md Claude Code, Codex, Goose Progressive disclosure: only name + description (~50 tokens) load until triggered

⚠️ Trap 1: Codex's 32 KiB limit is cumulative

OpenAI Codex walks from ~/.codex/AGENTS.md to your repo root AGENTS.md and down to your current working directory.

By default, project_doc_max_bytes is 32,768 bytes (32 KiB) across that entire chain, not per file. If your root AGENTS.md is a 28 KiB architecture essay, a package-specific packages/api/AGENTS.md deeper in the tree gets truncated or dropped without a loud warning.

Keeping root AGENTS.md under ~150 lines of concrete build, lint, and test commands leaves plenty of room for subdirectory overrides.

🔑 Trap 2: @path imports in CLAUDE.md don't save context

A common assumption in Claude Code is that splitting a large CLAUDE.md into imports like this keeps the context window lean:

@docs/architecture.md
@docs/coding-standards.md

It helps human readability, but it does not defer loading. Claude Code expands @path imports into the session context at launch.

If a rule only applies to database migrations or API routes, put it in path-scoped rules (.claude/rules/*.md or .cursor/rules/*.mdc) or an on-demand SKILL.md instead of importing it into root CLAUDE.md.

🧩 Trap 3: SKILL.md fails silently on folder-name mismatch

Agent Skills validate YAML frontmatter strictly:

  • name: 1–64 characters, lowercase alphanumeric and single hyphens only (^[a-z0-9]+(-[a-z0-9]+)*$), and it must match the parent folder name (db-check/SKILL.md -> name: db-check)
  • description: 1–1,024 characters stating both what the skill does and when to use it

If name has uppercase letters, underscores, or doesn't match the folder name, the agent skips it silently.

⚙️ One repo layout that stays in sync

Instead of hand-editing the same rules in three places:

  1. Put shared build, test, and architecture constraints in root AGENTS.md.
  2. Point CLAUDE.md at AGENTS.md and only add Claude-specific slash commands or hooks:
# Project Instructions

@AGENTS.md

## Claude Code Notes
- Run `/clear` between unrelated tasks to avoid re-caching long threads.
  1. Put personal local ports or sandbox paths in CLAUDE.local.md (gitignored).
  2. Keep .cursor/rules/*.mdc strictly for directory-specific globs (like src/components/**/*.tsx).

Wrapping up

Most instruction drift comes from treating AGENTS.md and CLAUDE.md as separate documents. Pick AGENTS.md as the base, import it from CLAUDE.md, and push situational workflows out to skills or glob-scoped rules.

If you want to check byte budgets or generate the boilerplate files side by side, there's a small browser-based linter and converter and a set of MIT starter templates on GitHub.

Related: Why Your MCP Config Works in Cursor but Not in VS Code

How are you organizing repo instructions when teammates use different coding agents?

來源:DEV Community · dev.to