Files
tool-notes/andrej-karpathy-skills-notes.md
2026-04-19 10:04:31 +08:00

108 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Andrej Karpathy Skills 安裝與使用筆記
## 基本資訊
- **專案**: https://github.com/forrestchang/andrej-karpathy-skills
- **作者**: Forrest Changforrestchang
- **授權**: MIT
- **類型**: Claude Code 外掛plugin/skill 可貼到 CLAUDE.md 的規則集
- **靈感來源**: [Andrej Karpathy 對 LLM coding 缺陷的觀察](https://x.com/karpathy/status/2015883857489522876)
- **安裝日期**: 2026-04-19
## 是什麼
一份讓 Claude Code以及 Cursor寫 code 時更「克制、精準、以目標為導向」的行為準則。核心觀點:**LLM 擅長為了達成目標而反覆迭代,所以把「目標」定義清楚,比教它怎麼寫 code 更重要。**
### 四大原則
1. **Think Before Coding先思考再動手**
- 明確說出假設;不確定就問
- 看到多種詮釋時攤開來,不要偷偷選
- 有更簡單的做法就直說,該推回時推回
2. **Simplicity First簡單優先**
- 只寫能解決問題的最小程式碼
- 不做沒要求的功能、抽象、彈性、錯誤處理
- 200 行能壓到 50 行就重寫
3. **Surgical Changes外科手術式修改**
- 只動必要的部分,別順手「改進」相鄰程式碼
- 不要 refactor 沒壞的東西;維持原有風格
- 每一行變更都要能對應到使用者的請求
4. **Goal-Driven Execution目標驅動執行**
- 把任務轉成可驗證的成功條件,例如:
- 「加驗證」→「寫失敗測試,讓它通過」
- 「修 bug」→「寫能重現 bug 的測試,讓它通過」
- 多步驟任務先列計畫,每步附 verify 檢查項
## 安裝方式
### 方法 AClaude Code Plugin推薦
在 Claude Code 對話中執行:
```text
/plugin marketplace add forrestchang/andrej-karpathy-skills
/plugin install andrej-karpathy-skills@karpathy-skills
/reload-plugins
```
### 方法 B直接放到專案 CLAUDE.md
```bash
# 新專案
curl -o CLAUDE.md https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md
# 既有 CLAUDE.md 附加
echo "" >> CLAUDE.md
curl https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md >> CLAUDE.md
```
### 方法 CCursor
專案 repo 內附 `.cursor/rules/karpathy-guidelines.mdc`,放進你的專案即可。詳見原 repo 的 `CURSOR.md`
## 與現有 karpathy-guidelines skill 的差異
本機 `~/.claude/skills/karpathy-guidelines/SKILL.md` 已存在一份同概念 skillAnthropic / 預設安裝),內容涵蓋完全相同的四大原則。
| 比較項 | 本機既有 skill | forrestchang plugin |
|--------|---------------|---------------------|
| 位置 | `~/.claude/skills/karpathy-guidelines/` | plugin marketplace |
| 格式 | 單檔 SKILL.md | plugin 套件 |
| 可更新 | 手動 | `/plugin update` |
| 內容 | 四原則 + trade-off 說明 | 四原則 + Cursor 支援 |
**實務建議**:兩者任擇其一即可,重複安裝會讓 skill 名稱衝突。
- 若只想在 Claude Code 使用並保持簡單:維持現有 skill。
- 若要跨 Cursor / 多機器同步並接受 plugin 更新機制:改裝 plugin 版本。
- 若要在特定專案強制執行:方法 B 把 CLAUDE.md 放進 repo團隊成員都會讀到。
## 成功指標(來自原作者)
- 不必要的 diff 變動變少
- 第一次嘗試就產出更簡潔的程式碼
- 實作前會先提釐清問題
- PR 更小、更聚焦
## 常用檢查
```bash
# 既有 skill
cat ~/.claude/skills/karpathy-guidelines/SKILL.md
# Plugin 安裝後
ls ~/.claude/plugins/marketplaces/ | grep -i karpathy
cat ~/.claude/plugins/known_marketplaces.json
# 在 Claude Code 查看 skill 列表
/skill list # 或直接輸入 / 查看建議
```
## 備註
- Karpathy 原推文提醒的幾個 LLM 缺陷:過度抽象、加非必要功能、改到不該改的地方、沒問就猜。這份 skill 就是針對這些的反制。
- 文件開頭已聲明 trade-off偏向「謹慎優先於速度」瑣碎任務自行拿捏。