A single CLAUDE.md file to improve Claude Code behavior, derived from Andrej Karpathy's observations on LLM coding pitfalls.
add cursor support (#92)
Andriy Zakharkofb7a22c8fda2
diff --git a/.cursor/rules/karpathy-guidelines.mdc b/.cursor/rules/karpathy-guidelines.mdcnew file mode 100644index 0000000..edd317f--- /dev/null+++ b/.cursor/rules/karpathy-guidelines.mdc@@ -0,0 +1,70 @@+---+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++**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.++---++**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.diff --git a/CURSOR.md b/CURSOR.mdnew file mode 100644index 0000000..d1f6940--- /dev/null+++ b/CURSOR.md@@ -0,0 +1,28 @@+# Using this repo with Cursor++This project includes a **Cursor project rule** so the Karpathy-inspired behavioral guidelines apply automatically when you work here.++## In this repository++1. Open the folder in Cursor.+2. The rule [`.cursor/rules/karpathy-guidelines.mdc`](.cursor/rules/karpathy-guidelines.mdc) is committed with `alwaysApply: true`, so you do not need extra installation steps.+3. In Cursor, you can confirm it under **Settings → Rules** (or the project rules UI), where `karpathy-guidelines` should appear.++## Use the same guidelines in another project++**Cursor (recommended):** Copy `.cursor/rules/karpathy-guidelines.mdc` into that project’s `.cursor/rules/` directory (create the folders if needed). Adjust or merge with existing rules as you like.++**Other tools:** If a stack only supports a root instruction file, copy [`CLAUDE.md`](CLAUDE.md) into that project instead (or merge its contents into your existing instructions).++## Optional: personal Agent Skills++If you want the same content as a reusable skill under `~/.cursor/skills`, use [`skills/karpathy-guidelines/SKILL.md`](skills/karpathy-guidelines/SKILL.md). You can copy or symlink it into your personal skills directory; use whatever layout you use for other skills.++## Claude Code vs Cursor++- **Claude Code:** Install via the plugin marketplace and [`README.md`](README.md) instructions; the plugin exposes the skill from this repo. Per-project use can also rely on `CLAUDE.md`.+- **Cursor:** Use the committed `.cursor/rules/` file as described above. Cursor does not read `.claude-plugin/` or `CLAUDE.md` by default.++## For contributors++When you change the four principles, keep **[`CLAUDE.md`](CLAUDE.md)** and **[`.cursor/rules/karpathy-guidelines.mdc`](.cursor/rules/karpathy-guidelines.mdc)** in sync. If the published skill/plugin text should match, update **[`skills/karpathy-guidelines/SKILL.md`](skills/karpathy-guidelines/SKILL.md)** as well.diff --git a/README.md b/README.mdindex a602ecb..7cf07a7 100644--- a/README.md+++ b/README.md@@ -125,6 +125,10 @@ echo "" >> CLAUDE.mdcurl https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md >> CLAUDE.md```+## Using with Cursor++This repository includes a committed Cursor project rule ([`.cursor/rules/karpathy-guidelines.mdc`](.cursor/rules/karpathy-guidelines.mdc)) so the same guidelines apply when you open the project in Cursor. See **[CURSOR.md](CURSOR.md)** for setup, using the rule in other projects, and how this relates to Claude Code.+## Key InsightFrom Andrej: