shareAI-lab/learn-claude-code

Bash is all you need - A nano claude code–like 「agent harness」, built from 0 to 1

Learn Claude Code – A Hands‑On Course for Building LLM Agent Harnesses

What it is – A step‑by‑step tutorial that shows you how to write the harness (the surrounding code) that lets a large language model such as Anthropic’s Claude act as an autonomous coding assistant. The repo does not train a model; it teaches you how to give a pre‑trained LLM the tools, permissions, context‑management, and orchestration it needs to operate safely and effectively in a real development environment.

Why it matters – Modern “AI agents” are essentially a trained model plus a runtime that connects the model to the world (file system, shell, browsers, APIs, etc.). Most public projects focus on the model itself, leaving the harness as an after‑thought. This repository flips that perspective and treats the harness as the core engineering problem, showing exactly how to implement each piece.

How it works – The core loop is a simple REPL:

while True:
    response = client.messages.create(model=MODEL, system=SYSTEM,
                                      messages=messages, tools=TOOLS)
    messages.append({"role": "assistant", "content": response.content})
    tool_calls = [b for b in response.content if b.type == "tool_use"]
    if not tool_calls:
        break                     # model decided it was done
    results = []
    for call in tool_calls:
        out = TOOL_HANDLERS[call.name](**call.input)
        results.append({"type": "tool_result",
                        "tool_use_id": call.id,
                        "content": out})
    messages.append({"role": "user", "content": results})

The model decides when to invoke a tool; the harness executes the tool and feeds the result back. The repository expands this loop across 17 progressive lessons, each adding a concrete harness feature:

Lesson Feature added What you learn
s01 Basic agent loop + Bash tool Minimal working agent
s02 Tool registration & dispatch Adding arbitrary tools
s03 Permission system Safe execution, approvals
s04 Hook system Extensible pre/post‑tool logic
s05 Todo‑write (planning) Model‑driven task planning
s06 Sub‑agent isolation Separate message contexts for sub‑tasks
s07 Skill loading On‑demand knowledge injection
s08 Context compaction Keeping token windows within limits
s09 Memory subsystem Persistent knowledge across sessions
s10 Disk‑backed task graph Structured, resumable worklists
s11 Background tasks Non‑blocking long‑running commands
s12 Cron scheduler Time‑based automation
s13 Agent teams Multi‑agent coordination, task claiming
s14 MCP plugin Plug‑in external capabilities as tools
s15 Integrated harness All prior mechanisms combined in one loop
s16 Workflow runtime Saved, resumable orchestration scripts
s17 Goal loop Independent evaluator decides when the agent should stop

Each lesson ships a small, runnable code.py plus a README (English, Chinese, Japanese) that explains the design, shows the implementation, and visualises the flow.

Who should use it

  • Harness engineers who already have access to an LLM API and want a production‑ready pattern for building agents.
  • Developers interested in turning Claude (or any compatible LLM) into a coding assistant that can read/write files, run shell commands, browse the web, or call custom APIs.
  • Researchers looking for a clean reference implementation of the “model + environment” paradigm.

What you get out of the repo

  • A complete, modular code base that can be copied into your own project.
  • Clear separation of concerns: tools, permissions, hooks, memory, task scheduling, and multi‑agent protocols are all independent modules.
  • A philosophy that agency comes from the model, not from clever prompt chaining, which helps avoid brittle “Rube‑Goldberg” agent hacks.

Bottom lineLearn Claude Code is not a new LLM; it is a practical curriculum that teaches you to build the vehicle for any LLM‑based agent, using Claude as the reference model. By the end of the 17 lessons you should be able to assemble a fully‑featured autonomous coding assistant—or adapt the patterns to other domains such as data analysis, web automation, or robotics.


Quick start checklist

  1. Get an Anthropic Claude API key (or adapt the client to another LLM that supports tool use).
  2. git clone https://github.com/shareAI-lab/learn-claude-code.git
  3. Install the minimal dependencies (usually just anthropic and standard library).
  4. Run python s01_agent_loop/code.py to see the simplest loop in action.
  5. Progress through the s02_…s17_… folders, adding the next mechanism each time.

All details above are taken directly from the repository’s README; no additional features have been inferred.

Related

  • Project
  • Project
  • Project
  • Dispatch
  • Dispatch