MiniClaudeCode banner
bcefghj bcefghj

MiniClaudeCode

Development community

Description

miniClaudeCode - 从50万行蒸馏到~1000行的Claude Code核心Agent架构最小复现 | Distilled Claude Code agent framework

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

miniClaudeCode

**从 50 万行蒸馏到 ~800 行 -- Claude Code 核心架构的最小可运行复现**

miniClaudeCode 是对 [Claude Code](https://docs.anthropic.com/en/docs/claude-code) 核心 Agent 架构的蒸馏(distillation)实现。它保留了 Claude Code 最核心的四大模块——Agent Loop、Tool System、Permission System、Context Management——同时将代码量从原版的 ~500K 行精简到 ~800 行纯 Python。

架构总览

用户输入
   │
   ▼
┌─────────────────────────────────┐
│         Agent Loop              │
│  ┌───────────────────────────┐  │
│  │  1. 构建 System Prompt    │  │
│  │  2. 调用 Claude API       │  │
│  │  3. 解析 tool_use blocks  │  │
│  │  4. 权限检查 (2层)        │  │
│  │  5. 执行工具              │  │
│  │  6. 结果追加到上下文      │  │
│  │  7. 循环直到无工具调用    │  │
│  └───────────────────────────┘  │
└─────────────────────────────────┘
   │
   ▼
最终文本输出

Claude Code 原版 vs miniClaudeCode

模块 Claude Code 原版 miniClaudeCode
Agent Loop SSE 流式 + 多并行 tool_use 同步循环 + 顺序工具链
工具数量 26+ 内置工具 + MCP 扩展 6 个核心工具
权限系统 5 层 (工具自检 / allowlist / sandbox / 模式 / hooks) 2 层 (工具自检 + 模式)
上下文管理 会话持久化 + 压缩 + CLAUDE.md + 记忆 消息列表 + 截断 + CLAUDE.md
终端 UI React/Ink 渲染 简单 REPL
代码量 ~500,000 行 TypeScript ~800 行 Python

快速开始

安装

cd miniClaudeCode
pip install -r requirements.txt

设置 API Key

export ANTHROPIC_API_KEY="your-api-key"

交互模式

python -m miniclaudecode

单次执行

python -m miniclaudecode "帮我查看当前目录下有哪些 Python 文件"

指定模式

# 自动模式 (无需确认)
python -m miniclaudecode --mode auto "列出所有 .py 文件"

# 只读模式 (禁止写操作)
python -m miniclaudecode --mode plan "分析项目结构"

内置工具

miniClaudeCode 保留了 Claude Code 最核心的 6 个工具:

工具 对应原版 功能
bash BashTool 执行 shell 命令
read_file FileReadTool 读取文件内容(带行号)
write_file FileWriteTool 写入文件
edit_file FileEditTool 字符串替换编辑
glob GlobTool 按模式搜索文件
grep GrepTool 正则搜索文件内容

蒸馏笔记

什么是"蒸馏"?

蒸馏 (Distill