Build minimal reimplementations of complex projects following Karpathy's nano/micro/min philosophy. Analyzes a target project to identify its irreducible algorithmic core, decomposes it into progressive layers, and guides incremental building with verification at each step. Works for any domain. Triggers on "build a minimal version of", "nanorepl", "reimplement from scratch", "strip down to the core", "build a micro/nano/mini version", or when a project URL is provided with a request to understand or rebuild its core. Invoke with "nanorepl".
"What I Cannot Create, I Do Not Understand." -- Richard Feynman
Build a minimal reimplementation of any complex project. Strip away everything that isn't the core algorithm, then layer complexity back in one concept at a time.
Two independent dials control the output:
Scale (1-5) -- how much of the project to replicate:
| Scale | LOC Target | Scope |
|---|---|---|
| 1 | ~50-200 | Core algorithm only |
| 2 | ~200-500 | + real I/O, runs on real data |
| 3 | ~500-1000 | + essential features, produces useful results |
| 4 | ~1000-2000 | + complete feature set, basic error handling |
| 5 | ~2000+ | + configuration, optimizations, usable tool |
Level (micro/nano/mini) -- implementation style:
| Level | Style | Dependencies | Files |
|---|---|---|---|
| micro | Pure algorithm, zero external deps, implement everything from scratch | stdlib only | single file |
| nano | Pragmatic minimal, stdlib + one key dependency | stdlib + 1 | single file |
| mini | Structured minimal, essential deps, some organization | essential deps | 1-3 files |
Default: nano-3 -- single file, one dependency, produces real results.
Reference points: micro-1 = microGPT gist (~200 LOC, pure Python autograd + GPT). nano-3 = nanoGPT (~600 LOC, PyTorch model + training). mini-5 = nanochat (~8000 LOC, full pipeline).
nanorepl # Start new project
nanorepl <url> # Analyze a specific project
nanorepl <concept> <level>-<scale> # Quick start with parameters
Use AskUserQuestion to gather parameters:
Q1 -- Target: "What do you want to build a minimal version of?"
Q2 -- Scale and Level: "What complexity?"
{level}-{scale} (e.g., micro-2, mini-4)Q3 -- Language: "What language?" (default: Python)
Q4 -- Output location: "Where to create the project?" (default: ./nanorepl-{name}/)
If the user provided arguments with nanorepl, skip already-answered questions.
Analyze the target to identify the irreducible core. Approach depends on input type:
If the target is very large (e.g., an entire framework like PyTorch or Linux), ask the user to identify a specific subsystem or capability to reimplement. Do not attempt to analyze an entire large codebase.
| Input | Action |
|---|---|
| GitHub URL | Fetch README via WebFetch. Clone if needed. Read entry points and core modules. Trace imports only for core algorithm -- do NOT read the entire repo. |
| Local path | Read directory structure. Read entry points and core modules. Map dependencies between modules. |
| Concept | WebSearch for reference implementations. Read 2-3 authoritative sources. Synthesize understanding of the core algorithm. |
| Paper URL | Fetch and extract the key algorithm, data structures, and evaluation approach. |
Produce an anatomy -- classify every component of the original:
| Category | Action |
|---|---|
| Core algorithm | KEEP -- implement explicitly, no black boxes |
| Essential data structures | KEEP -- simplest representation that works |
| I/O interface | KEEP -- simplify to minimum viable |
| Everything else | Classify per references/stripping-heuristics.md -- STRIP, DEFER to higher scale, or MAKE EXPLICIT |
Read references/stripping-heuristics.md from this skill's directory for the full decision framework.
Generate a layer plan. Number of layers = scale value (scale 3 = layers L0, L1, L2).
Rules:
Layer template from microGPT blog (example for a language model at micro-5):
For each layer, specify:
Present the decomposition as a clean overview:
nanorepl-{name} [{level}-{scale}]: {one-line description}
L0 (~{N} LOC): {core algorithm name}
adds: {what}
verify: {command}
L1 (~{N} LOC): + {concept added}
adds: {what}
verify: {command}
diff: {key additions from L0}
...
Stripped from original:
- {thing}: {why it was removed}
- {thing}: {why it was removed}
Wait for the user to confirm or adjust before building.
Build one layer at a time, interactively.
For each layer:
Generate the layer file (layer{N}.py or appropriate extension)
diff layer{N-1}.py layer{N}.py shows clean, meaningful changes# forward pass), step markers (# step 1), variable descriptions (# learning rate), or formula annotations (# dL/dw). If the code needs a comment to be understood, rename the variable or restructure the code instead. The only acceptable comment explains a non-obvious design choice (e.g., # ReLU instead of sigmoid to avoid vanishing gradients).micro level: zero external deps, implement everything from scratchnano level: allow one key dependencymini level: allow essential deps, may use multiple files per layerPresent with context
Show verification
Wait for user input. Supported commands:
| Command | Action |
|---|---|
next | Proceed to next layer |
explain {thing} | Walk through specific code, function, or concept |
diff | Show diff from previous layer |
modify {request} | Adjust current layer |
done | Stop here, skip remaining layers |
restart {N} | Regenerate from layer N |
After all layers are built (or user says "done"), generate README.md in the project directory:
# nanorepl-{name}
A minimal reimplementation of {project} in {total LOC} lines of {language}.
> "{one-line description of what the irreducible core does}"
## Layers
| File | LOC | Concept Added |
|------|-----|---------------|
| layer0.py | {N} | {core algorithm} |
| layer1.py | {N} | + {concept} |
| ... | ... | ... |
## What Was Stripped
| Original Feature | Why Removed |
|-----------------|-------------|
| {feature} | {rationale from stripping heuristics} |
## Run
{command to run the final layer}
## Compare
- Original: {link to original project}
- This reimplementation: {total LOC} lines vs {original LOC estimate}
These are non-negotiable -- they apply to every nanorepl project:
# forward pass), no variable descriptions (# weights), no formula annotations. If the code isn't clear, rename variables or restructure -- don't add a comment.diff between adjacent layers reveals exactly what one concept looks like in code.| Behavior | Rule |
|---|---|
| Layer files | Always standalone, never import from other layers |
| File naming | layer{N}.py at micro/nano level. At mini level with multiple files per layer: layer{N}/ directory (e.g., layer2/model.py, layer2/train.py) |
| Default language | Python unless user specifies otherwise |
| Default complexity | nano-3 |
| Layer 0 | Always the irreducible core, always present |
| Verification | Required for every layer -- no unverifiable code |
| Dependencies at micro | Zero. Implement from scratch, including things like autograd, HTTP parsing, etc. |
| Dependencies at nano | One key dependency maximum |
| Comments | Zero comments by default. Only a rare "why" comment for a non-obvious design choice. No section labels, no variable descriptions, no formula annotations, no step markers. |
| README | Always generated at the end |