# Build Your Own OpenClaw

czl9707's `build-your-own-openclaw` is a Python tutorial that constructs a Claude Code-style coding agent from scratch in 18 numbered steps, grouped into four phases. The name is a pun — OpenClaw is what you get when you're allowed to say "Claude Code" sideways. MIT-licensed, 917 stars as of April 2026, no published releases (the tutorial *is* the artifact). A reference implementation called `pickle-bot` ships alongside and demonstrates the final shape.

The progression is pedagogically deliberate: each step adds one concept, and the order matches the historical order in which real coding agents grew complex. If you want to understand why Claude Code, [[pi-coding-agent]], Cursor, and their peers converged on similar architectures, this is the cheapest way to walk the path end to end.

## Phase 1 — Single agent capability (steps 0-6)

The minimum viable coding agent. Starts with a bare chat loop, then layers in:

- **Tool calls** — the LLM can request actions (read file, run command) and get results back
- **Skill extension via documentation** — loading markdown skill files at startup so the agent can learn new capabilities without code changes (this is the same pattern Claude Code uses for skills)
- **Conversation persistence** — sessions survive restarts
- **User commands** — slash commands, interrupts, manual steering
- **History compaction** — summarizing old turns when the context window fills, a load-bearing technique for any long session
- **Web access** — adding a fetch tool so the agent can read URLs

By the end of Phase 1 you have something that resembles Claude Code in its simplest form: a REPL with tools and a growing toolbox of skills.

## Phase 2 — Event architecture (steps 7-10)

Rewrites the agent as an event-driven service. This is the architectural jump from "a Python script you run in a terminal" to "a process that stays up and accepts work from multiple sources." Steps cover:

- An internal event system
- Config hot-reload (edit the config file, the agent picks it up without a restart)
- Multi-channel support (one agent instance reachable from CLI, Slack, Telegram, etc., simultaneously)
- WebSocket integration for real-time frontends

## Phase 3 — Autonomous and collaborative (steps 11-15)

The agent gains the ability to initiate work on its own and to hand off to other agents:

- Intelligent routing — deciding which sub-agent should handle a given request
- Cron-scheduled tasks — the agent runs jobs on a timer, not just on user prompts
- Multi-layer prompting — layering system prompts, skill prompts, task prompts
- Bidirectional messaging — the agent can message users, not just respond
- Agent-to-agent dispatch — spawning and coordinating other agents

This phase is where multi-agent coordination starts looking like a real distributed systems problem, which is exactly the territory [[log-distributed-llms]] warns about. Building it by hand is a good way to feel the FLP/Byzantine corners in practice.

## Phase 4 — Production readiness (steps 16-17)

Concurrency management and persistent memory. The tutorial doesn't go deep on infrastructure, but it covers the basic shape: what changes when multiple users hit the same agent at once, and how memory spans sessions without exploding the context window. [[hippo-memory]] and [[mempalace]] are both deeper takes on the persistent memory problem.

## Tech notes

The project uses LiteLLM for provider abstraction, so the same agent code runs against Anthropic, OpenAI, local models, or anything else LiteLLM supports. This keeps the tutorial model-agnostic — the point is the architecture, not which LLM is behind it.

## Where this fits

For someone who already uses Claude Code, the value of this tutorial isn't learning *how to use* an agent — it's seeing the skeleton underneath one. Each phase maps directly to features you already interact with daily:

- Phase 1 → the basic loop, tools, skills, session files
- Phase 2 → hooks, the MCP surface, multi-surface reach
- Phase 3 → subagents, scheduled tasks, the Task tool
- Phase 4 → background processes, persistent memory across sessions

Closest cousins in the wiki: [[pi-coding-agent]] (a minimal terminal coding agent — smaller scope, similar philosophy), [[agent-reading-test]] (benchmark for whether agents can read docs), [[chiasmus]] (MCP server adding formal tools), [[hippo-memory]] / [[mempalace]] (the memory side of Phase 4), [[botctl]] (a production-grade process manager for the kind of agent this tutorial teaches you to build).
