Karpathy coding principles

From oyi77/1ai-skills · View interactive version

Karpathy coding principles is an AI agent skill from the GitHub repository oyi77/1ai-skills. Use when andrej Karpathy's 4 coding principles — think before coding, simplicity first, surgical changes, goal-driven execution. Use when coding, reviewing code quality, reducing overengineering,.

How to use this skill

Skill file

When NOT to Use

Overview

Andrej Karpathy's 4 coding principles distilled into actionable rules for AI agents and developers. Focuses on reducing overengineering, maintaining simplicity, making minimal changes, and verifying outcomes. Originally from multica-ai/andrej-karpathy-skills.

Capabilities

When to Use

Trigger phrases:

Principle 1: Think Before Coding

Before writing any code, reason explicitly about the problem.

# BAD: Jump straight to code
def process(data):
    # immediately writing implementation

# GOOD: Think first
# Assumption: data is a list of dicts with 'id' and 'value' keys
# Edge cases: empty list, missing keys, negative values
# Approach: validate -> transform -> aggregate
def process(data):
    ...

Principle 2: Simplicity First

Write the minimum code that solves the problem. No speculative features.

# BAD: Over-engineered for current needs
class DataProcessor:
    def __init__(self, config: ProcessingConfig):
        self.strategy = config.get_strategy()
        self.pipeline = Pipeline(config.steps)
    
    def process(self, data): ...

# GOOD: Simple, direct, matches actual requirement
def process_data(data: list[dict]) -> list[dict]:
    return [transform(item) for item in data if item["active"]]

Principle 3: Surgical Changes

Edit only what the task requires. No drive-by refactoring.

# BAD: Task says "add timeout parameter"
# Also renames function, fixes whitespace, adds type hints to unrelated code

# GOOD: Task says "add timeout parameter"
# Adds the parameter with a default, threads it through to the call site. Done.

Principle 4: Goal-Driven Execution

Define what "done" looks like before starting. Verify it when finished.

# Goal: "The API returns paginated results"
# Verification criteria:
# 1. GET /items?page=2&limit=10 returns items 11-20
# 2. Response includes total_count and has_next fields
# 3. Edge case: page beyond total returns empty list, not error

How to Use

  1. Invoke the skill when relevant domain keywords appear in the request
  2. Provide required inputs as specified in the skill definition
  3. Review the output for correctness before delivering to the user
  4. Combine with related skills for complex multi-step workflows

Verification

After completing this skill, confirm:

Process

  1. Analyze the task requirements
  2. Apply domain expertise
  3. Verify output quality

Anti-Rationalization Table

| Rationalization | Reality |

|---|---|

| "I will add monitoring later" | Without monitoring, you cannot detect failures. Add it from day one. |

| "One model is enough" | Different tasks need different models. Route intelligently. |

| "Premature optimization" | Infrastructure decisions are hard to change later. Design for scale early. |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.