这是目前 GitHub 前端/AI 圈最火的方向。因为大家都在用 AI 写代码,发现 AI 容易"放飞自我"(写得太复杂、乱改代码),所以大神们总结了一套**"如何让 AI 乖乖写代码"**的知识库。
-
项目名称:`andrej-karpathy-skills` (或者叫 `CLAUDE.md` 规范)
-
火爆程度:一周内冲上趋势榜第一,Star 数破 6 万。
-
核心内容
这不是代码,而是一份 Markdown 文档。它基于 AI 大神 Andrej Karpathy 的经验,总结了 4 条 AI 必须遵守的铁律:
- 编码前思考:遇到歧义先问,别瞎猜。
- 简洁优先:能用 50 行写完,绝不写 200 行(拒绝过度抽象)。
- 精准修改:只改必须改的地方,别顺手重构别人的代码。
- 目标驱动:先写测试复现 Bug,再修复它。
-
怎么用:
你可以直接把它的核心内容复制到你 Antigravity 的 `knowledge` 目录里,或者在项目根目录放一个 `CLAUDE.md` 文件。这能极大提升 AI 写前端代码的"听话程度"。
全局添加 Antigravity 的 Knowledge(知识库)非常简单,这相当于给你的 AI 装上一个"永久记忆体"。一旦配置好,无论你打开哪个项目,AI 都会自动读取这些规则,不需要重复配置。
以下是具体的操作步骤:
第一步:找到或创建全局目录
`Antigravity`的全局配置通常存储在用户主目录下的 `.gemini` 文件夹中。
-
打开文件资源管理器(Windows)或 访达(Mac)。
-
进入以下路径
- Windows: `C:\\Users\\你的用户名\\.gemini\\antigravity\\`
- Mac / Linux: `~/.gemini/antigravity/`
-
检查目录
查看是否存在名为 `knowledge` 的文件夹。
- 如果没有:请手动新建一个文件夹,命名为 `knowledge`。
小贴士:`.gemini` 是隐藏文件夹。
- Windows: 如果看不到,需要在查看选项中勾选"隐藏的项目"。
- Mac: 在访达中按 `Command + Shift + .` 可以显示隐藏文件。
把对应的CLAUDE.md放在`knowledge`这个文件夹下面即可
```markdown
CLAUDE.md
Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.
Tradeoff: These guidelines bias toward caution over speed. For trivial tasks, use judgment.
1. Think Before Coding
Don't assume. Don't hide confusion. Surface tradeoffs.
Before implementing:
- State your assumptions explicitly. If uncertain, ask.
- If multiple interpretations exist, present them - don't pick silently.
- If a simpler approach exists, say so. Push back when warranted.
- If something is unclear, stop. Name what's confusing. Ask.
2. Simplicity First
Minimum code that solves the problem. Nothing speculative.
- No features beyond what was asked.
- No abstractions for single-use code.
- No "flexibility" or "configurability" that wasn't requested.
- No error handling for impossible scenarios.
- If you write 200 lines and it could be 50, rewrite it.
Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
3. Surgical Changes
Touch only what you must. Clean up only your own mess.
When editing existing code:
- Don't "improve" adjacent code, comments, or formatting.
- Don't refactor things that aren't broken.
- Match existing style, even if you'd do it differently.
- If you notice unrelated dead code, mention it - don't delete it.
When your changes create orphans:
- Remove imports/variables/functions that YOUR changes made unused.
- Don't remove pre-existing dead code unless asked.
The test: Every changed line should trace directly to the user's request.
4. Goal-Driven Execution
Define success criteria. Loop until verified.
Transform tasks into verifiable goals:
- "Add validation" -> "Write tests for invalid inputs, then make them pass"
- "Fix the bug" -> "Write a test that reproduces it, then make it pass"
- "Refactor X" -> "Ensure tests pass before and after"
For multi-step tasks, state a brief plan:
- [Step] -> verify: [check]
- [Step] -> verify: [check]
- [Step] -> verify: [check]
Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
```
Trae 的全局配置通常在用户主目录下:
Windows: `C:\\Users\\你的用户名\\.trae\\`
Mac: `~/.trae/`
创建规则文件
在 .trae 目录下,找到或新建一个名为 rules 或 knowledge 的文件夹。