Code Lib / 代码库
更新于 a month ago

learn-claude-code

SshareAI-lab
15.3k
shareai-lab/learn-claude-code
88
Agent 评分

💡 摘要

一个教育性代码库,提供从最小化的bash工具到完整技能系统的渐进式、实践性AI编码智能体构建教程。

🎯 适合人群

AI智能体开发者机器学习工程学生技术教育者开源贡献者AI工具产品经理

🤖 AI 吐槽:一个终于承认自己过去错误的教程比大多数都诚实,但仍然忍不住使用经典的'一个奇怪循环'过度简化。

安全分析中风险

代码通过bash工具执行shell命令,如果智能体被误导,将带来任意代码执行的高风险。它还加载外部技能和依赖项,引入了供应链风险。缓解措施:为shell命令实施严格的允许列表和沙箱执行,并在安装前审查所有外部技能来源。

Learn Claude Code - Bash is all you & agent need

Python 3.10+ Tests License: MIT

Disclaimer: This is an independent educational project by shareAI Lab. It is not affiliated with, endorsed by, or sponsored by Anthropic. "Claude Code" is a trademark of Anthropic.

Learn how modern AI agents work by building one from scratch.

Chinese / 中文 | Japanese / 日本語


Why This Repository?

We created this repository out of admiration for Claude Code - what we believe to be the most capable AI coding agent in the world. Initially, we attempted to reverse-engineer its design through behavioral observation and speculation. The analysis we published was riddled with inaccuracies, unfounded guesses, and technical errors. We deeply apologize to the Claude Code team and anyone who was misled by that content.

Over the past six months, through building and iterating on real agent systems, our understanding of "what makes a true AI agent" has been fundamentally reshaped. We'd like to share these insights with you. All previous speculative content has been removed and replaced with original educational material.


Works with Kode CLI, Claude Code, Cursor, and any agent supporting the Agent Skills Spec.

What You'll Learn

After completing this tutorial, you will understand:

  • The Agent Loop - The surprisingly simple pattern behind all AI coding agents
  • Tool Design - How to give AI models the ability to interact with the real world
  • Explicit Planning - Using constraints to make AI behavior predictable
  • Context Management - Keeping agent memory clean through subagent isolation
  • Knowledge Injection - Loading domain expertise on-demand without retraining

Learning Path

Start Here
    |
    v
[v0: Bash Agent] -----> "One tool is enough"
    |                    16-50 lines
    v
[v1: Basic Agent] ----> "The complete agent pattern"
    |                    4 tools, ~200 lines
    v
[v2: Todo Agent] -----> "Make plans explicit"
    |                    +TodoManager, ~300 lines
    v
[v3: Subagent] -------> "Divide and conquer"
    |                    +Task tool, ~450 lines
    v
[v4: Skills Agent] ---> "Domain expertise on-demand"
                         +Skill tool, ~550 lines

Recommended approach:

  1. Read and run v0 first - understand the core loop
  2. Compare v0 and v1 - see how tools evolve
  3. Study v2 for planning patterns
  4. Explore v3 for complex task decomposition
  5. Master v4 for building extensible agents

Quick Start

# Clone the repository git clone https://github.com/shareAI-lab/learn-claude-code cd learn-claude-code # Install dependencies pip install -r requirements.txt # Configure API key cp .env.example .env # Edit .env with your ANTHROPIC_API_KEY # Run any version python v0_bash_agent.py # Minimal (start here!) python v1_basic_agent.py # Core agent loop python v2_todo_agent.py # + Todo planning python v3_subagent.py # + Subagents python v4_skills_agent.py # + Skills

The Core Pattern

Every coding agent is just this loop:

while True: response = model(messages, tools) if response.stop_reason != "tool_use": return response.text results = execute(response.tool_calls) messages.append(results)

That's it. The model calls tools until done. Everything else is refinement.

Version Comparison

