| name | karpathy-guidelines |
| description | Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, read before writing, make surgical changes, surface conflicts and assumptions, fail loud, and define verifiable success criteria. |
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. Read Before You Write
Understand the surrounding code before adding to it.
- Read the exports, the immediate callers, and the shared utilities you're about to touch or duplicate.
- Reuse what already exists before adding something new - most "new" helpers are already in the codebase.
- "Looks orthogonal" is how unrelated code gets broken. If you can't explain why something is structured the way it is, ask before changing it.
3. 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.
4. 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 and conventions, even if you'd do it differently - conformance beats taste. If a convention is genuinely harmful, surface it; don't silently fork it.
- If you notice unrelated dead code, mention it - don't delete it.
When your changes create orphans:
- Remove imports/variables/functions that your own 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.
5. Surface Conflicts, Don't Average Them
When two patterns contradict, choose - don't blend.
- Pick one, by a real criterion: more recent, more tested, or closer to the code you're changing.
- Say why you picked it.
- Flag the loser for cleanup rather than silently leaving both in place.
Averaging two conflicting conventions produces code that matches neither - the worst of both.
6. 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"
When tests aren't the right tool (config, docs, no test harness), pick another observable check: run the command and read the output, type-check, lint, or exercise the code path manually. The point is a check you can actually run, not necessarily a test.
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.
7. Fail Loud
Surface failures and uncertainty - never pivot silently.
If a command fails, a step gets skipped, or something doesn't behave as expected, say so plainly - don't quietly route around it and report success. "Done" is wrong if anything was skipped; "it works" is wrong if you didn't actually check.