anchor
engineering discipline for Claude Code & Codex CLI
English · 中文
Claude Code / Codex CLI 的工程化纪律包
让 AI 写代码"少走错路、不偏题、跑到完为止",并且真的记得住跨 session 跨项目的经验。
| 维度 | 数量 | 内容 |
|---|
| Slash commands | 22 | 工作流 / 长任务 / 记忆 / 复盘 / 安全 / Token 经济 |
| Hooks | 5 | SessionStart / Stop / PreToolUse / PostToolUse / PreCompact |
| 防御 patterns | 277+ | 14 轮 audit / 残忍 obfuscation 测试 |
| Regression tests | 364/364 | 15 suites(hooks / 记忆 loop / install / manifest 等) |
| 长期记忆类别 | 7 | pitfalls / decisions / facts / preferences / todos / snapshots / saved-tasks |
| 跨 CLI | 2 | Claude Code + OpenAI Codex CLI |
Quick links:
安装 · 22 个命令 · 设计原则 · Codex CLI · Playbook · 对比表
实测战报(v1.9.1 跑过 3 个真实场景)
在 Codex CLI 上跑 evals/stress/ 里的 3 个长任务测试,用 evals/stress/grade.py(codex-as-judge)评分。
| 场景 | v1.3 baseline | v1.4.6 | v1.9.1 | 改进 |
|---|
| debug 5 个失败测试 | 6/1/1 | 5/2/1 | 6/1/1 | 回到 peak — CLAUDE.md 4-field format ✅ |
| refactor 保留行为 | 3/1/3 | 3/1/3 | 4/0/3 ⬆ | tests-before-refactor 第一次过 |
| scaffold Express + SQLite API | 2/3/0 | 3/2/2 | 3/2/2 | anti-borrow-deps 持续闭环 |
| 总计 (pass/fail/N-A) | 11/5/4 | 11/5/6 | 13/3/6 | +2 pass / -2 fail |
最有信号的 finding:
anti-borrow-deps 跨场景闭环:v1.3 抓到 agent 借 node_modules cheat → v1.3.3 SKILL.md 加 anti-pattern → v1.9.1 stress #1 agent 正确说 "我没法在这里装依赖,请你本地跑 npm install 再跑测试" 并停下。
三段闭环:grade.py finding → SKILL.md update → 实测验证。
跑自己的:./evals/stress/run.sh <1|2|3>
和市面对比 → docs/competitors.md(10+ 同类工具的诚实对比)
它解决什么
| 问题 | anchor 怎么解 |
|---|
| 中途偏题(被 tool 输出带跑、顺手做范围外的事) | /lock 锁用户原话当第一条 task / autonomous mode Stop hook 拦截 |
| 长任务记忆衰减(auto-compact 截掉 skill) | 关键规则前置 SKILL.md / PreCompact 提示 /save / ~/.anchor/active-task.md 跨 session 续接 |
| 单测过 ≠ 功能正确 | /done checklist 强制走 E2E + 二阶自检 |
| 漏洞扫一遍说"干净" | /scan 多遍扫方法论 / /codex:review 交叉验证 |
| 修完 bug 转头就忘 | /pit 写当前项目 CLAUDE.md + 自动 sync 全局 |
| 自己审自己有盲点 | /done 按改动规模触发 codex review;trivial 跳过、复杂/安全/大改必跑 |
| 下次 session 不知道上次踩过什么坑 ⭐ | SessionStart 自动注入本项目 memory index → SKILL.md 规则 #8 "auto-recall reflex" |
| 跨项目复用经验 | /recall <keyword> grep ~/.anchor/memory/ 全部 7 个 category |
| 危险命令本能误操作 | PreToolUse hook 拦 277+ patterns(含组合绕过 / obfuscation / 跨平台变种) |
两层防线:
- 软:SKILL.md 写明工作流,模型主动遵循
- 硬:5 个 hooks 在关键时机自动触发
1 分钟上手
# 1. 安装(一键,含 Codex CLI 检测)
git clone https://github.com/biefan/anchor.git ~/anchor && cd ~/anchor && ./install.sh
# 2. 打开 Claude Code 进项目,第一次先建 CLAUDE.md
/init-claude-md
# 3. 锁定任务 scope
/lock 把 order-service 拆成 6 个模块
# 4. 启动 autonomous mode(做完才停)
touch ~/.claude/.efficient-coding-autonomous
# 5. 干完一阶段
/milestone phase-1-parse-extracted
# 6. 下班保存 / 第二天续接
/save end-of-day-refactor # 收工
/resume-task end-of-day-refactor # 续上
# 7. 修完 bug 写踩坑(跨项目可 /recall 到)
/pit
# 8. 收尾
/done
完整 walkthrough(5 个典型场景)→ docs/playbook.md
22 个 slash commands(概览)
按使用阶段分 6 类:
| 阶段 | 命令 |
|---|
| 开始任务 | /lock /init-claude-md /ec |
| 干活中 | /next /recap /status /diff |
| 长任务跨 session | /save /resume-task /milestone /snapshot |
| 跨项目记忆 | /pit /decide /remember /recall |
| 收尾 / 安全 | /scan /cleanup /done /ship |
| 复盘 / 成本 | /spend /report /lean |
每个命令的详细 + 何时用 → docs/commands.md
自动触发:不用 /<cmd> 也行 — Claude 看到符合 description 的任务自动调用 anchor skill。
设计原则
核心八条
- 意图清晰才开工 · 2. 任务范围用 TaskCreate 锁住 · 3. 先读项目契约
- 最小正确改动 · 5. 能派 agent 就派并行 · 6. 审查看情况调 codex
- 踩坑回写 CLAUDE.md · 8. 遇到 topic 先 /recall ⭐
每条详解 + 反模式 + 完成清单 → docs/design.md
跨项目记忆 closed loop(v1.9.0+)