| Version | Lines | Tools | Core Addition | Key Insight | |---------|-------|-------|---------------|-------------| | v0 | ~50 | bash | Recursive subagents | One tool is enough | | v1 | ~200 | bash, read, write, edit | Core loop | Model as Agent | | v2 | ~300 | +TodoWrite | Explicit planning | Constraints enable complexity | | v3 | ~450 | +Task | Context isolation | Clean context = better results | | v4 | ~550 | +Skill | Knowledge loading | Expertise without retraining |

File Structure

learn-claude-code/
├── v0_bash_agent.py       # ~50 lines: 1 tool, recursive subagents
├── v0_bash_agent_mini.py  # ~16 lines: extreme compression
├── v1_basic_agent.py      # ~200 lines: 4 tools, core loop
├── v2_todo_agent.py       # ~300 lines: + TodoManager
├── v3_subagent.py         # ~450 lines: + Task tool, agent registry
├── v4_skills_agent.py     # ~550 lines: + Skill tool, SkillLoader
├── skills/                # Example skills (pdf, code-review, mcp-builder, agent-builder)
├── docs/                  # Technical documentation (EN + ZH + JA)
├── articles/              # Blog-style articles (ZH)
└── tests/                 # Unit and integration tests

Documentation

Technical Tutorials (docs/)

Articles

See articles/ for blog-style explanations.

Using the Skills System

Example Skills Included

| Skill | Purpose | |-------|---------| | agent-builder | Meta-skill: how to build agents | | code-review | Systematic code review methodology | | pdf | PDF manipulation patterns | | mcp-builder | MCP server development |

Scaffold a New Agent

# Use the agent-builder skill to create a new project python skills/agent-builder/scripts/init_agent.py my-agent # Specify complexity level python skills/agent-builder/scripts/init_agent.py my-agent --level 0 # Minimal python skills/agent-builder/scripts/init_agent.py my-agent --level 1 # 4 tools

Install Skills for Production

# Kode CLI (recommended) kode plugins install https://github.com/shareAI-lab/shareAI-skills # Claude Code claude plugins install https://github.com/shareAI-lab/shareAI-skills

Configuration

# .env file options ANTHROPIC_API_KEY=sk-ant-xxx # Required: Your API key ANTHROPIC_BASE_URL=https://... # Optional: For API proxies MODEL_ID=claude-sonnet-4-5-20250929 # Optional: Model selection

Related Projects

| Repository | Description | |------------|-------------| | Kode | Production-ready open source agent CLI | | shareAI-skills | Production skills collection | | Agent Skills Spec | Official specification |

Philosophy

The model is 80%. Code is 20%.

Modern agents like Kode and Claude Code work not because of clever engineering, but because the model is trained to be an agent. Our job is to give it tools and stay out of the way.

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

  • Add new example skills in skills/
  • Improve documentation in docs/
  • Report bugs or suggest features via Issues

License

MIT


Model as Agent. That's the whole secret.

@baicai003 | shareAI Lab

五维分析
清晰度9/10
创新性7/10
实用性9/10
完整性10/10
可维护性9/10
优缺点分析

优点

  • 从简单到复杂的清晰、渐进式学习路径。
  • 结构良好的代码示例和版本对比。
  • 包含实用技能和生产环境集成指南。
  • 强调核心概念而非炒作。

缺点

  • 新颖性有限,主要教授既定模式。
  • 需要外部API密钥和设置,并非完全自包含。
  • 后期版本的复杂性可能让纯新手不知所措。
  • 依赖于对引用的Agent Skills Spec的理解。

相关技能

mcp-builder

S
toolCode Lib / 代码库
90/ 100

“这份指南详尽到可能教会 AI 自己编写 MCP 服务器,从而让你失业。”

connect

A
toolAuto-Pilot / 全自动
86/ 100

“这是终极的'我来替你干'技能,把 Claude 从一个深思熟虑的顾问变成了一个能访问你所有账户的、过度热切的实习生。”

langsmith-fetch

A
toolCo-Pilot / 辅助式
86/ 100

“这是你 AI 智能体的绝佳调试器,前提是你的智能体犯的第一个错误不是忘了启用追踪。”

免责声明:本内容来源于 GitHub 开源项目,仅供展示和评分分析使用。

版权归原作者所有 shareAI-lab.