karpathy-guidelines
它能做什么
这份指南能帮助 AI 避免常见错误,从而写出更好的代码。它教 AI 在动手编码前先思考、保持代码简洁、只做必要的修改,并明确定义什么样的结果才算好。
适用场景
- ✓当 AI 在编写新代码时。
- ✓当 AI 需要修复或改进现有代码时。
- ✓当你希望 AI 避免不必要的复杂化时。
技能链接
https://github.com/multica-ai/andrej-karpathy-skills/blob/main/skills/karpathy-guidelines/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
📦 包含此技能的技能包
可以这样问 AI
“AI,帮我写一个计算数字列表平均值的函数,但请在开始前仔细思考,只添加必不可少的内容。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会按步骤进行:先想清楚再写代码,只关注最低限度的需求,只修改必要的部分,并定义如何判断任务已经完成。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Karpathy Guidelines
Behavioral guidelines to reduce common LLM coding mistakes, derived from Andrej Karpathy's observations on LLM coding pitfalls.
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:
1. [Step] → verify: [check]
2. [Step] → verify: [check]
3. [Step] → verify: [check]
Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
常见问题
为什么 AI 要先思考再编码?
为了避免出错、充分理解问题,并且不做出比实际需要更复杂的方案。
“简单的代码”是什么意思?
用尽可能少的代码解决问题,不额外添加功能,也不引入不必要的复杂性。
AI 怎么知道代码是好的?
通过设定清晰、可验证的目标。例如,不是笼统地说“修复这个 bug”,而是把目标定为“先写一个能复现 bug 的测试,然后让测试通过”。
详情
作者的原始描述
Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.
热度
- GitHub 星标
- 220k
- 排名
- #628
- 许可证
- —
- 更新时间
- 2026/4/20
评论
- …