Claude Code From Scratch
Reimplement Claude Code's core in ~5,000 lines of code with a 13-chapter step-by-step tutorial to understand Coding Agents.
- Source repo
- Windy3f3f3f3f/claude-code-from-scratch
- Stars
- ★ 2.9k
- Last updated
- 3d ago v1.0.0
- FARS reviewed
- Nov 08, 2026
- License
- MIT
- Primary language
- HTML
- FA score
- 62/100 · Some gaps
At a glance
- How it runs
- Works with
- Universal · cross-platformOpenAI API · Claude API
- Cost
- Free software; you pay for model usage
- Setup effort
- Low · running in minutes
- You'll need
- Typical use
- Developers who want to deeply understand Claude Code's inner workings but find the 500k-line codebase overwhelming, using a step-by-step tutorial to reimplement the core.
- Not a fit if
- Teams needing production-grade robustness; this is a teaching minimal implementation
- Website
- windy3f3f3f3f.github.io ↗ set on GitHub
- Maintenance
- Commits in the last 30 dayslast commit 2026-11-29latest release v1.0.0 (2026-03-31)+0.7 ★/day over 7 days
- Source review
- 62/100 · Some gaps
What does this agent do, and when should you use it?
This is an educational project that reimplements the core architecture of Claude Code from scratch in about 5,000 lines of TypeScript or Python, rather than a full replacement. It includes a 13-chapter tutorial covering the Agent Loop, 13 tools (including parallel execution and streaming early start), 4-layer context compaction, semantic memory recall, skill system, multi-agent collaboration, and MCP integration. Each chapter's code is runnable without an API key, powered by a local mock model, with '--diff' to see newly added code. The project offers two functionally equivalent versions in TypeScript and Python, supports Anthropic and OpenAI-compatible API backends, and includes detailed architecture comparisons with Claude Code.
The project provides a complete implementation and tutorial for building a Coding Agent from scratch. The core is an Agent Loop: repeatedly calling the LLM, executing tools, and processing results until the task is complete. It implements 13 tools (e.g., file read/write, Shell, WebFetch, ToolSearch), supporting parallel execution of read-only tools and streaming output. It includes 4-layer context compaction, 5 permission modes, 4 memory types with semantic recall and async prefetch, a skill system (inline/fork modes), Sub-Agent multi-agent architecture, and an MCP client. It provides an interactive REPL CLI, session persistence, budget control (--max-cost, --max-turns), cross-platform shell auto-detection, and error retries. Each chapter includes a runnable minimal implementation, demonstrated via node steps/run.mjs <N> without needing real APIs.
- Developers who want to deeply understand Claude Code's inner workings but find the 500k-line codebase overwhelming, using a step-by-step tutorial to reimplement the core.
- Learners who want hands-on experience with Coding Agents, using runnable minimal code to quickly validate concepts without API keys.
- Technical instructors or bloggers needing a structured, reproducible teaching resource for topics like Agent Loop, tool systems, and context management.
- Developers who want to integrate a lightweight Coding Agent core into their own projects, using this as a reference or base.
- Researchers interested in advanced features like multi-agent collaboration and MCP integration, referencing the implementation patterns.
Key setup facts
Pulled from the install and usage notes below. The project README has the current values.
- Install / run
npm install && npm run build
- Environment variables
ANTHROPIC_API_KEYOPENAI_API_KEYOPENAI_BASE_URL- Runtime
- Python 3.11+
How do you install or deploy this agent?
Clone the repository: git clone https://github.com/Windy3f3f3f3f/claude-code-from-scratch.git, then cd claude-code-from-scratch and run npm install && npm run build. For Python version (requires Python 3.11+), cd python && pip install -e .. Configure API by setting environment variables: ANTHROPIC_API_KEY (Anthropic format) or OPENAI_API_KEY and OPENAI_BASE_URL (OpenAI-compatible format).
How do you use this agent?
Run the TypeScript version: npm start for interactive REPL mode, with flags like --resume to resume last session, --yolo to skip safety confirmations, --plan for plan mode, --max-cost for spending limits. Python version uses mini-claude-py command. In-session commands include /clear, /cost, /compact, /memory, /skills. To run tutorial chapters: node steps/run.mjs <N> where N is chapter number; use --diff to see code changes, --py for Python version, --live to connect to real models.
Safety boundaries, hardening & integrations
Operational blast radius, source-verified safety controls, and first-run hardening steps before connecting this agent to real workspaces.
Declared capability surface (blast radius)
Can run terminal commands; pair with approval gates or container/OS sandboxing.
Modifies local files; work on a clean Git branch or dedicated worktree.
Makes outbound requests; verify telemetry settings and model data routing on private repos.
Inherits capabilities of connected MCP servers; audit third-party servers before enabling.
What are this agent's strengths and limitations?
- Every chapter's code runs without an API key, using a local mock model, making it easy to learn and debug.
- Provides both TypeScript and Python versions to suit different language preferences.
- Detailed architecture comparison tables clearly show differences from Claude Code.
- Educational nature; feature completeness and robustness are not production-grade compared to Claude Code.
- Default model
claude-opus-4-6may require a valid API key, and there is no built-in model fallback strategy. - Advanced features like context compaction are simplified implementations that may differ from the original behavior.
How does this agent compare with similar options?
Compared to Claude Code, this project is positioned as a learning minimal implementation: only 13 tools (vs. 66+ in Claude Code), ~5000 lines of code (vs. 500k+), simplified permission system (5 modes vs. 7-layer + AST), and multi-agent only supports Sub-Agent (vs. Coordinator + Swarm).
Key facts side by side with the most closely related agents.
| Agent | Source review | Form / cost | Stars | Updated | Language | Full support on |
|---|---|---|---|---|---|---|
| Claude Code From Scratch This agent | 62 · Some gaps | CLIFree + model costs | ★ 2.9k | 3d ago | HTML | OpenAI API · Claude API |
| PI from Scratch | 56 · Major gaps | CLIFree + model costs | ★ 1.3k | 1mo ago | TypeScript | OpenAI API |
| Learn Claude Code: Harness Engineering for Real Agents | 57 · Major gaps | CLIFree + model costs | ★ 81k | 18d ago | Python | Claude API |
| Donggua's AI Learning Notes: In-depth Pi-Agent SDK Tutorial | 49 · Major gaps | Web appFree | ★ 3.8k | 3mo ago | MDX | — |
How does FollowAgents rate this agent?
Why each dimension lost points
The code and documentation describe permission modes, confirmation flows, deny-first rules, and a session whitelist; they also state that MCP connects external tools over stdio, giving some support for data-flow transparency and ordinary confirmation. Deductions: --yolo can bypass confirmations, dangerous-command protection relies on regexes that the documentation says can miss cases, and the packet gives limited evidence of credential protection, fine-grained tool permissions, or rollback. The project describes itself as an independent learning implementation inspired by publicly observable behavior and disclaims Anthropic affiliation, supporting limited attribution but not independent verification of Claude Code internals.
The README, package scripts, Python entry point, and test files jointly show two language implementations, retries, budget limits, and an organized test suite; their main architectural descriptions broadly align. Deductions: some README capability claims cannot be checked against this source sample, and some features are described only in summaries. Evidence about user-facing error messages and recovery guidance is limited. No execution result is inferred from this static review.
The tutorial clearly targets readers learning coding-agent principles and progresses from the core loop to permissions, memory, skills, and MCP. Deductions: although it distinguishes a learning implementation from a production product, some capability boundaries are summarized rather than fully demonstrated; the sampled skill descriptions give limited evidence about avoiding unintended triggers; TypeScript, Python, and multiple API configurations are offered, but environment and deployment guidance is limited.
Navigation, chapter structure, quick starts, command examples, project layout, and the permissions chapter are clear. The MIT license text is complete, and the regex protection limitations are stated. Deductions: the sample contains no version history, and maintenance responsibility and update path are unclear; package and README metadata provide some naming and version information but no full stability policy.
Chapter commands, diff viewing, two language entry points, and a local mock teaching path make the material usable for step-by-step learning and reuse; the comparison and architecture explanations add learning value. Deductions: live model use requires API configuration and can incur costs, although budget flags are offered; real-agent permission and safety behavior still depends on configuration and the specific tool call.
The README's chapter claims partly correspond to the supplied permissions documentation, entry-point code, package scripts, and tests; the permissions chapter also distinguishes its simplified demo from the fuller repository implementation. Deductions: this is only a sample of files, so many README claims cannot be checked individually here, and claims and code do not provide independent corroboration for every feature. The project distinguishes publicly observable behavior from actual internal implementation, reducing the risk of presenting inference as fact, but tutorial descriptions are largely supported by the project itself.
- This is a learning-oriented agent implementation. Live model use requires API credentials, and --yolo skips confirmations. The documentation explicitly says the dangerous-command regexes can miss cases.
- This assessment uses only the supplied static source sample; code was not executed, and files outside the sample are unknown.
Recent releases
Latest entries from the project's GitHub Releases. Notes are quoted from upstream as written, not rewritten or tested by FollowAgents.
FAQ
Do I need an API key to run the tutorial chapters?
--live flag to connect to real APIs.Which model backends are supported?
Is this project affiliated with Anthropic?
How to customize the model?
MINI_CLAUDE_MODEL or pass --model as a command-line argument (CLI takes precedence).Is there a Python version?
mini-claude-py command.Thanks — we use this to improve the page.
Subscribe to the FollowAgents RSS feed, or save this agent to your browser shortlist to compare on your next visit.