目录摘要一、为什么卡帕西 AI 编程规则突然火了1.1 项目背景1.2 Karpathy 观察到的 AI 编程问题1.3 四条核心原则二、GitHub 上如何找到 andrej-karpathy-skills 和 AGENTS.md2.1 搜索项目主页2.2 为什么首页可能找不到 AGENTS.md2.3 找到 Pull Request #1641打开项目主页2点击顶部菜单中的 Pull requests3打开这个 PR2.4 点击进入 Add Codex AGENTS instructions三、Codex、Claude Code、Cursor 都能用吗3.1 三者都可以用但入口文件不同3.2 三者内容一样吗3.3 怎么选择四、三种工具对应的规则文件内容4.1 Codex 对应内容AGENTS.md4.2 Claude Code 对应内容CLAUDE.md4.3 Cursor 对应内容karpathy-guidelines.mdc4.4 三种文件内容对比五、使用建议与总结5.1 建议一不要只放通用规则还要加项目规则5.2 建议二Codex、Claude Code、Cursor 可以同步维护5.3 建议三不要期待规则 100% 强制执行六、总结摘要最近 GitHub 上一个名为andrej-karpathy-skills的项目非常火。它把 Andrej Karpathy 对 AI 编程智能体常见问题的观察整理成了一套非常实用的行为准则用来约束 Claude Code、Cursor、Codex 这类 AI 编程工具。这个项目的核心目标不是让 AI 写更多代码而是让 AI 写代码时更稳、更准、更少乱改。它通过CLAUDE.md、.cursor/rules/karpathy-guidelines.mdc、AGENTS.md这类规则文件约束 AI 在写代码前先思考、实现时保持简单、修改时只动必要代码、完成后必须验证结果。本文重点讲三件事第一这个项目到底解决什么问题第二如何在 GitHub 上一步步找到 Codex 可用的AGENTS.md第三给出最终可直接复制到 Codex 自定义指令中的AGENTS.md完整项目地址https://github.com/multica-ai/andrej-karpathy-skillshttps://github.com/multica-ai/andrej-karpathy-skills后续可以部署到对应的Agents上比如我这是Codex1. 打开Codex点击左下角设置2. 点击个性化在自定义指令中将 AGENTS.md 内容复制进去一、为什么卡帕西 AI 编程规则突然火了1.1 项目背景andrej-karpathy-skills是一个围绕 AI 编程智能体行为约束的开源项目。项目 README 中介绍它原本主要通过一个CLAUDE.md文件改善 Claude Code 的行为规则来源于 Andrej Karpathy 对 LLM 编程常见问题的观察。项目当前在 GitHub 上已经达到约170k Star、17.4k ForkStar 数会持续变化所以网上看到的 11.7 万、15 万、17 万本质上都是不同时间点的数据。项目链接https://github.com/multica-ai/andrej-karpathy-skills有些文章中也可能写成https://github.com/forrestchang/andrej-karpathy-skills现在访问时建议优先使用multica-ai/andrej-karpathy-skills这个仓库地址。1.2 Karpathy 观察到的 AI 编程问题在 AI 编程过程中LLM Agent 经常会出现一些很典型的问题。1默默做假设用户只是说“帮我优化一下”AI 可能没有问清楚到底是优化性能、代码结构、可读性还是修复潜在 bug就自己选择一个方向开始改。2过度复杂化一个本来几十行代码能解决的问题AI 可能会加一堆抽象层、配置项、工具类和复杂错误处理。项目 README 中也提到模型容易把原本 100 行能完成的事情扩展成 1000 行。3乱改无关代码AI 在修改一个小功能时经常会顺手改动旁边的注释、格式、命名甚至重构不相关代码。这样会导致 diff 很脏代码审查难度变大。4没有验证目标很多 AI 编程任务只是“改完了”但没有明确验证bug 是否复现过测试是否通过功能是否符合预期这就很容易出现“看起来改了其实没改对”的情况。1.3 四条核心原则这个项目把这些问题总结成四条规则1Think Before Coding先思考再编码要求 AI 不要一上来就写代码而是先说明假设。如果有多种理解方式要主动说出来。如果需求不清楚要先问。2Simplicity First简洁优先要求 AI 用最少代码解决问题不要添加用户没有要求的功能不要为了单次使用写复杂抽象。3Surgical Changes精准修改要求 AI 只修改任务直接相关的代码不要顺手优化无关内容不要删除自己不理解的旧代码。4Goal-Driven Execution目标驱动执行要求 AI 把模糊任务变成可验证目标。例如“修复 bug”应该变成“先复现 bug再写测试或最小复现场景然后修复并验证”。这四条规则的核心价值可以总结为一句话让 AI 不再只是能写代码而是写得更像一个有边界感的工程助手。二、GitHub 上如何找到 andrej-karpathy-skills 和 AGENTS.md2.1 搜索项目主页先打开 GitHub搜索multica-ai/andrej-karpathy-skills进入项目主页后可以看到项目描述大致是一个用于改善 Claude Code 行为的CLAUDE.md文件来源于 Andrej Karpathy 对 LLM 编程陷阱的观察。项目文件列表中能看到CLAUDE.md、CURSOR.md、EXAMPLES.md、README.md、.cursor/rules、skills/karpathy-guidelines等内容。2.2 为什么首页可能找不到 AGENTS.md这里要注意一点项目主页当前主要文件是CLAUDE.md和 Cursor 相关规则不一定能直接在主分支根目录看到AGENTS.md。原因是AGENTS.md 是在 Pull Request #164 中新增的。也就是说Codex 版本的AGENTS.md来源于该项目的一个 PR而不是一开始就在主分支根目录里。2.3 找到 Pull Request #164操作步骤如下1打开项目主页https://github.com/multica-ai/andrej-karpathy-skills2点击顶部菜单中的 Pull requests进入后搜索Add Codex AGENTS instructions3打开这个 PRPR 名称是Add Codex AGENTS instructions #164这个 PR 是由gitbenlewis提交目标是把 1 个 commit 合并到multica-ai:main并且文件变化中包含AGENTS.md和README.md。PR 链接https://github.com/multica-ai/andrej-karpathy-skills/pull/164/files2.4 点击进入 Add Codex AGENTS instructions进入 PR 后点击Commits然后在文件列表中可以看到Add Codex AGENTS instructions点击进入可以看到AGENTS.md其中AGENTS.md是新增文件显示为 65 行新增内容。文件内容从# AGENTS.md开始后面就是四条行为准则Think Before Coding、Simplicity First、Surgical Changes、Goal-Driven Execution。PR 中 README 也新增了Using with Codex部分说明这个仓库新增根目录AGENTS.md后Codex 可以读取和项目指令相同的行为准则如果要在其他项目复用可以把AGENTS.md复制到目标项目根目录或者合并进已有的AGENTS.md。三、Codex、Claude Code、Cursor 都能用吗3.1 三者都可以用但入口文件不同答案是Codex、Claude Code、Cursor 都可以用这套规则。但是它们读取规则的方式不完全一样。工具推荐文件推荐位置作用CodexAGENTS.md项目根目录或~/.codex/AGENTS.mdCodex 项目级/全局指令Claude CodeCLAUDE.md项目根目录或~/.claude/CLAUDE.mdClaude Code 项目记忆/用户记忆Cursorkarpathy-guidelines.mdc或AGENTS.md.cursor/rules/或项目根目录Cursor 项目规则Codex 官方文档说明Codex 会在开始工作前读取AGENTS.md并且支持全局作用域和项目作用域。例如全局文件可以放在~/.codex/AGENTS.md项目文件可以放在仓库根目录。Codex 会按照从全局到项目、从根目录到当前目录的顺序组合这些规则。Claude Code 官方文档说明CLAUDE.md可以作为项目记忆或用户记忆被自动加载例如项目级可以放在./CLAUDE.md用户级可以放在~/.claude/CLAUDE.md。Cursor 官方文档说明Project Rules 通常存放在.cursor/rules目录中规则文件使用.mdc格式同时新版规则体系也支持AGENTS.md作为更简单的 Agent 指令方式。3.2 三者内容一样吗核心内容是一样的。不管是 Codex 的AGENTS.mdClaude Code 的CLAUDE.md还是 Cursor 的.cursor/rules/karpathy-guidelines.mdc它们本质上都是同一套 Karpathy 风格行为准则1. Think Before Coding 2. Simplicity First 3. Surgical Changes 4. Goal-Driven Execution区别主要有三个1文件名不同Codex 推荐使用AGENTS.mdClaude Code 推荐使用CLAUDE.mdCursor 推荐使用.cursor/rules/karpathy-guidelines.mdc2加载方式不同Codex 会读取AGENTS.mdClaude Code 会读取CLAUDE.mdCursor 会读取.cursor/rules/下的规则文件。项目中的CURSOR.md也说明Cursor 不会默认读取.claude-plugin/或CLAUDE.md所以 Cursor 更推荐使用.cursor/rules/karpathy-guidelines.mdc。3Cursor 需要额外的 frontmatterCursor 的.mdc文件前面一般会有一段元信息例如--- description: ... alwaysApply: true ---其中alwaysApply: true表示这条规则尽量始终应用到当前项目中。项目的CURSOR.md中也说明该仓库已经提交了.cursor/rules/karpathy-guidelines.mdc并设置为alwaysApply: true。3.3 怎么选择如果你主要用 Codex就用AGENTS.md如果你主要用 Claude Code就用CLAUDE.md如果你主要用 Cursor就用.cursor/rules/karpathy-guidelines.mdc它们内容核心保持一致即可。这样不管你用哪个 AI 编程工具打开项目都能受到同一套工程规则约束。四、三种工具对应的规则文件内容4.1 Codex 对应内容AGENTS.md如果你使用 Codex可以在项目根目录新建AGENTS.md然后复制下面内容。# AGENTS.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 **Dont assume. Dont hide confusion. Surface tradeoffs.** Before implementing: - State your assumptions explicitly. If uncertain, ask. - If multiple interpretations exist, present them - dont pick silently. - If a simpler approach exists, say so. Push back when warranted. - If something is unclear, stop. Name whats 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 wasnt 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: - Dont improve adjacent code, comments, or formatting. - Dont refactor things that arent broken. - Match existing style, even if youd do it differently. - If you notice unrelated dead code, mention it - dont delete it. When your changes create orphans: - Remove imports/variables/functions that YOUR changes made unused. - Dont remove pre-existing dead code unless asked. The test: Every changed line should trace directly to the users 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. --- **These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.Codex 全局使用时可以放到~/.codex/AGENTS.md项目级使用时可以放到项目根目录my_project/ ├── AGENTS.md ├── src/ ├── include/ ├── CMakeLists.txt └── README.md4.2 Claude Code 对应内容CLAUDE.md如果你使用 Claude Code可以在项目根目录新建CLAUDE.md内容和AGENTS.md基本一样只是文件名和标题改成CLAUDE.md。# 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 **Dont assume. Dont hide confusion. Surface tradeoffs.** Before implementing: - State your assumptions explicitly. If uncertain, ask. - If multiple interpretations exist, present them - dont pick silently. - If a simpler approach exists, say so. Push back when warranted. - If something is unclear, stop. Name whats 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 wasnt 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: - Dont improve adjacent code, comments, or formatting. - Dont refactor things that arent broken. - Match existing style, even if youd do it differently. - If you notice unrelated dead code, mention it - dont delete it. When your changes create orphans: - Remove imports/variables/functions that YOUR changes made unused. - Dont remove pre-existing dead code unless asked. The test: Every changed line should trace directly to the users 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. --- **These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.如果使用项目 README 中的方式也可以通过命令下载CLAUDE.md。新项目curl -o CLAUDE.md https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md已有项目追加echo CLAUDE.md curl https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md CLAUDE.md项目 README 中也提供了 Claude Code 插件安装方式/plugin marketplace add forrestchang/andrej-karpathy-skills /plugin install andrej-karpathy-skillskarpathy-skills这些命令来自项目 README 的安装说明。4.3 Cursor 对应内容karpathy-guidelines.mdc如果你使用 Cursor推荐在项目中创建目录.cursor/rules/然后新建文件karpathy-guidelines.mdcCursor 版本比AGENTS.md / CLAUDE.md多了一段.mdc元信息核心正文仍然是同样的四条规则。--- description: 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. alwaysApply: true --- # Karpathy behavioral guidelines 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 **Dont assume. Dont hide confusion. Surface tradeoffs.** Before implementing: - State your assumptions explicitly. If uncertain, ask. - If multiple interpretations exist, present them - dont pick silently. - If a simpler approach exists, say so. Push back when warranted. - If something is unclear, stop. Name whats 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 wasnt 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: - Dont improve adjacent code, comments, or formatting. - Dont refactor things that arent broken. - Match existing style, even if youd do it differently. - If you notice unrelated dead code, mention it - dont delete it. When your changes create orphans: - Remove imports/variables/functions that YOUR changes made unused. - Dont remove pre-existing dead code unless asked. The test: Every changed line should trace directly to the users 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. --- **These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.Cursor 项目结构可以这样放my_project/ ├── .cursor/ │ └── rules/ │ └── karpathy-guidelines.mdc ├── src/ ├── package.json └── README.md4.4 三种文件内容对比三种文件可以这样理解工具文件内容是否一样主要区别CodexAGENTS.md核心一样Codex 推荐的项目指令文件Claude CodeCLAUDE.md核心一样Claude Code 的项目记忆文件Cursor.cursor/rules/karpathy-guidelines.mdc核心一样多了.mdc元信息和alwaysApply: true所以严格来说规则思想一样正文核心一样文件格式不同。五、使用建议与总结5.1 建议一不要只放通用规则还要加项目规则通用规则只能约束 AI 的行为习惯但真正做工程时还需要加入你的项目特定要求。例如 ROS2 项目可以补充## Project-Specific Guidelines - 使用 ROS2 Humble 风格编写代码。 - 不要随意修改 package.xml 和 CMakeLists.txt除非任务明确要求。 - 节点名、话题名、消息类型必须和现有工程保持一致。 - 修改代码后至少说明应该使用哪些 ros2 命令验证。C 项目可以补充## Project-Specific Guidelines - 使用 C17。 - 不要随意改变已有函数接口。 - 优先保持原项目代码风格。 - 修改后检查是否引入未使用头文件。这样 AI 不仅知道“不要乱改”还知道“这个项目具体不能乱改哪里”。5.2 建议二Codex、Claude Code、Cursor 可以同步维护如果你同时使用三个工具建议保持这三个文件同步AGENTS.md CLAUDE.md .cursor/rules/karpathy-guidelines.mdc每次修改规则时三个地方都同步更新。项目自己的CURSOR.md也提醒贡献者如果修改四条原则需要让CLAUDE.md、.cursor/rules/karpathy-guidelines.mdc和 Skill 内容保持同步PR #164 中也进一步提到要让CLAUDE.md、AGENTS.md、Cursor 规则和 Skill 文件保持同步。5.3 建议三不要期待规则 100% 强制执行这类规则本质上是给 AI 的行为指导不是编译器规则也不是强制约束。它能显著降低 AI 乱改代码、过度设计、没问清楚就动手的概率但不代表 AI 永远不会犯错。所以正确使用方式应该是规则文件负责约束 AI 人负责审查关键逻辑 测试负责验证最终结果。尤其是涉及机器人控制、自动驾驶、硬件驱动、金融交易、生产环境代码时一定不要完全依赖 AI 直接提交。六、总结andrej-karpathy-skills这个项目真正有价值的地方不是代码量而是它把 AI 编程中最容易出问题的地方总结成了四条非常清晰的工程纪律先思考再编码保持简单不要过度设计精准修改不乱碰无关代码定义目标改完必须验证。对于 Codex 来说它对应的是AGENTS.md对于 Claude Code 来说它对应的是CLAUDE.md对于 Cursor 来说它对应的是.cursor/rules/karpathy-guidelines.mdc三者内容核心一样区别只是不同工具读取规则的入口不同。如果你正在用 Codex、Claude Code、Cursor 做 C、ROS2、机器人、算法工程或者论文代码这套规则非常值得放进项目里。它不能保证 AI 永远不犯错但可以让 AI 少一点“自作主张”多一点“工程边界感”。