Skip to main content

Quick Overview

In this build-along tutorial, AI educator Nate Herk details how to create an autonomous coding and teaching agent in Claude Code modeled on former Tesla AI director and OpenAI co-founder Andrej Karpathy. The video demonstrates how to crawl an expert's public materials, convert them into a structured LLM wiki, and enforce strict coding rules using custom subagents and hooks.

Key Points

  • 1.An AI coding agent can be grounded in a domain expert's methodology by compiling their public content into a structured LLM wiki rather than relying on standard system prompts.
  • 2.Andrej Karpathy's engineering and teaching habits are codified into seven strict rules extracted only when supported by multiple independent citations.
  • 3.Claude Code subagents and custom skills isolate memory and tasks to prevent long contextual conversations from degrading performance.
  • 4.A custom Stop hook acts as an execution gate that blocks the agent from delivering code until it has actually executed and tested it.
  • 5.The knowledge base self-updates via an ingestion command that extracts new sources, links related concepts, and adds new behavioral rules when verified.

Summary

Nate Herk presents a workflow for building an AI agent inside Claude Code that replicates the engineering instincts and pedagogical style of Andrej Karpathy. Rather than creating a voice clone or relying on superficial roleplay prompts, the project creates an agent grounded in Karpathy's verified writing, lectures, and code. Karpathy previously noted publicly that Claude Code often prioritises writing raw code over explaining concepts and makes unverified assumptions. Herk addresses these limitations by pairing an external knowledge base with strict execution gates.

The project starts by collecting Karpathy's public work across GitHub repositories, YouTube lecture captions, blog posts, and posts on X. Herk uses Python tools including YouTube Transcript API and YT-DLP for video transcripts alongside TwitterAPI.io for social posts, compiling over 700,000 words of source material in under an hour. Following Karpathy's own LLM wiki specification, Claude Code compiles this raw data into structured Markdown files with dedicated source notes, concept topics, indexes, and logs. This structured format creates explicit links between concepts, allowing visual exploration through Obsidian graph views.

From the compiled wiki, Claude Code extracts seven operational rules supported by at least two distinct sources. These rules dictate that the agent must build the smallest functional version first, prioritise the first-order term, predict numerical outputs before running code, display the broken version first, provide empirical proof rather than unverified assertions, explicitly state assumptions, and favour simpler implementations. Each rule links directly to quotes and timestamps in the raw source files.

Herk packages these rules into two primary configuration files: a Claude Code subagent and a custom skill called karpathy-teach. The subagent runs in an isolated context window so complex instructional tasks do not overwhelm the main project conversation. To enforce strict execution discipline, Herk configures a Stop hook script in Claude Code. This hook checks whether the agent modified code without running it, blocking completion and requiring the agent to execute and verify the implementation before presenting results.

The system is evaluated by asking the subagent to build and explain a byte-pair tokenizer from scratch. The agent defines explicit success criteria, builds a minimal version on toy data, predicts outputs, intentionally triggers a failure on UTF-8 emoji strings, and repairs the bug. Herk also shows an automated ingestion command that processes new URLs, generates source pages, refreshes index files, and promotes candidate ideas into full operational rules once sufficient independent citations are logged.

Ingesting Expert Content and Building a Knowledge Wiki

Nate Herk explains how to crawl Andrej Karpathy's complete public footprint across GitHub repositories, YouTube lectures, blogs, and posts on X using tools like YouTube Transcript API, YT-DLP, and TwitterAPI.io. The resulting corpus of over 700,000 words is compiled by Claude Code into a structured Markdown wiki following Karpathy's open-source LLM wiki design, creating index files, source pages, and relationship graphs visualisable in Obsidian.

Codifying Karpathy's Seven Core Rules

To teach the agent how Karpathy thinks and builds, the wiki is parsed to extract operational rules that appear across at least two distinct source materials. The final seven rules require the agent to build the smallest version first, focus on first-order terms, predict outputs before execution, show broken versions first, provide empirical proof, declare assumptions explicitly, and prefer simplicity, with every claim backed by source citations.

Configuring Subagents, Skills, and Run Gate Hooks

Herk sets up a Claude Code subagent and a dedicated karpathy-teach skill to manage prompt execution without polluting context windows. To address the common flaw where language models deliver untested code, Herk implements a Stop hook script that intercepts the agent's output and rejects any response if code was written or modified without being executed and verified in the terminal.

Testing Code Generation and Incremental Wiki Ingestion

The system is tested by tasking the subagent with building a byte-pair tokenizer from scratch, prompting the agent to write clear criteria, make numerical predictions, intentionally demonstrate UTF-8 edge case failures, and fix them. Herk also demonstrates an automated ingestion command that parses new links, updates cross-references across the wiki, and integrates new behavioral rules into the system.

The Bottom Line

The video establishes a repeatable architecture for turning an expert's public knowledge into a rule-governed Claude Code subagent backed by a structured wiki. It demonstrates that combining automated run-gate hooks with citation-backed behavioral rules forces language models to test their code and provide structured technical explanations. The workflow leaves open how effectively this structured extraction method translates to non-technical disciplines with less empirical documentation.

FAQ

What is an Andrej Karpathy Claude Code agent and how is it built?

An Andrej Karpathy Claude Code agent is a custom AI subagent programmed to emulate Andrej Karpathy's coding discipline and pedagogical methods. It is built by scraping his public content, compiling it into an LLM wiki, extracting multi-source verified rules, and configuring Claude Code subagents, skills, and Stop hooks.

Which specific tools are used to collect Andrej Karpathy's public content for the agent?

The build uses the YouTube Transcript API and YT-DLP to scrape video lecture captions, direct access for GitHub repositories and blogs, and TwitterAPI.io to retrieve posts from X.

What are the seven core rules codified into the Karpathy Claude Code agent?

The seven rules are building the smallest version first, starting with the first-order term, predicting output before running code, showing the broken version first, proving claims with empirical output, stating assumptions explicitly, and choosing simpler implementations.

Why is a Stop hook run gate implemented within the Claude Code agent?

The Stop hook enforces code verification by intercepting Claude Code before it finishes a turn. If code was written or edited without being run in the terminal, the hook blocks the response and instructs the agent to run and verify the code first.

How does the Karpathy ingest command update the knowledge wiki when new content is provided?

The command fetches the source material from a provided URL, creates a dedicated Markdown source page, updates cross-references in linked concept pages, and automatically refreshes the index, hot page, and ingestion log.

Worth watching for

Software developers, AI automation engineers, and technical creators looking to build expert-informed subagents and enforce rigorous testing workflows inside Claude Code.

  • claude-code
  • ai-agents
  • andrej-karpathy
  • llm-wiki
  • prompt-engineering
  • obsidian