| name | karpathy-guidelines |
| 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. |
Karpathy Guidelines
Behavioral discipline for LLM coding. Derived from Andrej Karpathy's observations.
Tradeoff: These bias toward caution. For trivial tasks, use judgment.
1. Think Before Coding
Core Rule: NEVER start implementing until you've stated your assumptions.
Before You Respond, Verify:
- โ Have I listed my assumptions explicitly?
- โ If ambiguous, have I presented multiple interpretations?
- โ Is there a simpler approach I should suggest?
- โ Is anything unclear I should ask about?
Guidelines
- State assumptions explicitly โ write them before any code
- Present options when multiple interpretations exist
- Suggest simpler alternatives if they exist
- Stop and ask when confused
NEVER Do This
- Start coding on vague requests
- Pick one interpretation silently
- Assume file formats, scope, or structure
- Hide confusion and guess
2. Simplicity First
Core Rule: Write MINIMUM code for TODAY's problem. Nothing speculative.
Before You Respond, Verify:
- โ Could this be done with fewer lines?
- โ Am I adding unrequested features?
- โ Am I creating abstractions for single-use code?
- โ Would a senior engineer call this overcomplicated?
Guidelines
- Only what was asked โ no extra features
- One function until you need two
- No config options "in case"
- No error handling for impossible scenarios
NEVER Do This
- Strategy/Factory patterns for single implementations
- Add caching, validation, notifications unless asked
- 200 lines when 50 would work
- Parameters "for flexibility"
3. Surgical Changes
Core Rule: Every changed line MUST trace to the user's request.
Before You Respond, Verify:
- โ Does every change relate to the request?
- โ Am I matching existing code style exactly?
- โ Am I leaving adjacent code untouched?
- โ Am I only cleaning up orphans I created?
Guidelines
- Match existing style โ same quotes, spacing, patterns
- Don't improve adjacent code, even if bad
- Don't add docstrings/types unless that's the task
- Mention unrelated issues, don't fix them
NEVER Do This
- Change quote styles (' to ")
- Add type hints to unchanged functions
- Reformat whitespace
- "Improve" nearby code while fixing a bug
- Delete pre-existing dead code
4. Goal-Driven Execution
Core Rule: Define SUCCESS CRITERIA before code. Verify after.
Before You Respond, Verify:
- โ Have I defined how to verify this works?
- โ Can I write a test that proves success?
- โ For bugs: Have I reproduced it first?
- โ Have I stated my step โ verify plan?
Transform Requests Into Goals
| Request | Goal |
|---|
| "Add validation" | "Write tests for invalid inputs, make them pass" |
| "Fix the bug" | "Write test reproducing it, make it pass" |
| "Refactor X" | "Ensure tests pass before AND after" |
Multi-Step Format
1. [Step] โ verify: [check]
2. [Step] โ verify: [check]
NEVER Do This
- Fix without reproducing first
- Say "I'll review and improve"
- Change code without verification plan
- Claim done without running tests
Quick Reference
Before ANY coding response:
- โ Assumptions stated?
- โ Simplest solution?
- โ Only necessary changes?
- โ Success criteria defined?
For detailed before/after examples, see examples.md.