claude-code-from-scratch  by Windy3f3f3f3f

Replicate a coding agent's core logic in ~1300 lines of TypeScript

Created 3 days ago

New!

628 stars

Top 52.7% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides a highly distilled, educational implementation of a coding agent, replicating core functionalities of Claude Code in approximately 1300 lines of TypeScript. It serves as a step-by-step tutorial for developers and researchers aiming to understand the internal workings of advanced coding assistants, offering a simplified yet functional model for learning and experimentation.

How It Works

The project reconstructs a coding agent's essential components, centered around a core agent loop that iteratively calls a Large Language Model (LLM), executes tools based on its output, and processes results. Key design choices include a simplified tool system comprising six fundamental operations (file read/write, code edit, search, command execution), strategic system prompt engineering to guide the LLM, and support for streaming output via both Anthropic and OpenAI compatible APIs. Context management is handled through token tracking and automatic dialogue compression, while a basic security layer requires user confirmation for potentially dangerous commands.

Quick Start & Requirements

  • Primary install/run command: Clone the repository, install dependencies with npm install, build with npm run build, and run the interactive REPL with npm start. Global CLI access is available via npm link followed by mini-claude.
  • Non-default prerequisites: Node.js environment, API keys for either Anthropic (ANTHROPIC_API_KEY) or OpenAI (OPENAI_API_KEY), and optionally custom base URLs (ANTHROPIC_BASE_URL, OPENAI_BASE_URL).
  • Configuration: Model selection can be configured via the MINI_CLAUDE_MODEL environment variable or a command-line argument (--model).
  • Links: Repository: https://github.com/Windy3f3f3f3f/claude-code-from-scratch

Highlighted Details

  • Agent Loop: Automates task execution through continuous LLM calls, tool invocation, and result processing.
  • Core Toolset: Implements six essential tools for code-related tasks, including file I/O, editing, searching, and command execution.
  • Dual Backend Streaming: Supports real-time, word-by-word output compatible with both Anthropic and OpenAI API formats.
  • Context Management: Features token usage tracking and automatic dialogue compression to manage context window limitations.
  • Security Confirmation: Includes a mechanism to prompt users before executing potentially dangerous commands, bypassable with the --yolo flag.
  • Session Persistence: Automatically saves conversation history for resuming sessions with the --resume flag.
  • Error Handling: Implements exponential backoff for API retries and graceful interruption via Ctrl+C.

Maintenance & Community

The project acknowledges support and discussion from the LINUX DO community. No specific details regarding active maintainers, sponsorships, or dedicated community channels (like Discord/Slack) are provided in the README.

Licensing & Compatibility

The project is released under the MIT license. This permissive license allows for broad compatibility, including commercial use and integration into closed-source projects without significant restrictions.

Limitations & Caveats

This project is explicitly positioned as a "minimal viable implementation" for educational purposes, contrasting with the production-grade complexity of the original Claude Code. It features a significantly reduced toolset (6 vs. 66+), a simpler security model, and less sophisticated context management compared to its inspiration. The ~1300-line codebase prioritizes clarity and learning over feature parity or robustness for demanding production environments.

Health Check
Last Commit

1 day ago

Responsiveness

Inactive

Pull Requests (30d)
1
Issues (30d)
0
Star History
653 stars in the last 3 days

Explore Similar Projects

Feedback? Help us improve.