docs: split language by audience, add Codex / AGENTS.md spec

Language policy: Chinese for human-facing files (README, docs/,
human-fillable templates), English for AI-facing files (CLAUDE.md,
AGENTS.md, AI templates). Commits / PRs / branches / tags stay
English.

- Translate docs/01-06 to Chinese
- Translate README.md, PR / handoff / project README templates to Chinese
- Drop README.en.md (redundant once language policy is explicit)
- Rewrite CLAUDE.md and CLAUDE.md.template under the new policy
- Add AGENTS.md (root) and templates/AGENTS.md.template for Codex
- Add docs/07-codex.md covering Codex usage and AGENTS.md / CLAUDE.md sync rules

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
阿白叔andClaude Opus 4.7 committed 2026-05-20 09:44:15 +08:00
1 parent 411f0b8182
commit 154f592f3c
16 files changed
+901 -690

No files matched your search

+78 -85
View File
@@ -1,129 +1,122 @@
# 02 — Claude Code
How we configure and use Claude Code across projects.
我们在每个项目里怎么配置和使用 Claude Code。
## Configuration files
## 配置文件
Each project should have:
每个项目应该有:
```
<repo>/
├── CLAUDE.md ← project context (committed)
├── CLAUDE.md ← 项目上下文(提交进仓库)
├── AGENTS.md ← Codex / 通用 agent 上下文(提交)
└── .claude/
├── settings.json ← shared settings (committed)
├── settings.local.json ← personal overrides (gitignored)
└── skills/ ← project-local skills (committed)
├── settings.json ← 共享设置(提交)
├── settings.local.json ← 个人覆盖(gitignore)
└── skills/ ← 项目级 skill(提交)
```
`settings.local.json` is **always** gitignored. Personal API keys, local
paths, and individual hook tweaks live there.
`settings.local.json` **永远** gitignore。个人 API key、本地路径、
个人 hook 调整都放这里。
## CLAUDE.md content
`AGENTS.md` 见 [docs/07-codex.md](07-codex.md)——给 Claude 看 `CLAUDE.md`,
给 Codex 看 `AGENTS.md`,两个文件内容大体一致,工具读各自的。
Every `CLAUDE.md` answers, in this order:
## CLAUDE.md 的内容
1. **What is this project?** Two sentences max.
2. **How do I run it?** Build, test, lint commands as bash blocks.
3. **Architecture in one paragraph.** Where the entry points are and
how data flows. No diagrams unless they save words.
4. **Conventions specific to this repo.** Naming, layout, patterns
that aren't obvious from the code.
5. **Don'ts.** Things Claude has gotten wrong before. One line each.
每个 `CLAUDE.md` 按这个顺序回答:
A new contributor (human or AI) should be productive after reading it
once. If a `CLAUDE.md` is over 100 lines, it's drifted into documentation
and should be split.
1. **这是个什么项目?** 最多两句话。
2. **怎么跑?** Build、test、lint 命令,写成 bash 块。
3. **架构一段话。** 入口在哪、数据怎么流。除非能省字,否则不画图。
4. **本仓库特有的约定。** 命名、目录、那些不看注释看不出来的模式。
5. **不要做的事。** Claude 以前在这里翻过的车,每条一行。
Use `templates/CLAUDE.md.template` as the starting point.
新人(人或 AI)读一遍就该能上手干活。`CLAUDE.md` 超过 100 行,说明
它已经偷偷变成"文档"了,应该拆出去。
## Permissions
用 `templates/CLAUDE.md.template` 起手。
Default permission posture: **prompt for everything risky, allow read-only
freely.**
## 权限(permission)
In `.claude/settings.json`, allow these without prompting:
默认姿态:**只读自由放行,能改的都问一下。**
- All `Read`, `Glob`, `Grep` tools
- `Bash(git status)`, `Bash(git diff)`, `Bash(git log)`, `Bash(git branch)`
- Project-specific read-only commands (e.g. `Bash(npm test)`, `Bash(pytest)`)
`.claude/settings.json` 里可以无提示放行:
Always prompt for:
- 所有 `Read`、`Glob`、`Grep`
- `Bash(git status)`、`Bash(git diff)`、`Bash(git log)`、`Bash(git branch)`
- 项目特定的只读命令(`Bash(npm test)`、`Bash(pytest)` 这类)
- File `Edit` / `Write` outside the working tree
- `Bash` with destructive verbs (`rm`, `mv`, `git push`, `git reset --hard`, package installs)
- Any MCP tool that talks to a remote service
永远要弹窗确认:
When you find yourself approving the same prompt over and over, run the
`fewer-permission-prompts` skill — it scans your transcripts and
proposes an allowlist.
- 工作树之外的 `Edit` / `Write`
- 带破坏动词的 `Bash`(`rm`、`mv`、`git push`、`git reset --hard`、装包)
- 任何会跟外部服务对话的 MCP 工具
## Hooks
如果你发现自己在反复批准同一类提示,跑一下 `fewer-permission-prompts`
skill——它会扫 transcript 给你列一份允许列表。
Hooks are how the harness enforces rules automatically — Claude itself
won't reliably remember a "from now on…" instruction across sessions.
## Hook(钩子)
Use hooks for:
Hook 是让 harness 自动执行规则的方式——AI 自己**不可靠地**记住"以后
都要 X",跨 session 会忘。
- Auto-formatting on file edit (Prettier, ruff, gofmt)
- Blocking edits to protected paths (`.env`, generated files, `dist/`)
- Auto-running tests after a write to a known test path
- Notifying on session stop / long-running task completion
适合用 hook 的事:
Don't use hooks for:
- 文件保存后自动格式化(Prettier、ruff、gofmt)
- 阻止改受保护路径(`.env`、生成文件、`dist/`)
- 写测试路径后自动跑测试
- session 结束 / 长任务完成时通知
- One-off checks ("just remember to do X this week")
- Anything that depends on Claude's judgment ("only run if it makes sense")
不适合用 hook 的:
Configure via the `update-config` skill or edit `.claude/settings.json`
directly. Document each hook with a one-line comment in the JSON.
- 一次性检查("这周记得 X 一下")
- 任何依赖 AI 判断的("觉得有必要就跑")
## Memory
通过 `update-config` skill 配置,或者直接编辑 `.claude/settings.json`。
JSON 里每个 hook 加一行注释说明。
The harness has a per-machine memory system. Use it for:
## Memory(记忆)
- **User**: who you are, your role, your preferences.
- **Feedback**: corrections you've given Claude that should stick across
sessions (with the *why*).
- **Project**: facts about ongoing work that aren't in the code (deadlines,
stakeholder decisions, why a refactor is happening).
- **Reference**: pointers to external resources (Linear projects, Grafana
dashboards, internal wikis).
Harness 有按机器的记忆系统。用法:
Don't put memory content in `CLAUDE.md`. CLAUDE.md is project context,
shared with the team. Memory is personal, per-machine, and lives outside
the repo.
- **User**:你是谁、角色、偏好。
- **Feedback**:你给 AI 的纠正,要跨 session 保留的(带上**为什么**)。
- **Project**:进行中工作的事实,代码里没写的(截止日期、相关方决策、
为什么要重构)。
- **Reference**:外部资源指针(Linear 项目、Grafana dashboard、内网 wiki)。
Don't use memory as a notes app. If it's task-scoped, it goes in a plan or
PR description.
不要把 memory 内容塞进 `CLAUDE.md`。CLAUDE.md 是项目上下文,团队共享。
Memory 是个人的、按机器的,不进仓库。
## Skills
不要把 memory 当便签本用。任务级别的东西塞进 plan 或 PR description。
Skills live in three places:
## Skill(技能)
- **User skills** (`~/.claude/skills/`) — installed once, available everywhere
- **Project skills** (`<repo>/.claude/skills/`) — committed, shared with team
- **Plugin skills** — installed via marketplace
Skill 在三个地方:
Promote a workflow to a skill once you've done it the same way three
times. See `docs/04-skills-and-planning.md` for the catalog.
- **用户级**(`~/.claude/skills/`)—— 装一次到处可用
- **项目级**(`<repo>/.claude/skills/`)—— 提交进仓库,团队共享
- **插件**—— 通过 marketplace 安装
## Sub-agents
同一个流程做了三次都一样,就提升成 skill。目录见
[docs/04-skills-and-planning.md](04-skills-and-planning.md)。
Spawn a sub-agent (via the `Agent` tool) when:
## Sub-agent(子 agent)
- The task needs a search across many files and you don't want the
results in your main context.
- You want a second, independent read on a design or diff.
- The work is genuinely parallel (e.g. researching three options).
什么时候开 sub-agent(用 `Agent` 工具):
Don't spawn sub-agents for tasks the main agent can do in two tool calls.
The handoff overhead isn't free.
- 任务要跨很多文件搜索,又不想把搜索结果塞进主上下文。
- 想让另一个独立视角再看一遍设计或 diff。
- 工作真的并行(比如同时调研三个方案)。
## Sessions
主 agent 两次工具调用就能搞定的事,别开 sub-agent。交接成本不是免费
的。
- One task per session. Open a new session for a new task.
- If a session is running long and the context bar is filling, finish
the current step, summarize state into a plan or PR draft, then start
fresh.
- Don't use `--continue` to resume a session from yesterday on a new
topic. The stale context will leak in.
## Session
- 一个 session 一个任务。新任务开新 session。
- session 跑长了、上下文条快满了:先收尾当前步骤,把状态总结进 plan
或 PR draft,然后开新 session。
- 别用 `--continue` 把昨天的 session 拉回来做新主题。陈旧上下文会
渗进来。