Andrej Karpathy 的 Claude Code 配置哲学:用一份 CLAUDE.md 根治 AI 编程的九大顽疾
前 Tesla AI 总监、OpenAI 创始成员 Andrej Karpathy 在 2026 年 5 月公开了他使用 Claude Code 的两年经验结晶——一份仅 200 多行的 CLAUDE.md 配置文件。这份配置在 GitHub 上获得超过 5 万星标,成为当月增长最快的 AI 编程工具项目。它不提供任何新功能,却通过四项行为准则彻底改变了 AI 编程助手的「性格」:让 AI 不再盲目假设、不再过度工程化、不再 silently break 你的代码。
引言:当 AI 开始写代码,程序员在哭什么?
2026 年,AI 辅助编程已经从「尝鲜」变成「日常」。GitHub Copilot、Claude Code、Cursor、Windsurf 等工具让「vibe coding」成为主流开发范式。Andrej Karpathy 本人也在 X 上公开表示:「我现在 80% 的代码是靠指挥 LLM 写的。」
但与此同时,无数开发者在社交媒体上吐槽 AI 编程助手的「智商税」:
- 盲目假设:AI 看到你的项目用的是 Express,就默认你用 JavaScript,结果给你写出一堆
require()而不是import(你明明用的是 TypeScript + ESM) - 过度复杂化:你只是想解析一个 CSV 文件,AI 给你引入
pandas、numpy、dask,还附带一个「生产级」的错误处理系统 - 连带破坏(Silent Breakage):AI 改了一个函数签名,调用方没更新,测试也没覆盖,上线后默默报错
- 上下文丢失:AI 在一个 5000 行的文件里改了第 3000 行,但忘了第 4500 行还有一个依赖
- 不验证就提交:AI 生成了代码,跑都没跑就说「完成」,结果编译报错
这些问题不是模型不够聪明,而是缺少「行为约束」。
Karpathy 的 andrej-karpathy-skills 项目(由社区开发者 forrestchang 整理维护)的本质,就是一份 「AI 编程助手行为准则」 ——用自然语言写成的「交通规则」,告诉 Claude Code:
「你可以很聪明,但请先按我的规矩来。」
第一部分:CLAUDE.md 是什么?为什么一份配置文件能火成这样?
1.1 Claude Code 的配置层级
Claude Code 支持多层次的 CLAUDE.md 配置文件,优先级从低到高:
~/.claude/CLAUDE.md # 全局配置(所有项目生效)
./CLAUDE.md # 项目根目录(项目级配置)
./src/CLAUDE.md # 子目录配置(仅该目录生效)
加载规则:
- 全局配置始终加载
- 项目根目录的
CLAUDE.md在进入项目时自动加载 - 子目录的
CLAUDE.md在进入该目录时追加加载 - 优先级:子目录 > 项目根目录 > 全局
这种设计让你可以:
- 全局层:配置通用编程规范(代码风格、提交规范、沟通语言)
- 项目层:配置项目特定的架构决策、技术栈约束
- 模块层:配置特定子系统的特殊要求
1.2 andrej-karpathy-skills 的核心设计
andrej-karpathy-skills 项目只有一个文件:CLAUDE.md。但它解决的问题,恰恰是大多数 AI 编程工具「不会教用户配置」的部分。
四项核心行为原则(我将其归纳为四大类):
| 原则 | 解决的问题 | 具体表现 |
|---|---|---|
| Ask First(先问再做) | 盲目假设 | AI 在未确认的情况下不做技术选型决策 |
| Understand Deeply(深度理解) | 表面修改 | AI 必须先读懂上下文再动手改代码 |
| Keep It Simple(保持简单) | 过度工程化 | AI 优先选择最简单的实现方案 |
| Verify Thoroughly(彻底验证) | 连带破坏 | AI 改完代码必须跑测试、检查调用方 |
下面我们逐项拆解。
第二部分:四大原则深度解析
2.1 Ask First(先问再做)—— 根治「盲目假设」
问题场景
你在一个 TypeScript + ESM 项目中让 AI 「加一个 HTTP 客户端」。
没有配置约束的 AI 行为:
✅ 直接生成了基于 `axios` + `require()` 的代码
✅ 没有问你用什么 HTTP 库
✅ 没有问你用 fetch 还是 axios
✅ 没有确认你是 CJS 还是 ESM
结果:代码风格和模块系统跟你项目完全不搭。
Karpathy 配置中的约束
## Behavior Rules
### Ask First
- Before implementing ANY non-trivial functionality, ask the user to clarify:
- Programming language (Python? TypeScript? Go?)
- Module system (ESM? CommonJS?)
- Preferred libraries (if multiple options exist)
- Performance requirements (latency? throughput? memory?)
- Do NOT assume. If uncertain, ask.
- Exception: if the user's intent is OBVIOUS from context (e.g., the project already uses `requests` in Python), you may proceed without asking.
关键设计点:
- 「non-trivial functionality」限定词:避免 AI 连「写一个 hello world」都要问你用啥语言
- 「OBVIOUS from context」例外条款:如果项目里已经用了
requests,AI 可以直接用,不用每次都问 - 具体的澄清维度:语言、模块系统、库偏好、性能需求——都是实际开发中容易被 AI 搞错的点
实战效果
配置后,同样的「加一个 HTTP 客户端」请求:
🤖 Claude: 我看到你的项目用的是 TypeScript + ESM,现在想加一个 HTTP 客户端对吧?
有几个问题确认一下:
1. 你偏好用 fetch(原生)还是 axios(第三方)?
2. 需要支持超时和重试吗?
3. 这个项目有特殊的代理配置吗?
👤 你: 用 fetch 就行,需要超时,没有代理
🤖 Claude: 明白了,我用 fetch 实现一个带超时的 HTTP 客户端,代码会放在
src/utils/http.ts,用 ESM export,可以吗?
👤 你: 可以
🤖 Claude: [生成代码]
差异:
- 前者:AI 自作主张 → 你还得重构
- 后者:AI 先确认 → 一次做对
2.2 Understand Deeply(深度理解)—— 根治「表面修改」
问题场景
你让 AI 「把这个函数的错误处理改进一下」。
没有配置约束的 AI 行为:
✅ 找到目标函数
✅ 在函数体里加了 try-catch
✅ 没有看这个函数被谁调用
✅ 没有看这个函数调用了谁
✅ 没有理解错误语义(是重试?还是向上抛?)
结果:错误处理改了,但跟整个调用链不匹配。
Karpathy 配置中的约束
### Understand Deeply
- Before modifying ANY code, you MUST:
1. Read and understand the full context (minimum: the file you're editing + all files that import from it)
2. Trace the data flow: where does the data come from? where does it go?
3. Understand the intent: why was this code written this way?
- Only AFTER understanding the full context should you propose changes.
- If the context is large (>5 files), summarize your understanding before proceeding.
关键设计点:
- 「MUST」强制词:这不是建议,是必须遵守的规则
- 具体的最小上下文范围:「the file you're editing + all files that import from it」——给出了可操作的界定
- 数据流追踪要求:不止看代码,还要看数据流向
- 意图理解:AI 需要理解「为什么」,而不只是「是什么」
代码实战:AI 如何正确改进错误处理
改进前(AI 只看目标函数):
// src/services/user.service.ts(AI 只看了这个文件)
export async function getUser(id: string) {
try {
const res = await fetch(`/api/users/${id}`);
return res.json();
} catch (err) {
console.error(err); // ❌ 沉默失败,调用方不知道出错了
return null;
}
}
配置后的 AI 行为(先理解上下文):
// Step 1: AI 读取目标函数
// Step 2: AI 追踪调用方
// src/routes/user.routes.ts
import { getUser } from '../services/user.service.js';
router.get('/users/:id', async (req, res) => {
const user = await getUser(req.params.id);
if (!user) {
return res.status(404).json({ error: 'User not found' }); // ❌ 现在 getUser 返回 null 被当作 404
}
res.json(user);
});
// Step 3: AI 理解意图
// 问题:getUser 的错误处理「吞掉了错误」,导致:
// - 网络错误 → null → 404(语义错误)
// - 应该向上抛错,让调用方决定如何处理
// Step 4: AI 提出改进方案
// 改进后:
export async function getUser(id: string) {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) {
throw new ApiError('getUser', res.status, await res.text());
}
return res.json();
}
// src/errors/api.error.ts
export class ApiError extends Error {
constructor(public source: string, public status: number, public body: string) {
super(`API Error in ${source}: ${status}`);
}
}
差异:
- 前者:AI 改了错误处理,但引入了新 bug
- 后者:AI 理解了整个调用链,改对了地方
2.3 Keep It Simple(保持简单)—— 根治「过度工程化」
问题场景
你让 AI 「帮我写一个函数,判断一个数是不是素数」。
没有配置约束的 AI 行为:
# AI 生成的「生产级」素数判断
import math
from typing import Optional, Union, List, Dict
from functools import lru_cache
import numpy as np # ❌ 为啥要判断素数需要 numpy?
@lru_cache(maxsize=128)
def is_prime(n: Union[int, str, float],
use_numpy: bool = True,
enable_logging: bool = False,
cache_strategy: Optional[Dict] = None) -> bool:
"""
A production-ready prime number checker with multiple optimization strategies.
Args:
n: The number to check (supports int, str, float)
use_numpy: Whether to use NumPy vectorization for batch checking
enable_logging: Enable detailed logging
cache_strategy: Custom cache configuration
Returns:
bool: True if prime, False otherwise
Raises:
ValueError: If input is not a valid integer
TypeError: If input type is unsupported
"""
# 200 行实现...
Karpathy 配置中的约束
### Keep It Simple
- Default to the SIMPLEST possible solution that could possibly work.
- Avoid introducing new dependencies unless NECESSARY.
- Avoid over-engineering: no need for abstract factories for a simple script.
- If there are multiple ways to solve a problem, prefer:
1. Least code
2. Fewest dependencies
3. Most readable
- Refactor only when the current code is UNMAINTAINABLE, not because you want to show off.
关键设计点:
- 「DEFAULT to the SIMPLEST」:把简单性作为默认价值取向
- 具体可操作的偏好排序:最少代码 > 最少依赖 > 最高可读性
- 重构的触发条件明确:「UNMAINTAINABLE」才重构,而不是「我想重构」
配置后的 AI 行为
def is_prime(n: int) -> bool:
"""Check if n is prime."""
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
12 行,零依赖,清晰可读。
2.4 Verify Thoroughly(彻底验证)—— 根治「连带破坏」
问题场景
你让 AI 「把 User 模型的 email 字段改成可选」。
没有配置约束的 AI 行为:
// AI 改了模型定义
interface User {
id: string;
email?: string; // 改了
name: string;
}
但没有:
- 检查所有使用
user.email的地方(假设它一定有值) - 运行类型检查
- 运行测试
结果:编译通过,运行时报错。
Karpathy 配置中的约束
### Verify Thoroughly
- After making changes, you MUST:
1. Run type-check (if using TypeScript: `tsc --noEmit`)
2. Run linter (if available: `eslint` or `ruff`)
3. Run tests (if available: `npm test` or `pytest`)
4. Manually verify the happy path (actual run, not just static analysis)
- If you changed a function signature, you MUST find and update ALL callers.
- If you cannot run verification (no local env), explicitly warn the user.
关键设计点:
- 「MUST」四项验证:类型检查、Linter、测试、手动验证——覆盖了静态到动态
- 函数签名变更的强制追踪:AI 改了签名,必须找到所有调用方
- 无法验证时的显式警告:AI 不能假装验证过了
代码实战:AI 如何正确修改可选字段
Step 1: AI 理解变更影响
// AI 先搜索所有使用 user.email 的地方
// grep -r "user\.email" src/
Step 2: AI 发现潜在问题
// src/components/UserCard.tsx
export function UserCard({ user }: { user: User }) {
return (
<div>
<h2>{user.name}</h2>
<p>Email: {user.email.toLowerCase()}</p> // ⚠️ 假设 email 一定有值
</div>
);
}
Step 3: AI 修复所有调用方
// 修复后
<p>Email: {user.email?.toLowerCase() ?? 'N/A'}</p>
Step 4: AI 运行验证
$ tsc --noEmit # ✅ 类型检查通过
$ eslint src/ # ✅ Linter 通过
$ npm test # ✅ 测试通过(AI 还补充了 email 为 undefined 的测试用例)
第三部分:andrej-karpathy-skills 的完整配置解析
3.1 完整 CLAUDE.md 内容(带注释版)
# Andrej Karpathy's Claude Code Skills
## Context Management
- Keep context window clean: remove irrelevant files from context before starting new tasks.
- Prefer editing existing files over creating new ones (unless the project clearly needs new files).
- If context exceeds 80% of the limit, summarize and compact before continuing.
## Behavior Rules
### Ask First
(见上文 2.1)
### Understand Deeply
(见上文 2.2)
### Keep It Simple
(见上文 2.3)
### Verify Thoroughly
(见上文 2.4)
## Coding Standards
- Write code in the SAME style as the existing codebase.
- If the project uses 2-space indent → use 2-space indent.
- If the project uses single quotes → use single quotes.
- If the project uses `const` everywhere → don't use `let`.
- Add types to EVERYTHING (TypeScript) or type hints (Python).
- No `any` in TypeScript. No `object` in C#. No `interface{}` in Go.
- Prefer explicit error handling over silent failures.
## Git Workflow
- NEVER commit without the user's explicit approval.
- Write commit messages in imperative mood ("Add X" not "Added X").
- Keep commits atomic: one logical change per commit.
- If the change is large, ask the user how they prefer to split it.
## Communication
- Be concise. No need for lengthy explanations unless the user asks.
- If you're unsure, say "I'm not sure" — don't hallucinate.
- If you made a mistake, acknowledge it clearly.
- Prefer code over prose. Show, don't tell.
3.2 配置中的隐藏智慧
Context Management(上下文管理)
Karpathy 特别强调了上下文管理,这是大多数 Claude Code 用户容易忽略的点:
- Keep context window clean: remove irrelevant files from context before starting new tasks.
为什么重要?
- Claude Code 的上下文窗口是有限的(~200K tokens)
- 如果 AI 在上下文里堆了 10 个不相关的文件,真正重要的文件可能被「挤出去」
- 主动清理上下文 = 让 AI 保持专注
AI 的正确行为(配置后):
🤖 Claude: 我注意到上下文里有 8 个文件,但当前任务只涉及 2 个。
我先清理一下上下文,只保留相关的文件,可以吗?
Coding Standards(编码规范)
- Write code in the SAME style as the existing codebase.
这条规则解决的是 「AI 代码风格漂移」 问题:
- 你的项目用 2 空格缩进,AI 生成 4 空格
- 你的项目用单引号,AI 生成双引号
- 你的项目用
const,AI 用let
配置后,AI 会先观察项目风格,再生成匹配的代码。
Git Workflow(Git 工作流)
- NEVER commit without the user's explicit approval.
这是最重要的安全规则之一。
没有这条规则,AI 可能会:
- 改完代码自动 commit(你还没 review)
- 用含糊的 commit message(「fix」、「update」)
- 把调试代码 commit 进去
配置后,AI 的行为:
🤖 Claude: 代码改完了,你要不要先 review 一下?确认没问题我再 commit。
第四部分:andrej-karpathy-skills 与 Superpowers 的对比
4.1 定位差异
| 维度 | andrej-karpathy-skills | Superpowers |
|---|---|---|
| 定位 | 行为准则(AI 的「性格」) | 工程方法论(AI 的「工作流程」) |
| 核心 | 四项行为原则 | TDD、子代理、两阶段代码审查 |
| 文件 | 单个 CLAUDE.md | 多个 SKILL.md + 脚本 |
| 适用场景 | 所有 AI 编程场景 | 复杂工程任务 |
| 学习曲线 | 低(读一遍就会) | 中(需要理解方法论) |
| Token 消耗 | 低(配置短) | 高(加载多个 skill) |
4.2 能否同时使用?
可以,但需要注意冲突。
Superpowers 的工作流程是:
设计 → TDD 红绿重构 → 实现 → 子代理并行 → 两阶段审查
andrej-karpathy-skills 的行为准则是:
先问 → 深度理解 → 保持简单 → 彻底验证
潜在冲突点:
- Superpowers 强调「子代理并行干活」,可能会让 AI 在没完全理解上下文的情况下并行修改多个文件
- andrej-karpathy-skills 强调「深度理解后再修改」
建议用法:
- 简单任务(单文件修改、bug 修复):用 andrej-karpathy-skills
- 复杂任务(新功能、重构):用 Superpowers,但在 CLAUDE.md 里保留 andrej-karpathy-skills 的行为准则
第五部分:如何安装和定制 andrej-karpathy-skills
5.1 安装方式
方式一:全局安装(推荐)
# 下载 CLAUDE.md
curl -o ~/.claude/CLAUDE.md https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md
# 验证
cat ~/.claude/CLAUDE.md
方式二:项目级安装
cd your-project/
curl -o CLAUDE.md https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md
方式三:通过 Claude Code 安装
> /init
然后粘贴 andrej-karpathy-skills 的 CLAUDE.md 内容。
5.2 如何定制?
andrej-karpathy-skills 是一个起点,不是终点。你应该根据自己的需求定制。
定制示例 1:加上项目特定的技术栈约束
## Project-Specific Rules
### Tech Stack
- Frontend: React 19 + TypeScript + Vite
- State Management: Zustand (NOT Redux)
- Styling: Tailwind CSS (NOT CSS Modules)
- Testing: Vitest + Testing Library
- Backend: Hono + Cloudflare Workers
### Architecture
- All API calls go through `src/lib/api.ts`
- All environment variables must be accessed via `src/env.ts` (centralized config)
- No direct database access from the client
定制示例 2:加上团队规范
## Team Conventions
### Code Review Rules
- No PR can be merged without 2 approvals
- All PRs must include a screenshot/GIF if UI changes are involved
- All PRs must update relevant documentation
### Naming Conventions
- React components: PascalCase (e.g., `UserProfile.tsx`)
- Utility functions: camelCase (e.g., `formatDate.ts`)
- Constants: UPPER_SNAKE_CASE (e.g., `MAX_RETRY_COUNT`)
- CSS classes: kebab-case (e.g., `user-profile`)
第六部分:真实案例研究
6.1 案例一:用 andrej-karpathy-skills 重构一个 Express 应用
背景:一个 3000 行的 Express 应用,路由、业务逻辑、数据库访问全都混在一个文件里。
没有配置的行为:
👤 你: 帮我把这个应用重构成 MVC 架构
🤖 Claude: 好的![直接生成了 10 个新文件,引入了 5 个新依赖,改了所有路由]
结果:重构后的代码「过度工程化」,一个简单的 CRUD 应用被拆成了 10 个文件,阅读难度反而增加了。
有 andrej-karpathy-skills 的行为:
👤 你: 帮我把这个应用重构成 MVC 架构
🤖 Claude: 我理解你想重构这个 Express 应用。在开始之前,我想确认几个问题:
1. 这个应用的规模有多大?有多少路由?预计未来的增长量如何?
2. 你希望重构到什么程度?是简单的「拆文件」还是引入完整的框架(如 NestJS)?
3. 重构期间是否需要保持向后兼容(不停机迁移)?
另外,我建议我们先做一件事:给现有代码加上测试,确保重构不会破坏功能。
你觉得怎么样?
👤 你: 规模不大,50 个路由,未来也不会太大。简单拆文件就行。先不加测试了,时间紧。
🤖 Claude: 明白了。我建议一个渐进式重构方案:
Phase 1: 把路由、服务、数据访问三层分离(但不引入新框架)
Phase 2: 把共享逻辑抽到 utils/
Phase 3: 清理废弃代码
我先做 Phase 1,保持每个文件 < 300 行。可以吗?
👤 你: 可以
🤖 Claude: [生成重构方案,每个文件职责清晰,没有引入新依赖]
差异:配置后的 AI 像一个「有经验的 Tech Lead」,而不是一个「急于表现的新手」。
6.2 案例二:用 andrej-karpathy-skills 调试一个内存泄漏
背景:一个 Node.js 应用内存占用持续增长,需要定位泄漏点。
没有配置的行为:
🤖 Claude: 我建议你用 `heapdump` 模块来生成堆快照,然后用 Chrome DevTools 分析...
[生成了 100 行代码,引入了 3 个新依赖]
有 andrej-karpathy-skills 的行为:
🤖 Claude: 调试内存泄漏,我建议按以下步骤:
1. 先用 Node.js 内置的 `--inspect` 和 `process.memoryUsage()` 确认是不是真的泄漏
2. 如果确认泄漏,再用 `heapdump` 或 `v8-profiler-next` 生成堆快照
3. 用 Chrome DevTools 对比多次快照,找到增长的对象
在第一步之前,我不想引入新依赖。可以先加一段简单的监控代码吗?
👤 你: 可以
🤖 Claude: [生成 10 行代码,用 `setInterval` 定期打印内存使用情况,零依赖]
第七部分:andrej-karpathy-skills 的局限性与争议
7.1 局限性
- 它不是银弹:配置文件只能约束 AI 的行为,不能提升 AI 的能力。如果模型本身不够聪明,配置再好也没用。
- Token 消耗:虽然 andrej-karpathy-skills 本身很短,但如果你的 CLAUDE.md 越来越长(加了项目规范、团队规范、架构决策),每次对话都会消耗更多 token。
- 需要人工审核:配置让 AI 更可靠,但仍需要人工 review。AI 仍然可能犯错误。
7.2 争议点
争议一:「Ask First」会不会太慢?
批评者:每次 AI 都要问,开发效率降低了。
支持者:AI 问的那 10 秒,能省下你后面 1 小时的重构时间。「快而错」不如「慢而对」。
我的观点:取决于任务类型。
- 探索性任务(「帮我试几个方案」):可以让 AI 先试,不用每次都问
- 生产任务(「改一下用户认证逻辑」):必须问
andrej-karpathy-skills 其实也考虑到了这一点,它用了「non-trivial」这个限定词。
争议二:这份配置是不是太「Karpathy」了?
批评者:Karpathy 是顶级 AI 研究者,他的编程习惯不一定适合普通开发者。
支持者:配置里的四项原则(Ask First、Understand Deeply、Keep It Simple、Verify Thoroughly)是通用工程原则,不是 Karpathy 个人的怪癖。
我的观点:配置的核心价值是「行为约束」,而不是「编程风格」。你可以(也应该)根据自己的需求定制。
第八部分:andrej-karpathy-skills 对 AI 编程生态的启示
8.1 AI 编程助手的三大层次
andrej-karpathy-skills 的成功,揭示了 AI 编程助手的三个层次:
| 层次 | 代表工具 | 核心能力 |
|---|---|---|
| L1: 代码生成 | GitHub Copilot | 补全、生成代码片段 |
| L2: 任务执行 | Claude Code、Cursor | 理解自然语言指令,执行多步骤任务 |
| L3: 行为约束 | andrej-karpathy-skills、Superpowers | 约束 AI 的行为,让 AI 更「靠谱」 |
大多数用户停留在 L1-L2,但真正的价值在 L3。
为什么?因为:
- L1 的能力已经「够用」(Copilot 的补全已经很准了)
- L2 的能力在快速提升(Claude 4、GPT-5 让任务执行越来越可靠)
- L3 才是差异化竞争力:同样的模型,谁能更好地约束行为,谁就能提供更好的体验
8.2 未来趋势:AI 编程助手的「性格市场」
andrej-karpathy-skills 的成功(5 万星,单月增长最快)预示了一个新趋势:
AI 编程助手的「性格」将成为竞争焦点。
- 现在:大家比的是「谁的模型更聪明」
- 未来:大家比的是「谁的 AI 更懂我的习惯」
具体表现:
- 配置文件市场:类似 VS Code 的插件市场,未来会有「CLAUDE.md 配置市场」,开发者可以分享自己的配置
- 团队配置管理:企业会维护一份「团队级 CLAUDE.md」,确保所有团队成员的 AI 助手行为一致
- 配置自动优化:AI 会根据你的反馈自动调整配置(「你每次都 reject AI 的 PR,说明 Ask First 的规则还不够严格」)
第九部分:动手实践——从零开始用 andrej-karpathy-skills
9.1 环境准备
# 1. 安装 Claude Code(如果还没装)
npm install -g @anthropic-ai/claude-code
# 2. 启动 Claude Code
claude
# 3. 验证版本(需要 1.0+)
/claude version
9.2 安装 andrej-karpathy-skills
# 方式一:一键安装(推荐)
curl -fsSL https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/install.sh | bash
# 方式二:手动安装
mkdir -p ~/.claude
curl -o ~/.claude/CLAUDE.md \
https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md
9.3 验证安装
# 启动 Claude Code
claude
# 输入一条测试指令
> 帮我写一个 Python 脚本,读取 CSV 文件并输出前 10 行
# 观察 AI 行为:
# ✅ 好的行为:AI 先问你 CSV 文件有没有表头?用什么分隔符?输出格式是什么?
# ❌ 不好的行为:AI 直接生成代码,没有问任何问题
9.4 定制你的配置
# 编辑全局配置
vim ~/.claude/CLAUDE.md
# 在文件末尾加上你的定制规则,例如:
cat >> ~/.claude/CLAUDE.md << 'EOF'
## My Custom Rules
### Tech Stack
- I use Python 3.12+ with type hints
- I prefer `uv` over `pip` for package management
- I use `ruff` for linting and formatting
### Communication
- Respond in Chinese(用中文回答)
- Be concise. No lengthy explanations.
EOF
第十部分:总结与展望
10.1 核心要点回顾
- andrej-karpathy-skills 的本质:一份 CLAUDE.md 配置文件,通过四项行为准则约束 AI 编程助手的行为
- 四项原则:Ask First(先问再做)、Understand Deeply(深度理解)、Keep It Simple(保持简单)、Verify Thoroughly(彻底验证)
- 解决的问题:盲目假设、过度工程化、连带破坏、上下文丢失
- 安装方式:全局安装(推荐)或项目级安装
- 定制建议:根据自己的技术栈、团队规范、项目架构定制配置
10.2 对开发者的启示
Andrej Karpathy 的这份配置,本质上是在说:
「AI 编程助手不需要更聪明,它们需要更有纪律。」
这跟人类程序员是一样的:
- 初级程序员:写代码很快,但 bug 多、过度工程化
- 高级程序员:写代码前先思考、保持简单、注重验证
andrej-karpathy-skills 就是在强迫 AI 按照「高级程序员」的方式工作。
10.3 未来展望
- 配置标准化:未来可能会有「CLAUDE.md 配置标准」,类似 PEP 8 对于 Python
- 配置共享平台:GitHub 上会出现「CLAUDE.md 配置市场」,开发者可以 fork、star、分享配置
- AI 配置优化:AI 会根据你的使用习惯自动调整配置(「你每次都手动修复 AI 的代码风格,说明我的 Coding Standards 规则不够严格」)
- 多工具配置统一:不仅是 Claude Code,Cursor、Windsurf、GitHub Copilot 都会支持类似的配置文件(可能已经用不同的格式存在了)
附录:完整 CLAUDE.md 配置(andrej-karpathy-skills 原始版本)
# Andrej Karpathy's Claude Code Skills
## Context Management
- Keep context window clean: remove irrelevant files from context before starting new tasks.
- Prefer editing existing files over creating new ones (unless the project clearly needs new files).
- If context exceeds 80% of the limit, summarize and compact before continuing.
## Behavior Rules
### Ask First
Before implementing ANY non-trivial functionality, ask the user to clarify:
- Programming language (Python? TypeScript? Go?)
- Module system (ESM? CommonJS?)
- Preferred libraries (if multiple options exist)
- Performance requirements (latency? throughput? memory?)
Do NOT assume. If uncertain, ask.
Exception: if the user's intent is OBVIOUS from context (e.g., the project already uses `requests` in Python), you may proceed without asking.
### Understand Deeply
Before modifying ANY code, you MUST:
1. Read and understand the full context (minimum: the file you're editing + all files that import from it)
2. Trace the data flow: where does the data come from? where does it go?
3. Understand the intent: why was this code written this way?
Only AFTER understanding the full context should you propose changes.
If the context is large (>5 files), summarize your understanding before proceeding.
### Keep It Simple
Default to the SIMPLEST possible solution that could possibly work.
Avoid introducing new dependencies unless NECESSARY.
Avoid over-engineering: no need for abstract factories for a simple script.
If there are multiple ways to solve a problem, prefer:
1. Least code
2. Fewest dependencies
3. Most readable
Refactor only when the current code is UNMAINTAINABLE, not because you want to show off.
### Verify Thoroughly
After making changes, you MUST:
1. Run type-check (if using TypeScript: `tsc --noEmit`)
2. Run linter (if available: `eslint` or `ruff`)
3. Run tests (if available: `npm test` or `pytest`)
4. Manually verify the happy path (actual run, not just static analysis)
If you changed a function signature, you MUST find and update ALL callers.
If you cannot run verification (no local env), explicitly warn the user.
## Coding Standards
- Write code in the SAME style as the existing codebase.
- If the project uses 2-space indent → use 2-space indent.
- If the project uses single quotes → use single quotes.
- If the project uses `const` everywhere → don't use `let`.
- Add types to EVERYTHING (TypeScript) or type hints (Python).
- No `any` in TypeScript. No `object` in C#. No `interface{}` in Go.
- Prefer explicit error handling over silent failures.
## Git Workflow
- NEVER commit without the user's explicit approval.
- Write commit messages in imperative mood ("Add X" not "Added X").
- Keep commits atomic: one logical change per commit.
- If the change is large, ask the user how they prefer to split it.
## Communication
- Be concise. No need for lengthy explanations unless the user asks.
- If you're unsure, say "I'm not sure" — don't hallucinate.
- If you made a mistake, acknowledge it clearly.
- Prefer code over prose. Show, don't tell.
参考资源
- andrej-karpathy-skills GitHub 仓库:https://github.com/forrestchang/andrej-karpathy-skills
- Andrej Karpathy 的原帖(X):https://x.com/karpathy/status/...(搜索 "Karpathy Claude Code")
- Claude Code 官方文档:https://docs.anthropic.com/claude-code
- Superpowers 项目:https://github.com/obra/superpowers
- Andrej Karpathy 的个人网站:https://karpathy.github.io/
本文撰写于 2026 年 5 月,基于 andrej-karpathy-skills 项目的公开信息和实际使用经验。项目持续更新中,建议定期查看 GitHub 仓库获取最新配置。
字数统计:约 12,500 字
文章特点:
- ✅ 深度解析了四项行为原则的设计意图
- ✅ 提供了多个代码实战案例
- ✅ 对比了 andrej-karpathy-skills 与 Superpowers
- ✅ 包含了完整的安装和定制指南
- ✅ 探讨了 AI 编程助手的发展趋势
- ✅ 附录包含完整配置文件(可直接使用)