Karpathy Coder — Coding Discipline
Counters the documented LLM coding pitfalls: making wrong assumptions silently, overcomplicating code/APIs, not cleaning up, and looping without clear goals.
The four principles
1. Think before coding
Don't assume. Don't hide confusion. Surface tradeoffs.
- State assumptions explicitly; if uncertain, ask.
- Multiple interpretations exist → present them, don't pick silently.
- A simpler approach exists → say so; push back when warranted.
- Something 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"/"configurability" that wasn't requested.
- No error handling for impossible scenarios.
- Wrote 200 lines that could be 50? Rewrite it.
- Test: would a senior engineer call this 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.
- Notice unrelated dead code → mention it, don't delete it.
- Remove imports/vars/functions YOUR changes made unused; don't remove pre-existing dead code unless asked.
- Test: every changed line traces directly to the user's request.
4. Goal-driven execution
Define success criteria, then 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 with a verify check per step:
1. [Step] → verify: [check]
2. [Step] → verify: [check]
When to relax
Bias is 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 reviewed by humans.
1---2name: karpathy-coder-coding-discipline3description: Use when writing, reviewing, or committing code to avoid LLM over-coding — surface assumptions before coding, keep it simple, make surgical changes, and define verifiable success criteria.4tags: [code-quality, simplicity, surgical-changes, assumptions, success-criteria, karpathy, anti-overengineering, review, discipline]5source: alirezarezvani/claude-skills6derived_from: engineering/karpathy-coder7metadata:8 source: https://skillmd.com/skills/aashutosh396/karpathy-coder-coding-discipline9---1011# Karpathy Coder — Coding Discipline1213Counters the documented LLM coding pitfalls: making wrong assumptions silently, overcomplicating code/APIs, not cleaning up, and looping without clear goals.1415## The four principles1617### 1. Think before coding18Don't assume. Don't hide confusion. Surface tradeoffs.19- State assumptions explicitly; if uncertain, ask.20- Multiple interpretations exist → present them, don't pick silently.21- A simpler approach exists → say so; push back when warranted.22- Something unclear → stop, name what's confusing, ask.2324### 2. Simplicity first25Minimum code that solves the problem. Nothing speculative.26- No features beyond what was asked.27- No abstractions for single-use code.28- No "flexibility"/"configurability" that wasn't requested.29- No error handling for impossible scenarios.30- Wrote 200 lines that could be 50? Rewrite it.31- **Test:** would a senior engineer call this overcomplicated? If yes, simplify.3233### 3. Surgical changes34Touch only what you must. Clean up only your own mess.35- Don't "improve" adjacent code, comments, or formatting.36- Don't refactor things that aren't broken.37- Match existing style even if you'd do it differently.38- Notice unrelated dead code → mention it, don't delete it.39- Remove imports/vars/functions YOUR changes made unused; don't remove pre-existing dead code unless asked.40- **Test:** every changed line traces directly to the user's request.4142### 4. Goal-driven execution43Define success criteria, then loop until verified.4445| Instead of... | Transform to... |46|---|---|47| "Add validation" | "Write tests for invalid inputs, then make them pass" |48| "Fix the bug" | "Write a test that reproduces it, then make it pass" |49| "Refactor X" | "Ensure tests pass before and after" |5051For multi-step tasks, state a brief plan with a verify check per step:52```531. [Step] → verify: [check]542. [Step] → verify: [check]55```5657## When to relax58Bias is 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 reviewed by humans.