Build your own Claude Code
Build Claude Code itself — loop, tools, permissions, subagents, MCP, hooks, skills — and watch your clone fix a repo.
What you'll build
You'll reconstruct Claude Code in TypeScript, feature by feature. Start from the bare Anthropic Messages-API loop (tool_use → execute → tool_result → repeat) and build outward: the Read/Write/Edit/Bash tools with read-before-edit and stale-write guards, a permission engine and a sandbox, subagents, an MCP client and server, hooks, skills, context compaction, and plan mode. The model is replayed from cassettes so runs are deterministic; your tools execute for real against a sandbox; and 'the task is done' is decided by a test's exit code and a byte diff — never by a model judging itself.
- The Messages-API agent loop and the real tool surface — view/create/edit (exact-match + stale-write) / glob / grep / bash — confined to a sandbox guard
- A permission engine (modes + allow/ask/deny rules + protected paths) and subagents that run in isolated context with their own tool allowlist
- An MCP client and server speaking JSON-RPC, plus hooks that block/modify tool calls and skills loaded from SKILL.md
- Context compaction, plan mode + task tracking, and a CLI that fixes a real repo — graded on the trajectory, the final files, and the planted test
What you'll learn
- What separates a chatbot from an agent: tools with real side effects driven by a loop that decides when it is done
- The safety layer every real agent needs — permission precedence (deny→ask→allow), protected paths, and sandbox containment
- How subagents, MCP, hooks, and skills actually wire together — isolated context, JSON-RPC framing, the hook exit-code contract, progressive skill disclosure
- How to grade an agent deterministically — fix the model with a cassette, run the tools for real, assert the side effects
Prerequisites
- Completed react-agent (a reason→act→observe loop)
- Comfortable reading and running TypeScript, including async code and child processes
- Familiar with JSON and the shape of an HTTP/JSON-RPC request (we build the protocols by hand)
Get started
Everything runs locally — no GPU, no API keys. Clear stage 1 in under ten minutes.
# 1. log in (approve in your browser — required) npx theinference login # 2. scaffold the course npx theinference course start claude-code ./claude-code # 3. install dependencies cd claude-code && npm install # 4. grade the first stage npx theinference test --stage run-the-grader --watch
Each lesson shows the exact --stage command for that stage — passing it marks the stage complete here automatically.