⚡ Karpathy-Inspired

Fix How Claude Code Behaves

One file. Six principles. Drop it in your project and Claude Code stops guessing, over-engineering, and touching code it shouldn't.

⭐ Star on GitHub See Live Demo ↓
6
Principles
1
File to drop
30s
To install
MIT
License

Interactive Demo

Toggle between what LLMs do wrong and what should happen.

Principle 1 — Think Before Coding

Don't assume. Don't hide confusion. Surface tradeoffs.

"Add a feature to export user data"
View:
export.py WRONG
def export_users(format='json'):
    # assumed ALL users — no pagination, no privacy check
    users = User.query.all()
    # assumed file path without asking
    with open('users.json', 'w') as f:
        # assumed which fields to include
        json.dump([u.to_dict() for u in users], f)

# Problems:
# - Exports ALL users (privacy/GDPR risk)
# - Hardcoded file path
# - No pagination for large datasets
# - Assumed JSON format without asking
Problem: Silently assumed scope (all users), delivery (local file), format (JSON), and fields — without asking any of them. One wrong assumption can mean a GDPR violation.

Principle 2 — Simplicity First

Minimum code that solves today's problem. Nothing speculative.

"Add a function to calculate discount"
View:
discount.py WRONG
from abc import ABC, abstractmethod
from dataclasses import dataclass

class DiscountStrategy(ABC):
    @abstractmethod
    def calculate(self, amount: float) -> float: ...

class PercentageDiscount(DiscountStrategy):
    def __init__(self, pct): self.pct = pct
    def calculate(self, amount):
        return amount * (self.pct / 100)

class FixedDiscount(DiscountStrategy):
    def __init__(self, fixed): self.fixed = fixed
    def calculate(self, amount): return min(self.fixed, amount)

@dataclass
class DiscountConfig:
    strategy: DiscountStrategy
    min_purchase: float = 0.0

class DiscountCalculator:
    def __init__(self, config): self.config = config
    def apply(self, amount):
        if amount < self.config.min_purchase: return 0
        return self.config.strategy.calculate(amount)

# 60+ lines for a single use case that doesn't exist yet
Problem: Strategy pattern, abstract classes, dataclasses — for one discount type that was never asked for. 60+ lines when 3 would do.

Principle 3 — Surgical Changes

Touch only what the task requires. Match existing style.

"Fix the bug where empty emails crash the validator"
View:
validators.py — diff view WRONG
 def validate_user(user_data):
+    """Validate user data."""          # added docstring (unrequested)
-    if not user_data.get('email'):
+    email = user_data.get('email','').strip()
+    if not email:
         raise ValueError("Email required")
-    if '@' not in user_data['email']:
+    if '@' not in email or '.' not in email.split('@')[1]:  # "improved"
         raise ValueError("Invalid email")
-    if not user_data.get('username'):
+    username = user_data.get('username','').strip()   # reformatted
+    if not username:
         raise ValueError("Username required")
+    if len(username) < 3:                  # NEW RULE — nobody asked
+        raise ValueError("Username too short")
     return True
Problem: Added docstring, "improved" email regex beyond the bug, reformatted username block, added a min-length rule nobody requested. Only the empty email crash needed fixing.

Principle 4 — Goal-Driven Execution

Define success criteria. Loop until verified.

"Fix the authentication system"
View:
response WRONG
# LLM response:
"I'll fix the authentication system by:
  1. Reviewing the code
  2. Identifying issues
  3. Making improvements
  4. Testing the changes"

# Then proceeds to make unverifiable changes.
# No success criteria.
# No tests written.
# No way to know if it actually worked.
# "Done" means nothing here.
Problem: Zero success criteria = zero way to verify "done". Karpathy: "LLMs are exceptionally good at looping until they meet specific goals — give it success criteria and watch it go."

Principle 5 — Reproduce Before Fixing

Never patch a bug you haven't confirmed exists.

"The sorting breaks with duplicate scores"
View:
sort.py WRONG
# Immediately "fixes" without confirming the bug
def sort_scores(scores):
    return sorted(
        scores,
        key=lambda x: (-x['score'], x['name'])
    )

# Bug was never reproduced with a test.
# No confirmation the fix actually works.
# No regression check.
# If this is wrong — no way to know.
Problem: Blind patch. No failing test to prove the bug existed. No confirmation the fix works. Always: reproduce → confirm → fix → verify.

Principle 6 — Communicate Tradeoffs

Surface options before choosing. 3–5 lines, not an essay.

"Add rate limiting to the API"
View:
rate_limit.py WRONG
import redis

# Silently:
# - Installed Redis (new infra dependency)
# - Added docker-compose requirement
# - Changed production architecture
# - Never asked if Redis was even available

r = redis.Redis(host='localhost', port=6379)

def is_rate_limited(user_id: str) -> bool:
    key = f"rate:{user_id}"
    count = r.incr(key)
    if count == 1:
        r.expire(key, 60)
    return count > 100
Problem: Silently added Redis — a real infra dependency — without mentioning in-memory was an option. On a single server, in-memory works fine and needs zero setup.

Install in 30 seconds

Option A — Per project (curl)
curl -o CLAUDE.md https://raw.githubusercontent.com/BurukalaManiReethika/Karpathy-Inspired-Claude-Code-Guidelines/main/CLAUDE.md
Option B — Claude Code plugin (all projects)
/plugin marketplace add BurukalaManiReethika/Karpathy-Inspired-Claude-Code-Guidelines
/plugin install karpathy-code-guidelines@karpathy-guidelines