claw0: Building an AI Agent Gateway from Scratch, Section by Section
0 - 1 learn OpenClaw: sections to build an claw-AI agent from scratch
At a glance
- What is it?
- claw0 is a 10-section Python tutorial for building a production-grade AI agent gateway, where each section is a single runnable file that introduces exactly one new concept. It takes a reader from a bare while loop all the way through concurrent named-lane session handling, using Anthropic's API throughout.
- Who is it for?
- claw0 is a good match for engineers who understand basic Python and want a hands-on path through the internals of an AI agent gateway: session persistence, multi-channel routing, proactive heartbeats, and concurrent execution. Someone who only needs to call the Anthropic API once or twice will find it more than required.
- Can I use it commercially?
- Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
- Is it still maintained?
- Yes. The repository last received commits 91 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 29, 2026, and from our analysis. They are not legal advice.
Editorial analysis
What Problem claw0 Solves and Who It Targets
Most AI agent tutorials stop after a single API call. claw0 starts from that while loop and walks through 10 progressive concepts needed to run a production-grade agent gateway: session management, multi-channel routing, scheduled behavior, reliable message delivery, and concurrent execution. The README describes the audience as engineers who want to read OpenClaw's production codebase with confidence after completing all 10 sections. Each section is a standalone Python file, roughly 175 to 1130 lines, that compiles and runs as written. Prior knowledge required is basic Python; no Neovim plugins, no framework overhead. The repository is in three languages (English, Chinese, Japanese), with each language folder self-contained: the same Python logic runs in all three, with only comments and documentation translated.
The 10-Section Architecture and What Each Introduces
The README describes claw0's sections in five phases. Phase 1 (Foundation) is s01 and s02: s01 builds a bare agent loop on while True plus stop_reason; s02 adds tool use through a dispatch table where the model picks a name and the code looks it up. Phase 2 (Connectivity) covers s03 through s05: s03 adds JSONL session persistence with summarization when the context grows too large; s04 introduces Telegram and Feishu channel pipelines that normalize platform differences into a single InboundMessage; s05 adds WebSocket gateway routing with a 5-tier binding table. Phase 3 (Brain) is s06: an 8-layer prompt assembly system where the soul, memory, and skills are files on disk, making personality changes a file swap. Phase 4 (Autonomy) covers s07 and s08: s07 adds a heartbeat thread with a cron scheduler; s08 adds a write-ahead delivery queue with backoff so crashes do not lose messages. Phase 5 (Production) is s09 and s10: s09 wraps the whole system in a 3-layer retry onion for auth rotation and overflow compaction; s10 replaces a single lock with named FIFO lanes and generation tracking for concurrent sessions.
The README also lists the section dependency graph explicitly:
s01 --> s02 --> s03 --> s04 --> s05
| |
v v
s06 ----------> s07 --> s08
| |
v v
s09 ----------> s10Getting Started: Clone, Configure, and Run
The repository requires Python 3.11 or later and an Anthropic API key. The README gives these quick start steps:
git clone https://github.com/shareAI-lab/claw0.git && cd claw0
pip install -r requirements.txt
cp .env.example .envAfter copying .env.example to .env, set ANTHROPIC_API_KEY and MODEL_ID. The .env.example file uses claude-sonnet-4-20250514 as the example MODEL_ID but notes that any Anthropic-API-compatible provider (such as OpenRouter) can be used by setting ANTHROPIC_BASE_URL. Once the environment is configured, run any section by picking its language folder:
python sessions/en/s01_agent_loop.pyThe dependencies are listed in requirements.txt:
anthropic>=0.39.0
python-dotenv>=1.0.0
websockets>=12.0
croniter>=2.0.0
python-telegram-bot>=21.0
httpx>=0.27.0The channel-related packages (python-telegram-bot, websockets) are only needed from s04 onward. Sections s01 and s02 work with just the anthropic and python-dotenv packages installed. The optional Telegram and Feishu credentials in .env.example are only required for s04_channels.py.
How the Sections Stay Additive
A key design constraint in claw0 is that each section introduces exactly one new concept while keeping all prior code intact. This means s03 is not a rewrite of s02 but an extension: it takes the tool loop from s02 and wraps it with JSONL persistence and context summarization. The dependency graph in the README makes this explicit: s09 builds on both s03 and s06, reusing ContextGuard from s03 for overflow compaction and the model configuration from s06 for auth rotation. This additive structure means a reader can stop at any section and have a runnable, self-contained example of everything up to that point. It also means debugging is more tractable: a failure in s07 is likely a heartbeat or cron issue, not a regression in session handling. The tradeoff is that each later file is necessarily longer: s09 is approximately 1130 lines and s10 approximately 900, compared to s01's 175.
claw0 vs. learn-claude-code
The README describes learn-claude-code (also from shareAI-lab) as a companion repository. The distinction the README draws is direct: claw0 focuses on gateway routing, channels, and proactive behavior, while learn-claude-code dives into the agent's internal design. learn-claude-code covers structured planning with a TodoManager, context compression with a 3-layer compact approach, file-based task persistence with dependency graphs, team coordination with JSONL mailboxes, and git worktree isolation for parallel execution. In concrete terms, claw0 teaches how to receive a message from Telegram, route it to an agent, persist the session, and deliver the response reliably. learn-claude-code teaches how the agent itself decides what to do, manages subtasks, and coordinates with other agents. A reader wanting to understand both layers would need both repositories.
Limitations and What claw0 Does Not Cover
claw0 is a teaching repository, not a deployable framework. Each section is a single Python file, which means there is no package structure, no test suite, and no configuration management suitable for a real deployment without additional scaffolding. The README notes approximately 7000 lines of Python across all 10 sections, but that total is split across independent files, not a unified codebase. The Feishu integration in s04 requires valid Feishu app credentials, which are not trivially obtained outside China-region accounts. The repository has no GitHub releases. The last push was on 2026-06-30. The README does not document how to migrate state from one section to the next when a production deployment needs upgrading, since the progression is designed for learning rather than in-place upgrades.
Editorial conclusion
claw0 is a good match for engineers who understand basic Python and want a hands-on path through the internals of an AI agent gateway: session persistence, multi-channel routing, proactive heartbeats, and concurrent execution. Someone who only needs to call the Anthropic API once or twice will find it more than required. Before starting, verify that Python 3.11 or later is installed and that an Anthropic API key with sufficient quota is available, since every section makes live API calls.
Frequently asked questions
What does claw0 teach that a basic Anthropic API tutorial does not?
A basic API tutorial shows how to call the API once. claw0 adds session persistence with JSONL, multi-channel routing, a heartbeat scheduler, a write-ahead delivery queue, and named-lane concurrent execution. Each of these is a production concern that a one-call tutorial does not address.
Do I need to complete all 10 claw0 sections in sequence?
The README's dependency graph shows s01 and s02 as foundation sections with no prerequisites. Later sections build cumulatively: s09 requires understanding from both s03 and s06. A reader can stop at any section and have a complete, runnable example of the concepts covered up to that point.
Which AI providers does claw0 support beyond Anthropic?
The .env.example includes an optional ANTHROPIC_BASE_URL setting, with OpenRouter listed as an example of a compatible provider. Any API endpoint that accepts the same request format as Anthropic's Messages API can be used by setting that variable and a matching MODEL_ID.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/shareai-lab-claw0)