engineering deep-dive

How NanoClaw Builds a Complete AI Assistant in 500 Lines with Claude Agent SDK

NanoClaws.io

NanoClaws.io

@nanoclaws

February 26, 2026

8 min read

How NanoClaw Builds a Complete AI Assistant in 500 Lines with Claude Agent SDK

There's a moment in every software project where you realize you've been building the wrong thing. You've spent weeks writing a message router, a tool execution engine, a conversation state manager, and a retry system — and then you discover that the AI provider already handles all of it, better than you could, as a single API call.

That moment is what led to NanoClaw's architecture. The entire core — the part that turns a WhatsApp message into an AI agent response with tool use, web browsing, file access, and multi-turn conversation — is roughly 500 lines of TypeScript. Not 500 lines of glue code that imports 50,000 lines of framework. Five hundred lines, total, built on top of Anthropic's Claude Agent SDK.

The reaction from developers who read the source for the first time is usually disbelief, followed by the question that matters: "Where's the rest of it?"

What Claude Agent SDK Actually Does

Most AI agent frameworks exist because, historically, language model APIs were stateless and simple. You sent a prompt, you got a response. If you wanted tool use, you had to build the tool execution loop yourself. If you wanted multi-turn conversation, you had to manage the message history yourself. If you wanted the model to decide between multiple tools, you had to build the routing logic yourself.

Claude Agent SDK changes that equation fundamentally. The SDK doesn't just call the Claude API — it runs an agent loop. You give it a system prompt, a set of tools, and a user message. The SDK handles everything else: it sends the message to Claude, receives the response, checks if Claude wants to use a tool, executes the tool, sends the result back to Claude, and repeats until Claude produces a final response. The entire tool-use loop — the thing that most frameworks spend thousands of lines implementing — is a single function call.

This isn't a thin wrapper. The SDK handles streaming, retry logic, token counting, and conversation state. It manages the back-and-forth between Claude and tools across multiple turns, handling edge cases like tool execution failures and context window limits. The complexity that NanoClaw doesn't need to implement isn't missing — it's been pushed down into a well-tested SDK maintained by Anthropic's own engineering team.

What NanoClaw Actually Builds

If the SDK handles the agent loop, what does NanoClaw's 500 lines actually do? The answer is everything around the loop — the parts that are specific to running a personal AI assistant rather than just calling an API.

The first responsibility is channel integration. NanoClaw connects to WhatsApp via the Baileys library, receives messages, and routes them to the right agent container. This is the glue between "someone sent a message on WhatsApp" and "an agent needs to process this message." It's not complicated code, but it's essential code — without it, the agent has no way to reach users where they already are.

The second responsibility is container orchestration. Every agent conversation runs inside its own Linux container — Apple Container on macOS, Docker on Linux. NanoClaw spawns containers, mounts the right directories, passes secrets via stdin, and collects responses. This is the security boundary that prevents a compromised agent from accessing anything outside its sandbox. The container lifecycle management is maybe 80 lines of code, but those 80 lines are the difference between an agent that can be trusted with real credentials and one that can't.

The third responsibility is persistent memory. NanoClaw maintains a SQLite database of conversations, group state, and scheduled tasks. Each WhatsApp group gets its own CLAUDE.md file that serves as the agent's long-term memory for that group. The memory system is simple — intentionally so — because the complex part of memory (deciding what's relevant, what to recall, how to use context) is handled by Claude itself.

The fourth responsibility is scheduled tasks. Users can ask the agent to do things at specific times — "remind me at 3pm" or "check this website every morning." NanoClaw's cron-like scheduler triggers agent containers at the right times, which is a small but genuinely useful feature that turns a reactive chatbot into a proactive assistant.

Why 500 Lines Matters

The line count isn't a vanity metric. It's a direct measure of the maintenance surface, the bug surface, and the cognitive load required to understand the system.

When a bug appears in NanoClaw's core, there are 500 lines where it could live. A developer can read the entire codebase in under an hour and understand every decision that was made. Compare that to frameworks with 50,000 lines of core code — finding a bug means navigating abstractions, understanding plugin systems, and tracing execution through layers of indirection that exist to support features you might not even use.

The security implications are equally concrete. Every line of code is a potential vulnerability. NanoClaw's 500-line core has a smaller attack surface than most framework's configuration parsers. The container isolation, the stdin secret passing, the mount allowlists — these security features are implemented in code that's small enough to audit completely in an afternoon.

And the upgrade story is simple. When Anthropic releases a new version of Claude Agent SDK with better tool use, or faster streaming, or new capabilities, NanoClaw gets those improvements by updating a single dependency. There's no framework abstraction layer that needs to be updated to expose new SDK features. The SDK is the framework.

The Philosophy of Not Building

The hardest part of NanoClaw's architecture wasn't building it — it was deciding what not to build. The temptation to add a custom tool execution engine, a sophisticated memory retrieval system, a multi-provider abstraction layer, a plugin marketplace — these are all things that other frameworks have built, and they're all things that NanoClaw deliberately doesn't have.

Each one of those features would add thousands of lines of code, dozens of potential bugs, and weeks of maintenance burden. And each one would duplicate functionality that either Claude Agent SDK already provides or that Claude itself handles better than any hand-written code could.

The result is a project where the interesting decisions are architectural, not implementational. How should containers be isolated? How should secrets be passed? How should memory be scoped per group? These are the questions that matter for a personal AI assistant, and they're the questions that NanoClaw's 500 lines are dedicated to answering.

The next time you evaluate an AI agent framework, don't count features. Count lines. The framework with the fewest lines isn't the least capable — it might be the one that understood the problem well enough to let the AI provider do the heavy lifting.

Stay in the Loop

Get updates on new releases, integrations, and NanoClaw development. No spam, unsubscribe anytime.