openclaw-mini: a teaching rebuild of the OpenClaw agent kernel
A minimal reimplementation of OpenClaw's core architecture, covering sessionKey session scoping, serial queueing, tool-based memory retrieval, on-demand context loading, extensible skills and a proactive heartbeat wake mechanism
At a glance
- What is it?
- OpenClaw is described as an agent system of more than 430,000 lines. openclaw-mini extracts the parts worth understanding: a two-layer agent loop behind an event stream, JSONL session persistence that writes nothing until the first assistant message, three stages of context reduction and a WebSocket gateway with six RPC methods.
- Who is it for?
- openclaw-mini fits a developer who has read one agent-loop tutorial and suspects there is more to it, because the value here is the mapping between each small file and the corresponding file in the full system. It does not fit production use, since the project says so itself: no API compatibility with the main repository, no channel or provider coverage, and the memory layer is keyword scoring rather than semantic search.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 178 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- voocel/openclaw-mini704 ★ · +5
| Repository | 2026-09-10 | 2026-11-25 |
|---|---|---|
| voocel/openclaw-mini | 699 | 704 |
5 Stars in the last 76 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Four layers, and a reading order that starts with the kernel
The project states its aims as clearly as its limits. It wants to explain the design points that matter in the OpenClaw kernel with one small complete project, let a reader follow five lines at once, the CLI, the agent loop, the session, the context and the gateway, and keep the comments explaining why a thing is built that way rather than only supplying code that runs.
The non-goals are just as explicit: no attempt at one-to-one API compatibility with the OpenClaw repository, no coverage of every channel, provider, plugin and operational capability, and no attempt to carry over every production guard, permission and compatibility detail.
Getting it running is three commands, and the environment file is part of the reading material because every line in it is commented out and documents the choices:
git clone [email protected]:voocel/openclaw-mini.git
cd openclaw-mini
pnpm install
cp .env.example .envThe provider variable accepts a list including anthropic, openai, google, groq, xai and openrouter, the model has to match the provider, the base URL covers proxies, self-hosted endpoints and Azure OpenAI, and API keys can be given under the provider's own standard variable name. An agent identifier defaults to `main`, which is the first half of the session key format.
The code is then sorted into four layers with a suggested order, core, extension, gateway, engineering. The core layer is marked must-read and pairs every file with its counterpart in the real system: `agent.ts` against `agent.js`, `agent-loop.ts` against `agent-loop.js`, `session.ts` against `session-manager.ts`, `context/loader.ts` against `bootstrap-files.ts`, and so on. That pairing is the actual teaching device, and it is why the tables are worth more than the snippets.
The agent loop is two loops behind one stream
The stated problem is that a simple while loop cannot handle follow-ups, steering injection or context overflow. The answer is an outer loop and an inner loop wrapped in an event stream, and the stream is the return value rather than a side channel, so the caller consumes it with a for-await loop.
The outer loop exists for continuation: when the model ends a turn or wants a tool, the loop runs again. The inner loop handles tool execution and steering injection, where a steering message arrives mid-run and is folded into the turn in progress. Events are pushed as they happen, including tool execution start, and the stream is ended with the text, the turn count and the tool call count.
Subscription is deliberately aligned with the real package's `Agent.subscribe`, and the three events used in the example are message deltas for streaming text, tool execution start for the tool name and arguments, and agent errors. Returning a stream rather than a result is what lets a UI render progress without knowing anything about the loop.
Sessions touch the disk only after the first assistant message
The session manager answers the question of what happens after a restart, and the answer is JSONL with a deliberate write policy. The append path updates an in-memory cache first, so reads cost no I/O, and only then considers the file.
The first disk write is deferred until an assistant message actually arrives. Before that point the session is not written at all, which is the comment's stated reason: an empty session on disk is worse than no session. The first write rewrites the whole file with its header and entries, and every later write appends a single line, which is O(1).
Two robustness details follow from the format. Each line is one entry, so a corrupted line is skipped without taking the rest of the file with it, and a write lock keeps concurrent appends from interleaving. For a teaching project this is the cheapest useful lesson in persistence: the caching decision, the first-write rule and the append rule are three separate choices, and only the third is obvious.
Context shrinks in three stages, and one of them asks the model first
The context problem is a finite window, and the strategy is three stages rather than one. Pruning drops old tool results while keeping the most recent N in full. Compaction, past a threshold, compresses older messages into a summary of the history. Bootstrap loads configuration files such as `AGENTS.md` on demand, and truncates a very long file by taking its head and tail rather than skipping it.
The ordering that matters is the one the README insists on: compaction is lossy, so before the trigger fires there is a memory flush. The model is asked to write whatever is worth keeping into long-term memory first, and only then is the history compressed. Losing detail is accepted; losing the decision to remember it first is not.
Each stage maps to a file and a counterpart in the real system, `context/pruning.ts` against the pruner module and `context/compaction.ts` against compaction, which is what makes the progression legible rather than a single blob of heuristics.
Memory here is keyword scoring, not vector search
The extension layer's memory module is a search function you can read in one screen. It lowercases the query, splits it into terms, and for every stored entry adds one point for each term found in the entry text and half a point for each term matching a tag. There is no embedding, no decay and no time weighting.
The README is direct about the gap. The full system uses SQLite-vec for vector semantic search combined with BM25 keyword search, and this project reduces that to pure keyword relevance without time decay. So an older entry scores exactly like a newer one with the same words, which is fine for a demonstration and wrong for a memory that has to stay useful over months.
The other two extension modules are the skill system, which reads SKILL.md frontmatter and matches trigger words, and the heartbeat, which has two layers, a wake request merge stage and a runner scheduling stage, so several wake signals collapse into one run.
The gateway adds a protocol, six methods and a reconnecting client
The gateway layer is what turns an agent attached to a terminal into a network service, and it is the part the README marks as advanced but required reading. The protocol module defines three frame types, request, response and event, plus error codes and constants. The server is the substantial piece: an HTTP and WebSocket service with a challenge handshake, method routing, publish and subscribe broadcast, backpressure control and graceful shutdown.
The handler surface is six RPC methods, connect, chat send, chat history, the session methods and health. The client mirrors what you would expect from a resilient socket, a pending map for in-flight requests, exponential backoff reconnect, a tick heartbeat monitor and sequence gap detection so a dropped frame is noticed rather than silently tolerated. A CLI entry runs in two modes, serve and connect.
The quick example, `pnpm example:gateway`, exists to show the acknowledgement-then-stream sequence, which is the part that is hard to infer from the type signatures.
Three runtime dependencies, one npm script and a version behind the tag
The dependency list is three packages. `pi-ai` is pinned to an exact version, 0.50.7, and it is where the multi-provider adaptation comes from, so the claim of twenty-odd providers is inherited rather than implemented here. `grammy` is the Telegram bot framework, which is the one channel the scripts expose through a dedicated command. `ws` is the WebSocket library behind the gateway. Development adds `tsx` and TypeScript types.
The scripts mix package managers in a way worth knowing. Every command in the documentation runs through pnpm, and the lockfile is a pnpm one, but `prepack` and `pack:check` call npm directly, with prepack running the build first and the check being a dry-run pack.
The manifest version is 0.1.0 while the newest release is v0.1.1, both published on 2026-05-31 about an hour apart, and the last push carries that same timestamp. So the tag and the branch agree and the manifest is one patch behind.
The published file list includes a `workspace-templates/` directory that the visible documentation never explains, which is one of the first places to look when you are trying to work out how a session workspace is meant to be laid out.
Editorial conclusion
openclaw-mini fits a developer who has read one agent-loop tutorial and suspects there is more to it, because the value here is the mapping between each small file and the corresponding file in the full system. It does not fit production use, since the project says so itself: no API compatibility with the main repository, no channel or provider coverage, and the memory layer is keyword scoring rather than semantic search. Before you build on it, read the four layer tables in order, treat the manifest version as behind the released tag, and remember the pre-publish scripts run npm while every documented command runs pnpm.
Frequently asked questions
What is openclaw-mini?
A minimal reproduction of the OpenClaw agent architecture in TypeScript, written so a reader can follow the CLI, agent loop, session, context and gateway lines at once. It does not aim for API compatibility with the OpenClaw repository and drops most channels, providers and production guard details.
How do I run openclaw-mini?
Clone the repository, run `pnpm install`, copy `.env.example` to `.env` and set at least one model key, then run `pnpm test` and `pnpm dev`. `pnpm example:gateway` runs the round-trip example that shows the gateway's acknowledge-then-stream path.
How does openclaw-mini store conversations?
As JSONL, one entry per line, with corrupted lines skipped. A dual-write strategy updates an in-memory cache immediately and writes to disk only after the first assistant message, then appends single lines in O(1), with a write lock guarding concurrent writes.
What are openclaw-mini's dependencies?
Three runtime packages: pi-ai pinned at 0.50.7 for the multi-provider layer, grammy for the Telegram channel and ws for the WebSocket gateway. Development adds tsx and TypeScript type packages, and the provider and model are configured through environment variables.
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/voocel-openclaw-mini)Star history chart for your README
[](https://hysenlabs.com/projects/voocel-openclaw-mini)Was this useful?