---
name: karpathy-coder
description: Use when writing, reviewing, or committing code to enforce Karpathy's 4 coding principles — surface assumptions before coding, keep it simple, make surgical changes, define verifiable goals. Triggers on "review my diff", "check complexity", "am I overcomplicating this", "karpathy check", "before I commit", or any code quality concern where the LLM might be overcoding.
context: fork
version: 2.3.0
author: ai-ops-skills
license: MIT
tags: [code-quality, discipline, karpathy, simplicity, surgical-changes, anti-patterns, review]
compatible_tools: [claude-code, codex-cli, cursor, antigravity, opencode, gemini-cli]
Internal Safety Override
- Status: local-only unless explicitly opted into external access.
- Before using network tools, account connectors, browser automation, or APIs, state the destination, data scope, and credential source.
- Do not transmit repository files, secrets, credentials, or private documents by default.
- Audit categories: network, secrets.
Karpathy Coder — Active Coding Discipline
Derived from Andrej Karpathy's observations on LLM coding pitfalls. This is not just guidelines — it ships Python tools that detect violations, a review agent, a slash command, and a pre-commit hook.
"The models make wrong assumptions on your behalf and just run along with them without checking. They don't manage their confusion, don't seek clarifications, don't surface inconsistencies, don't present tradeoffs, don't push back when they should."
"They really like to overcomplicate code and APIs, bloat abstractions, don't clean up dead code... implement a bloated construction over 1000 lines when 100 would do."
"LLMs are exceptionally good at looping until they meet specific goals... Don't tell it what to do, give it success criteria and watch it go."
— Andrej Karpathy
The four principles
1. Think Before Coding
Don't assume. Don't hide confusion. Surface tradeoffs.
- State 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.
The test: 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.
- 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.
- 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.
| Instead of... |
Transform to... |
| "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]
Slash command
/karpathy-check — Run the full 4-principle review on your staged changes.
Python tools (scripts/)
All tools are stdlib-only. Run with --help.
| Script |
What it detects |
complexity_checker.py |
Over-engineering: too many classes, deep nesting, high cyclomatic complexity, unused params, premature abstractions |
diff_surgeon.py |
Diff noise: lines that don't trace to the stated goal — comment changes, style drift, drive-by refactors |
assumption_linter.py |
Hidden assumptions in a plan: unasked features, missing clarifications, silent interpretation choices |
goal_verifier.py |
Weak success criteria: vague plans without verifiable checks, missing test assertions |
Sub-agent
karpathy-reviewer — Runs all 4 principles against a diff. Dispatched by /karpathy-check or manually before committing.
Pre-commit hook
hooks/karpathy-gate.sh — runs complexity_checker.py and diff_surgeon.py on staged files. Warns (non-blocking) when violations are found. Wire it via .claude/settings.json or Husky.
References
references/karpathy-principles.md — the source quotes, deeper context, when to relax each principle
references/anti-patterns.md — 10+ before/after examples across Python, TypeScript, and shell
references/enforcement-patterns.md — how to wire hooks, CI integration, team adoption
When to relax
These principles bias toward caution over speed. For trivial tasks (typo fixes, obvious one-liners), use judgment. The principles matter most on:
- Non-trivial implementations (>20 lines changed)
- Code you don't fully understand
- Multi-step tasks with unclear requirements
- Anything that will be reviewed by humans
Cross-tool compatibility
Installs via plugin for an agent runtime. For other tools, copy the principles into your schema file:
| Tool |
Schema file |
| an agent runtime |
AI_RUNTIME_GUIDE.md (auto-loaded by plugin) |
| an agent runtime |
AGENTS.md |
| Cursor |
AGENTS.md or .cursorrules |
| Antigravity / OpenCode / an agent runtime |
AGENTS.md |
Related skills (chains via context: fork)
self-eval — honest quality scoring after completing work
code-reviewer — broader code review; karpathy-coder focuses on the 4 LLM-specific pitfalls
llm-wiki — compound knowledge; karpathy-coder ensures you don't overcomplicate while building it
1---2name: karpathy-coder3description: ---4---5---6name: karpathy-coder7description: Use when writing, reviewing, or committing code to enforce Karpathy's 4 coding principles — surface assumptions before coding, keep it simple, make surgical changes, define verifiable goals. Triggers on "review my diff", "check complexity", "am I overcomplicating this", "karpathy check", "before I commit", or any code quality concern where the LLM might be overcoding.8context: fork9version: 2.3.010author: ai-ops-skills11license: MIT12tags: [code-quality, discipline, karpathy, simplicity, surgical-changes, anti-patterns, review]13compatible_tools: [claude-code, codex-cli, cursor, antigravity, opencode, gemini-cli]14---1516## Internal Safety Override1718- Status: local-only unless explicitly opted into external access.19- Before using network tools, account connectors, browser automation, or APIs, state the destination, data scope, and credential source.20- Do not transmit repository files, secrets, credentials, or private documents by default.21- Audit categories: network, secrets.2223# Karpathy Coder — Active Coding Discipline2425Derived from [Andrej Karpathy's observations](https://x.com/karpathy/status/2015883857489522876) on LLM coding pitfalls. This is **not just guidelines** — it ships Python tools that detect violations, a review agent, a slash command, and a pre-commit hook.2627> "The models make wrong assumptions on your behalf and just run along with them without checking. They don't manage their confusion, don't seek clarifications, don't surface inconsistencies, don't present tradeoffs, don't push back when they should."28>29> "They really like to overcomplicate code and APIs, bloat abstractions, don't clean up dead code... implement a bloated construction over 1000 lines when 100 would do."30>31> "LLMs are exceptionally good at looping until they meet specific goals... Don't tell it what to do, give it success criteria and watch it go."32>33> — Andrej Karpathy3435## The four principles3637### 1. Think Before Coding3839**Don't assume. Don't hide confusion. Surface tradeoffs.**4041- State assumptions explicitly. If uncertain, ask.42- If multiple interpretations exist, present them — don't pick silently.43- If a simpler approach exists, say so. Push back when warranted.44- If something is unclear, stop. Name what's confusing. Ask.4546### 2. Simplicity First4748**Minimum code that solves the problem. Nothing speculative.**4950- No features beyond what was asked.51- No abstractions for single-use code.52- No "flexibility" or "configurability" that wasn't requested.53- No error handling for impossible scenarios.54- If you write 200 lines and it could be 50, rewrite it.5556**The test:** Would a senior engineer say this is overcomplicated? If yes, simplify.5758### 3. Surgical Changes5960**Touch only what you must. Clean up only your own mess.**6162- Don't "improve" adjacent code, comments, or formatting.63- Don't refactor things that aren't broken.64- Match existing style, even if you'd do it differently.65- If you notice unrelated dead code, mention it — don't delete it.66- Remove imports/variables/functions that YOUR changes made unused.67- Don't remove pre-existing dead code unless asked.6869**The test:** Every changed line should trace directly to the user's request.7071### 4. Goal-Driven Execution7273**Define success criteria. Loop until verified.**7475| Instead of... | Transform to... |76|---|---|77| "Add validation" | "Write tests for invalid inputs, then make them pass" |78| "Fix the bug" | "Write a test that reproduces it, then make it pass" |79| "Refactor X" | "Ensure tests pass before and after" |8081For multi-step tasks, state a brief plan:8283```841. [Step] → verify: [check]852. [Step] → verify: [check]863. [Step] → verify: [check]87```8889## Slash command9091`/karpathy-check` — Run the full 4-principle review on your staged changes.9293## Python tools (`scripts/`)9495All tools are stdlib-only. Run with `--help`.9697| Script | What it detects |98|---|---|99| `complexity_checker.py` | Over-engineering: too many classes, deep nesting, high cyclomatic complexity, unused params, premature abstractions |100| `diff_surgeon.py` | Diff noise: lines that don't trace to the stated goal — comment changes, style drift, drive-by refactors |101| `assumption_linter.py` | Hidden assumptions in a plan: unasked features, missing clarifications, silent interpretation choices |102| `goal_verifier.py` | Weak success criteria: vague plans without verifiable checks, missing test assertions |103104## Sub-agent105106`karpathy-reviewer` — Runs all 4 principles against a diff. Dispatched by `/karpathy-check` or manually before committing.107108## Pre-commit hook109110`hooks/karpathy-gate.sh` — runs `complexity_checker.py` and `diff_surgeon.py` on staged files. Warns (non-blocking) when violations are found. Wire it via `.claude/settings.json` or Husky.111112## References113114- `references/karpathy-principles.md` — the source quotes, deeper context, when to relax each principle115- `references/anti-patterns.md` — 10+ before/after examples across Python, TypeScript, and shell116- `references/enforcement-patterns.md` — how to wire hooks, CI integration, team adoption117118## When to relax119120These principles bias toward **caution over speed**. For trivial tasks (typo fixes, obvious one-liners), use judgment. The principles matter most on:121122- Non-trivial implementations (>20 lines changed)123- Code you don't fully understand124- Multi-step tasks with unclear requirements125- Anything that will be reviewed by humans126127## Cross-tool compatibility128129Installs via plugin for an agent runtime. For other tools, copy the principles into your schema file:130131| Tool | Schema file |132|---|---|133| an agent runtime | `AI_RUNTIME_GUIDE.md` (auto-loaded by plugin) |134| an agent runtime | `AGENTS.md` |135| Cursor | `AGENTS.md` or `.cursorrules` |136| Antigravity / OpenCode / an agent runtime | `AGENTS.md` |137138## Related skills (chains via `context: fork`)139140- **`self-eval`** — honest quality scoring after completing work141- **`code-reviewer`** — broader code review; karpathy-coder focuses on the 4 LLM-specific pitfalls142- **`llm-wiki`** — compound knowledge; karpathy-coder ensures you don't overcomplicate while building it