agents-md
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseagents-md
agents-md
Repository-scoped hygiene for : create it, measure it, audit its
content, and check it against its harness mirrors. One canonical file,
harness-neutral, no frontmatter.
AGENTS.mdauthoring and Copilot code-review setup live in.github/copilot-instructions.md(if installed). This skill only checks that file's mirror status against/github-copilot-repo-instructions; it does not write Copilot-specific content orAGENTS.mdpath rules.applyToPersonal or machine-global instruction files (a user's own, personal Copilot instructions) are out of scope. This skill only touches files committed to the repository.~/.claude/CLAUDE.md
面向仓库的 治理:创建、测量、审计其内容,并检查其与 harness 镜像文件是否一致。保持单一规范文件、harness 中立且不使用 frontmatter。
AGENTS.md的编写和 Copilot 代码审查设置由.github/copilot-instructions.md(如果已安装)负责。本 skill 仅检查该文件 相对于/github-copilot-repo-instructions的镜像同步状态;不会写入 Copilot 专用内容或AGENTS.md路径规则。applyTo个人或机器全局的指令文件(用户自己的、个人 Copilot 指令)不在范围内。本 skill 仅处理已提交到仓库中的文件。~/.claude/CLAUDE.md
Why AGENTS.md hygiene matters
为什么 AGENTS.md 治理很重要
AGENTS.md is a vendor-neutral, plain-Markdown convention with no required
fields (agents.md). Harnesses load applicable files at
different times. Loaded text uses context, so keep instructions concise and
commands current. Do not equate loaded context with billed tokens or assume
every file loads on every turn.
Effectiveness evidence is mixed. Keep repository rules that help agents act,
not rules based on a promised task-success gain. See
for loading behavior and
for study limits.
references/harness-matrix.mdreferences/content-checklist.mdAGENTS.md 是一种厂商中立的纯 Markdown 约定,没有必填字段(agents.md)。各 harness 会在不同时机加载适用文件。加载的文本会占用上下文,因此应让指令保持简洁、命令保持最新。不要将加载的上下文等同于计费 token,也不要假设每个文件都会在每一轮加载。
现有效果证据并不一致。保留能帮助 Agent 行动的仓库规则,不要保留仅以任务成功率提升承诺为依据的规则。有关加载行为,请参阅
;有关研究限制,请参阅
。
references/harness-matrix.mdreferences/content-checklist.mdProtocol
流程
1. Inventory instruction files
1. 盘点指令文件
List what exists, repository-relative, root and nested:
bash
find . -maxdepth 4 \( -name AGENTS.md -o -name CLAUDE.md -o -name CLAUDE.local.md \
-o -name GEMINI.md -o -path '*/.github/copilot-instructions.md' -o -path '*/.cursor/rules*' \) \
-not -path '*/node_modules/*'Each harness reads a different subset with different precedence and caps.
Read before assuming one file's presence
or absence is equivalent to another's — nearest-file precedence is the
norm (agents.md spec, Codex, Copilot, Cursor), but Claude Code's own trigger
is different: it reads only when no /
exists above the working file, or via an explicit import inside
a .
references/harness-matrix.mdAGENTS.mdCLAUDE.mdCLAUDE.local.md@AGENTS.mdCLAUDE.md列出仓库相对路径下的现有文件,包括根目录和嵌套目录:
bash
find . -maxdepth 4 \\( -name AGENTS.md -o -name CLAUDE.md -o -name CLAUDE.local.md \\
-o -name GEMINI.md -o -path '*/.github/copilot-instructions.md' -o -path '*/.cursor/rules*' \\) \\
-not -path '*/node_modules/*'每个 harness 读取不同的文件子集,并采用不同的优先级和大小上限。
在假定某个文件是否存在能够代表另一个文件之前,请先阅读
——最近文件优先是通行做法
(agents.md 规范、Codex、Copilot、Cursor),但 Claude Code 自身的触发机制不同:
只有当前工作文件的上级目录中没有 / 时,它才读取
;也可以通过 中显式的 导入来读取。
references/harness-matrix.mdCLAUDE.mdCLAUDE.local.mdAGENTS.mdCLAUDE.md@AGENTS.md2. Measure
2. 测量
bash
python3 "$AGENTS_MD_CHECK" [path/to/AGENTS.md]Resolve from the loaded directory
(), resolving symlinks first. Do not assume the
skill sits at in the target repository.
AGENTS_MD_CHECKSKILL.mdscripts/agents_md_check.pyskills/agents-md/Reports bytes, lines, the heading map, every referenced
checked against a nearby , every referenced repo-relative path,
and the mirror status of , , and
. Flag a file over ~200 lines as a soft readability warning. The
script also sums the chain from the repository root to each
directory at or below the checked file. A chain over 32 KiB fails outright.
OpenAI Codex concatenates that chain from the root down. It stops adding
files when the combined size reaches (32 KiB by
default), so the files nearest the working directory drop first
(https://developers.openai.com/codex/guides/agents-md/).
just <recipe>justfileCLAUDE.md.github/copilot-instructions.mdGEMINI.mdAGENTS.mdproject_doc_max_bytesRoot discovery and skip rules follow Codex:
- The root is the nearest directory at or above the checked file that
contains . With no
.git, each chain is the checked file only, and the report says "file directory" instead of "repository root"..git - Per directory, counts when present, else
AGENTS.override.md.AGENTS.md - Sizes are raw on-disk bytes, so CRLF line endings count in full.
- The walk skips dot directories, , broken symlinks, and any subdirectory with its own
node_modules(a nested project root)..git
Exit codes: 0 when no chain breaches the cap, no mirror has diverged, and
every referenced recipe and path exists. 1 on a cap breach, on any drift
(diverged mirror, missing recipe, or missing path), or when the file does
not exist.
--jsonpathbyteschain_byteschain_dirroot_marker.gitlinesbyte_capcap_breachnear_capline_warnheadingsjustfilereferenced_just_recipesmissing_recipesreferenced_pathsmissing_pathsmirrorsdiverged_mirrorsdriftbash
python3 "$AGENTS_MD_CHECK" [path/to/AGENTS.md]从已加载的 所在目录解析
(),并先解析符号链接。不要假设该 skill 位于目标仓库的
中。
SKILL.mdAGENTS_MD_CHECKscripts/agents_md_check.pyskills/agents-md/报告会列出字节数、行数、标题映射、每个被引用的 (与附近的
核对)、每个被引用的仓库相对路径,以及 、
和 的镜像状态。将超过约 200 行的文件
标记为软性可读性警告。脚本还会汇总从仓库根目录到被检查文件所在目录及其下每个
目录的 链。链大小超过 32 KiB 将直接判定失败。
just <recipe>justfileCLAUDE.md.github/copilot-instructions.mdGEMINI.mdAGENTS.mdOpenAI Codex 会按从根目录向下的顺序连接该链。当组合大小达到
(默认 32 KiB)时,它会停止添加文件,因此离工作目录
最近的文件最先被排除(https://developers.openai.com/codex/guides/agents-md/)。
project_doc_max_bytes根目录发现和跳过规则遵循 Codex:
- 根目录是被检查文件所在目录或其上级目录中包含 的最近目录。如果没有
.git,则每条链都只包含被检查文件,报告会显示 "file directory" 而不是 "repository root"。.git - 在每个目录中,存在 时以它为准,否则使用
AGENTS.override.md。AGENTS.md - 大小按磁盘原始字节数计算,因此 CRLF 行尾也会被完整计入。
- 遍历会跳过点目录、、失效符号链接,以及拥有自身
node_modules的任何 子目录(嵌套项目根目录)。.git
当没有链突破上限、没有镜像发生偏离,且所有被引用的 recipe 和路径均存在时,
退出码为 0。出现上限突破、任何漂移(镜像偏离、recipe 缺失或路径缺失),或
文件不存在时,退出码为 1。
--jsonpathbyteschain_byteschain_dirroot_marker.gitlinesbyte_capcap_breachnear_capline_warnheadingsjustfilereferenced_just_recipesmissing_recipesreferenced_pathsmissing_pathsmirrorsdiverged_mirrorsdrift3. Content audit
3. 内容审计
For every command and path AGENTS.md names, verify it against the real
repository, not against memory:
- Every backticked exists in the
just <recipe>— the script checks this; treat ajustfileline as a stale command, not a script bug.FAIL missing just recipes - Every backticked repo-relative path exists — same treatment for
.
FAIL missing referenced paths - Quality gates, conventions, and "do not touch" boundaries match the project's actual CI and review practice, not an aspirational one.
- PR and commit rules are stated, not implied.
Anti-patterns to flag and remove, per :
narrative history, README duplication, secrets or tokens, per-person
preferences, and any command that no longer runs.
references/content-checklist.md对于 AGENTS.md 提到的每个命令和路径,都要根据真实仓库进行验证,而不是凭记忆:
- 每个用反引号括起的 都必须存在于
just <recipe>中——脚本会检查 这一点;将justfile行视为过期命令,而不是脚本缺陷。FAIL missing just recipes - 每个用反引号括起的仓库相对路径都必须存在——同样应将
视为过期引用,而不是脚本缺陷。
FAIL missing referenced paths - 质量门禁、约定和 "do not touch" 边界应符合项目的实际 CI 和评审实践, 而不是理想化目标。
- PR 和 commit 规则应明确写出,而不是仅靠暗示。
根据 ,需要标记并移除以下反模式:
叙述性历史、README 重复内容、密钥或 token、个人偏好,以及任何已无法运行的命令。
references/content-checklist.md4. Mirror strategy
4. 镜像策略
Keep exactly one canonical . For each mirror:
AGENTS.md- : either absent, or contains only
CLAUDE.md(a Claude Code import — https://code.claude.com/docs/en/memory). Do not duplicate content into it.@AGENTS.md - : either absent (Copilot reads
.github/copilot-instructions.mddirectly) or a short pointer. If the user wants Copilot-specific content (path-scopedAGENTS.mdrules, code-review knobs), route toapplyTo— do not author that file here./github-copilot-repo-instructions - : either absent or a short pointer, same pattern as CLAUDE.md.
GEMINI.md
Report any mirror the check script marks as drift, and propose
collapsing it to a pointer or removing it.
diverged每个范围只保留一个规范的 。对于每个镜像文件:
AGENTS.md- :要么不存在,要么只包含
CLAUDE.md(Claude Code 导入—— https://code.claude.com/docs/en/memory)。不要在其中重复内容。@AGENTS.md - :要么不存在(Copilot 会直接读取
.github/copilot-instructions.md),要么只包含一个简短指针。如果用户需要 Copilot 专用内容 (按路径限定的AGENTS.md规则、代码审查选项),请转至applyTo——不要在此处编写该文件。/github-copilot-repo-instructions - :要么不存在,要么只包含一个简短指针,与 CLAUDE.md 的模式相同。
GEMINI.md
如果检查脚本将任何镜像标记为 ,则将其报告为漂移,并建议将其折叠为
指针或删除。
diverged5. Nested AGENTS.md
5. 嵌套 AGENTS.md
For a monorepo or multi-package layout, put a nested in each
package that needs its own rules. Codex, Claude Code, Cursor, Gemini CLI,
and Copilot CLI load the nested file together with every ancestor file. No
harness replaces the root file with the nested file. The nearer file wins
only on conflict. See for each harness.
AGENTS.mdreferences/harness-matrix.md- Put only the subtree's delta in the nested file: its own commands, boundaries, and exceptions. A copied root rule duplicates context when both files load and can drift.
- State each exception to a root rule explicitly, and name the root rule that it replaces. VS Code warns that harnesses do not share one precedence order.
- Keep every root-to-leaf chain under the Codex 32 KiB cap. Codex drops the nearest files first.
- Claude Code reads a nested only when that directory has no
AGENTS.mdof its own.CLAUDE.md
对于 monorepo 或多包布局,在每个需要独立规则的包中放置嵌套 。
Codex、Claude Code、Cursor、Gemini CLI 和 Copilot CLI 会将嵌套文件与每个祖先
文件一起加载。没有任何 harness 会用嵌套文件替换根文件。只有在发生冲突时,
距离更近的文件才优先。有关各 harness 的行为,请参阅
。
AGENTS.mdreferences/harness-matrix.md- 嵌套文件中只写子树的增量内容:其自身命令、边界和例外。复制根规则会在两个 文件同时加载时造成上下文重复,并可能产生漂移。
- 明确说明每一条根规则例外,并指出它所替代的根规则。VS Code 提醒各 harness 并不使用统一的优先级顺序。
- 确保每条从根到叶的链都低于 Codex 的 32 KiB 上限。Codex 会最先排除距离 工作目录最近的文件。
- 只有在该目录没有自己的 时,Claude Code 才会读取嵌套的
CLAUDE.md。AGENTS.md
6. Trim or rewrite
6. 精简或重写
Always show the proposed change as a diff against the current file. Then
stop and ask for explicit approval before writing or any
mirror. A request to skip the diff ("I don't need to see the diff") does
not waive this step and is not approval. Write only after the user
approves the diff that you showed.
AGENTS.mdNever run or . Leave the changes in the working
tree. The user owns commits.
git commitgit pushUse as the starting shape for a new file, not
as boilerplate to paste unedited — every section must reflect this
repository's actual commands and boundaries.
assets/AGENTS.md.template始终以相对于当前文件的 diff 形式展示拟议更改。然后停止并请求明确批准,之后
才能写入 或任何镜像文件。要求跳过 diff
("I don't need to see the diff")并不豁免此步骤,也不构成批准。只有用户批准
你展示的 diff 后才能写入。
AGENTS.md绝不运行 或 。将更改留在工作树中,commit 由用户负责。
git commitgit push对于新文件,使用 作为初始结构,不要原样粘贴其中的
样板内容——每个部分都必须反映该仓库实际使用的命令和边界。
assets/AGENTS.md.template7. Verify
7. 验证
bash
python3 "$AGENTS_MD_CHECK" --self-test
python3 "$AGENTS_MD_CHECK"Both must exit 0. Re-run any command the audit changed or added before
reporting done.
bash
python3 "$AGENTS_MD_CHECK" --self-test
python3 "$AGENTS_MD_CHECK"两者都必须以退出码 0 结束。在报告完成之前,重新运行审计过程中修改或新增的
所有命令。
Rules
规则
- One canonical per directory scope. Mirrors point at it; they do not restate it.
AGENTS.md - Never invent a command or path. Every backticked and every referenced path must exist — the check script verifies this, do not skip it.
just <recipe> - Do not add narrative, README duplication, secrets, or per-person
preferences. See for the full list.
references/content-checklist.md - Do not write content beyond a short pointer — that authoring belongs to
.github/copilot-instructions.md./github-copilot-repo-instructions - Do not touch personal or machine-global instruction files.
- Show the diff and get explicit approval before overwriting an existing
or mirror. A request to skip the diff is not approval.
AGENTS.md - Never run ,
git commit, or any other publication command. Leave changes in the working tree.git push
- 每个目录范围只保留一个规范的 。镜像指向它,不复述其内容。
AGENTS.md - 绝不虚构命令或路径。每个用反引号括起的 和每个被引用的 路径都必须存在——检查脚本会验证这一点,不得跳过。
just <recipe> - 不要添加叙述性内容、README 重复内容、密钥或 token、个人偏好。完整列表请参阅
。
references/content-checklist.md - 不要在 中写入超出简短指针的内容——该文件的 编写工作属于
.github/copilot-instructions.md。/github-copilot-repo-instructions - 不要处理个人或机器全局的指令文件。
- 覆盖现有 或镜像文件前,必须展示 diff 并获得明确批准。要求跳过 diff 不构成批准。
AGENTS.md - 绝不运行 、
git commit或其他任何发布命令。将更改留在工作树中。git push
References
参考资料
- — which harness reads which file, with precedence and size caps, cited.
references/harness-matrix.md - — what belongs in AGENTS.md and what does not. Harness-behavior claims are cited; the lists are this skill's guidance.
references/content-checklist.md - — a short, sectioned starting template.
assets/AGENTS.md.template
- ——哪些 harness 读取哪些文件,并附有优先级、大小 上限及引用来源。
references/harness-matrix.md - ——哪些内容应放入 AGENTS.md,哪些内容不应放入。 harness 行为相关论断附有引用;这些列表则是本 skill 的指导准则。
references/content-checklist.md - ——一个简短、分章节的初始模板。
assets/AGENTS.md.template