agent-instructions Skill
基于仓库实际情况创建或统一管理 AGENTS.md、CLAUDE.md 和 Cursor 规则。当编码智能体的指导文档缺失、过时、重复或冲突时使用。
安装方式:把技能目录放入 ~/.claude/skills/(Claude Code)或在 claude.ai 设置中启用;也可复制右侧安装命令一键添加。
技能指令原文(SKILL.md)
Agent instructions
Write the smallest set of instruction files that each target runtime actually loads. A correct file in a location the runtime skips, or one shadowed by another file, does nothing. Recover facts from the repository before asking, and separate commands you ran from commands you only read about.
Choose the task
- Create: no instruction files exist.
- Improve: one existing file is thin, stale or bloated.
- Reconcile: files duplicate or contradict each other, or one runtime ignores guidance the others see.
- Scope a subtree: a package or directory needs different commands, ownership or boundaries.
- Explain loading: the user asks why an agent ignores its instructions. Report what each runtime loads here. Change nothing unless asked.
Infer the target runtimes from the request, existing files and the user's tooling. Ask only when the answer changes which files exist. "Make this work for our agents" with no other signal means Claude Code, Codex and Cursor.
Read the loading matrix first
Read the loading matrix before choosing any file. It records which files Claude Code, Codex and Cursor read, in what order, with which limits, checked on a stated date. Follow its run-time rule: re-check a runtime's docs when the check date is more than about 90 days old or the installed runtime is older than a version it names.
Inventory every instruction source
pwd
git rev-parse --show-toplevel
rg --files --hidden -g '!node_modules' -g '!.git' \
-g '**/AGENTS.md' -g '**/AGENTS.override.md' -g '**/CLAUDE.md' -g '**/CLAUDE.local.md' \
-g '**/.claude/rules/**' -g '**/.cursor/rules/**' -g '**/.cursorrules'
Then check three places rg misses:
- Ancestors above the repository root. Claude Code loads every
CLAUDE.md,.claude/CLAUDE.mdandCLAUDE.local.mdfrom cwd upward. One in a parent folder shadows the repository'sAGENTS.mdfor Claude Code. Ignore~/.claude/CLAUDE.md; it does not shadow. - Codex fallback names. Read
project_doc_fallback_filenamesandproject_doc_max_bytesin~/.codex/config.toml(or$CODEX_HOME) when present. A fallback-named file is an instruction file for Codex. - Fixture and example directories. An
AGENTS.mdorCLAUDE.mdinside test fixtures, examples or proof folders loads as a real instruction for Claude Code and Cursor when work touches that folder.
For each file record: directory, runtimes that load it, when it loads (launch or on demand), what it shadows or is shadowed by, size, and statements that conflict with a nearer file or with repository evidence.
Treat user-global files (~/.claude/CLAUDE.md, ~/.codex/AGENTS.md) as context that explains behavior. Do not edit them unless asked.
Choose the layout
Default for a repository shared across runtimes:
- One root
AGENTS.mdas the shared source. Codex and Cursor read it. Claude Code reads it when noCLAUDE.mdexists in cwd or above. - Add
CLAUDE.mdonly when Claude-specific rules exist (plan-mode areas, hooks, Claude tool notes) or aCLAUDE.mdalready exists. Its first line is@AGENTS.md; Claude-only notes go below. - Never create a
CLAUDE.md,.claude/CLAUDE.mdorCLAUDE.local.mdwithout that import in a repository that relies onAGENTS.md. It silently dropsAGENTS.mdfor Claude Code. This includes advising a user to add a personalCLAUDE.local.md. - Existing
CLAUDE.mdwith shared content plusAGENTS.md: move shared facts intoAGENTS.md, reduceCLAUDE.mdto@AGENTS.mdplus Claude-only notes. Ask before deleting aCLAUDE.mdthat holds anything beyond the import. - Cursor:
AGENTS.mdalready covers it. Add.cursor/rules/*.mdconly for activationAGENTS.mdcannot express: glob-scoped rules or description-selected rules. Do not copyAGENTS.mdcontent into rules. Cursor does not inline@filereferences in rules, so put must-have content in the rule body. - Path-scoped Claude rules: use
.claude/rules/*.mdwithpaths:for guidance that matters only for some files, instead of growingCLAUDE.mdpast about 200 lines. - Do not create
AGENTS.override.mdfor shared rules. Only Codex reads it. Flag an existing one as a divergence. - Keep shared content inline in
AGENTS.md.@pathimports expand only in Claude Code. Codex documents no import syntax, so imported content is invisible to it.
Do not create parallel vendor files the runtimes do not need. One AGENTS.md often covers all three.
Nested files
Add a nested AGENTS.md only when a subtree needs different commands, ownership or boundaries. Put only the difference in it. Nearer files come later in context in all three runtimes. Codex and Cursor treat that as precedence; Claude Code does not guarantee it, so a nested file must add to its parents, not contradict them. Reach also differs:
- Claude Code and Cursor pick up a nested file when work touches that directory.
- Codex loads only directories from the project root down to where it was started. Started at the root, it never sees
services/payments/AGENTS.md.
So when a subtree rule must hold for Codex, add a one-line pointer in the root file ("Before editing services/payments/, read services/payments/AGENTS.md"), or document starting Codex in that directory.
Size
Codex stops adding files once the combined size reaches 32 KiB by default, so a long root file pushes nested files out. Claude Code recommends under 200 lines per CLAUDE.md, and imports do not reduce context cost. Cut content an agent can derive from the code: directory trees, dependency lists, generic style advice.
Build an evidence map
Read the minimum evidence needed to establish:
- package or workspace boundaries and runtime versions;
- install, dev, build, lint, typecheck, test and release commands;
- generated files, migrations, credentials, deployment configuration and other high-risk areas;
- conventions an agent would get wrong from defaults (package manager, test runner, formatting, file placement);
- required services, environment variables, ports and setup order.
Prefer manifests, scripts, CI workflows and executable configuration over prose. When sources disagree, report the conflict and use the source that controls execution (CI usually wins over README).
Include a path only when it changes how an agent navigates, edits or verifies. Write instructions an agent can check: "Run npm test before finishing" beats "test your changes".
Verify commands proportionately
Label each command:
- executed: ran successfully here;
- partially verified: syntax or a narrow target ran, but dependencies or services blocked the full run;
- documented only: found in a trusted project source, not run;
- stale or conflicting: contradicted by configuration, or failed for a repository reason.
Run safe, relevant checks. Do not start long-lived services, mutate external systems, install dependencies or run destructive commands to upgrade a label. State prerequisites next to commands that need them.
Resolve conflicts explicitly
For each conflict choose one action:
- retain the nearer scoped rule;
- replace stale guidance with verified repository behavior;
- separate runtime-specific mechanics from shared facts;
- ask the user when two live policies express different intent the repository cannot settle.
Do not silently choose between policy statements about deployment, generated files, security, data handling or ownership.
Output contract
- The instruction files written or changed (or, in Explain loading mode, none).
- A loading table: for each target runtime, which files load at the root and in each scoped directory, and which are shadowed or skipped.
- A command table with verification labels.
- Conflicts resolved, preserved, or awaiting a decision.
- Facts left out because they were unverified or volatile, and any loader fact re-checked against docs this run, with the date.
Verify
- Re-read every instruction file that applies to each edited location. Confirm each target runtime loads the intended files and nothing shadows them, using the loading matrix.
- Where a runtime is installed, confirm with its own check:
/context allor/memoryin Claude Code;codex --ask-for-approval never "Summarize the current instructions."(add--cdfor a subtree) in Codex; Customize, Rules in Cursor. Otherwise label loading as reasoned from docs, not observed. - Measure combined bytes on each Codex path (
wc -c) against the 32 KiB default and eachCLAUDE.mdagainst about 200 lines. - Confirm every path, script, package name, port and environment variable exists in repository evidence.
- Re-run the safe commands used as acceptance checks, or label them accurately.
- Confirm nested files hold only scope-specific differences and do not contradict inherited rules.
- Check
.mdcfrontmatter and glob coverage against the files each rule should govern. - Remove unsupported claims, generic agent advice and duplicated repository documentation. Do not describe a documented-only command as tested.