灵感来自 Claude Code 的 Python AI 编程助手学习项目
零依赖 · 高性能 · 跨平台
Python 3.11+ | MIT License | 零外部依赖 | 98.9% 测试覆盖率
中文文档 | English Docs
🔍 搜索关键词导航 | Search Keywords
中文关键词 : Claude Code | AI编程助手 | AI Agent | 终端AI工具 | Python代码助手 | CLI开发工具 | 智能编程 | AI代码补全 | Git工具 | 代码审查 | 零依赖Python | 高性能CLI | Anthropic Claude | AI工作流自动化
English Keywords : Claude Code | AI Agent | AI coding assistant | Terminal AI tool | Python code helper | CLI development tool | Intelligent programming | AI code completion | Git tools | Code review | Zero dependency Python | High performance CLI | Anthropic Claude | AI workflow automation
💡 灵感来自 Claude Code | 📚 Python 学习项目
git clone https://github.com/laojiahuo2003/BabyCode.git
cd BabyCode
# 交互式安装(推荐)
python -m babycode.main --install
平台
安装后命令
直接运行命令
Windows
babycode.bat
python -m babycode.main
macOS
babycode-py
python3 -m babycode.main
Linux
babycode-py
python3 -m babycode.main
📋 Windows 配置 PATH
按 Win+R 输入 sysdm.cpl
高级 → 环境变量
在用户变量中找到 Path
添加:%USERPROFILE%\.baby-code\bin
重启终端后使用:babycode.bat
📋 macOS 配置 PATH (zsh)
# 快速添加(macOS 默认 zsh)
echo ' export PATH="$HOME/.local/bin:$PATH"' >> ~ /.zshrc
source ~ /.zshrc
# 启动命令
babycode-py
📋 Linux 配置 PATH (bash)
# 快速添加
echo ' export PATH="$HOME/.local/bin:$PATH"' >> ~ /.bashrc
source ~ /.bashrc
# 启动命令
babycode-py
经过 8 轮系统化优化 (93+ 优化点),在关键性能指标上达到生产级优秀水平 :
性能指标
优化前
优化后
提升
Token 估算速度
35 ops/sec
479,326 ops/sec
🚀 13,695x
CPU 空闲使用率
5%
2%
⬇️ 60%
文件读取(缓存)
196ms/1000
107ms/1000
⬆️ 1.8x
GC 压力
高
低
⬇️ 30-50%
代码可读性
3/10
9/10
⬆️ 200%
测试通过率
-
98.9%
✅ 生产级
🖥️ 丰富的终端 UI — 备用屏幕 TUI,面板、ANSI 样式、平滑滚动 | Rich Terminal UI with alternate-screen TUI
🤖 智能代理循环 — 多轮工具使用,自动规划、执行、迭代 | Intelligent Agent Loop with multi-turn tool use
🛠️ 30+ 内置工具 — 文件 I/O、代码搜索、Shell、Git、测试等 | 30+ Built-in tools for file I/O, code search, shell, git
🔒 权限系统 — 审批、拒绝、自动允许工具调用 | Permission system for tool call approval
💾 会话持久化 — 保存并恢复对话,30 秒自动保存 | Session persistence with autosave
🧠 三级记忆 — 对话 → 会话 → 长期记忆 | 3-Tier Memory system
🔌 MCP 集成 — 连接外部模型上下文协议服务器 | MCP integration for external servers
⌨️ 斜杠命令 — /help、/tools、/cost、/config、/context、/memory
学习方向
技术点
AI Agent 开发
理解 Claude Code 架构设计理念
Python TUI
终端备用屏幕、ANSI 样式、平滑滚动
工具调用系统
Tool use loop, 权限审批, 自动化执行
性能优化
13,695x 提速经验,93+ 优化点实践
零依赖设计
纯 Python 标准库实现,无外部依赖
工具
说明
Description
list_files
列出目录内容
List directory contents
grep_files
跨文件正则搜索
Regex search across files
read_file
读取文件(支持行范围)
Read file with line ranges
write_file
创建或覆盖文件
Create or overwrite files
edit_file / patch_file
文件编辑
File editing and patching
工具
说明
Description
find_symbols
AST 符号搜索
AST-based symbol search
find_references
查找符号引用
Find symbol references
code_review
代码质量分析
Code quality analysis
执行与测试 | Execution & Testing
工具
说明
Description
run_command
执行 Shell 命令
Execute shell commands
test_runner
测试发现和执行
Test discovery and execution
工具
说明
Description
git
Git 工作流
Git workflow automation
docker_helper
Docker 管理
Docker management
db_explorer
SQLite 数据库探索
SQLite database exploration
完整工具列表见 英文版文档
~/.baby-code/settings.json:
方案一:Anthropic API
{
"model" : " claude-sonnet-4-20250514" ,
"env" : {
"ANTHROPIC_BASE_URL" : " https://api.anthropic.com" ,
"ANTHROPIC_AUTH_TOKEN" : " your-token-here"
}
}
方案二:OpenRouter
{
"model" : " z-ai/glm-5.1" ,
"env" : {
"OPENROUTER_API_KEY" : " sk-or-..."
}
}
# 克隆仓库
git clone https://github.com/laojiahuo2003/BabyCode.git
cd BabyCode
# 运行测试
pip install -e " .[dev]"
pytest
# Mock 模式(无需 API 密钥)
BABY_CODE_MODEL_MODE=mock python -m babycode.main
指标
值
Python 文件数
69
代码行数
~15,000
内置工具
30+
外部依赖
0
优化点
93+
测试通过率
98.9%
代码可读性
9/10
After 8 rounds of systematic optimization (93+ optimizations), BabyCode Python achieves production-grade performance :
Metric
Before
After
Improvement
Token Estimation
35 ops/sec
479,326 ops/sec
🚀 13,695x
CPU Idle Usage
5%
2%
⬇️ 60%
File Read (Cached)
196ms/1000
107ms/1000
⬆️ 1.8x
GC Pressure
High
Low
⬇️ 30-50%
Code Readability
3/10
9/10
⬆️ 200%
Test Pass Rate
-
98.9%
✅ Production-ready
git clone https://github.com/laojiahuo2003/BabyCode.git
cd BabyCode
# Interactive installer (recommended)
python -m babycode.main --install
Cross-Platform Launch Commands
Platform
After Install
Direct Run
Windows
babycode.bat
python -m babycode.main
macOS
babycode-py
python3 -m babycode.main
Linux
babycode-py
python3 -m babycode.main
📋 Windows PATH Setup
Press Win+R, type sysdm.cpl
Advanced → Environment Variables
Find Path in User Variables
Add: %USERPROFILE%\.baby-code\bin
Restart terminal, then use: babycode.bat
📋 macOS PATH Setup (zsh)
# Quick setup (macOS default zsh)
echo ' export PATH="$HOME/.local/bin:$PATH"' >> ~ /.zshrc
source ~ /.zshrc
# Launch command
babycode-py
📋 Linux PATH Setup (bash)
# Quick setup
echo ' export PATH="$HOME/.local/bin:$PATH"' >> ~ /.bashrc
source ~ /.bashrc
# Launch command
babycode-py
🖥️ Rich Terminal UI — Alternate-screen TUI with panels, ANSI styling, smooth scrolling
🤖 Intelligent Agent Loop — Multi-turn tool use, auto-plan/execute/iterate
🛠️ 30+ Built-in Tools — File I/O, code search, shell, git, testing, and more
🔒 Permission System — Approve, deny, auto-allow tool calls
💾 Session Persistence — Save & resume conversations, 30s autosave
🧠 3-Tier Memory — Conversation → Session → Long-term memory
🔌 MCP Integration — Connect external Model Context Protocol servers
⌨️ Slash Commands — /help, /tools, /cost, /config, /context, /memory
Tool
Description
list_files
List directory contents with glob
grep_files
Regex search across files
read_file
Read file with line ranges
write_file
Create or overwrite files
edit_file / patch_file
Structured editing and patching
Tool
Description
find_symbols
AST-based symbol search (functions, classes)
find_references
Find all references to a symbol
code_review
Automated code quality analysis
Tool
Description
run_command
Execute shell commands with timeout
test_runner
Smart test discovery and execution
api_tester
HTTP API endpoint testing
Tool
Description
web_fetch
Fetch and extract web page content
web_search
Web search via API
Tool
Description
git
Git workflow (status, diff, log, commit)
docker_helper
Docker & Docker Compose management
db_explorer
SQLite database exploration & queries
Tool
Description
file_tree
Visual directory tree
diff_viewer
Rich diff visualization
notebook_edit
Jupyter notebook editing
todo_write
Task list management
ask_user
Prompt user for clarification
load_skill
Load domain-specific skills
~/.baby-code/settings.json:
Option 1: Anthropic API
{
"model" : " claude-sonnet-4-20250514" ,
"env" : {
"ANTHROPIC_BASE_URL" : " https://api.anthropic.com" ,
"ANTHROPIC_AUTH_TOKEN" : " your-token-here"
}
}
Option 2: OpenRouter
{
"model" : " anthropic/claude-sonnet-4" ,
"env" : {
"OPENROUTER_API_KEY" : " sk-or-..."
}
}
Variable
Description
Default
ANTHROPIC_API_KEY
Anthropic API key
—
ANTHROPIC_AUTH_TOKEN
Auth token (alternative)
—
ANTHROPIC_BASE_URL
API base URL
https://api.anthropic.com
ANTHROPIC_MODEL
Model name
—
OPENROUTER_API_KEY
OpenRouter API key
—
OPENAI_API_KEY
OpenAI API key
—
BABY_CODE_MODEL_MODE
Set to mock for testing
—
Command
Description
/help
Show available commands
/tools
List all tools
/cost
Show session cost
/config
Show configuration diagnostics
/context
Show context window usage
/memory
Show memory system status
/exit
Exit BabyCode
Key
Action
Enter
Submit input
Up/Down
Input history
PageUp/PageDown
Scroll transcript
Ctrl+C
Cancel operation
Ctrl+U
Clear input line
# Clone
git clone https://github.com/laojiahuo2003/BabyCode.git
cd BabyCode
# Run tests
pip install -e " .[dev]"
pytest
# Mock mode (no API key needed)
BABY_CODE_MODEL_MODE=mock python -m babycode.main
Metric
Value
Python files
69
Lines of code
~15,000
Built-in tools
30+
External dependencies
0
Optimizations
93+
Test pass rate
98.9%
Code readability
9/10
MIT — see LICENSE for details.