You don't need to be a programmer to understand this. We'll start with plain English, build up to pseudocode, and then look at only the ~20 lines of real code that matter. By the end, you'll understand how NanoClaw works — and you'll realize you could build one yourself.
Forget code for a moment. An AI agent is structured exactly like a small company with three departments. NanoClaw has just 3 important files — and each one maps to a department.
Receives requests, decides what to do, delegates work, and delivers the final answer. Runs the whole show.
Connects the CEO to the outside world. Need to send a message? Schedule a meeting? Make the call through here.
Stores every conversation, every decision, every piece of context. So the CEO remembers what happened yesterday.
If a customer sends a WhatsApp message and the agent needs to look up their order history before replying — which "departments" are involved?
Every AI agent in the world — from NanoClaw to ChatGPT to enterprise systems — follows this same 4-step loop. Once you see it, you'll recognize it everywhere.
Someone sends a WhatsApp message. NanoClaw checks: "Is this message for me?" (Does it match the trigger word?)
The message + conversation history gets sent to Claude. Claude decides: "Do I need a tool, or can I just answer?"
If Claude needs to take action — send a message, check a schedule — it calls a tool. Then loops back to step 2 with the result.
Once Claude has everything it needs, it crafts a clear answer and sends it back through WhatsApp.
That's it. That's the entire pattern. Now let's see it as pseudocode.
Before we look at real code, here's the entire agent written in plain English that looks like code. This is called "pseudocode" — it's how programmers plan before they write.
Read that again. That's the entire NanoClaw agent. 12 lines of logic. Everything else is just the TypeScript syntax to express this same logic.
Look at lines 5-6 in the pseudocode. Why would NanoClaw skip messages that don't have a trigger word?
Now the fun part. Below is NanoClaw's actual code — but we've dimmed everything except the key lines. Your job: match each highlighted line back to the pseudocode you just read. The grey lines are just syntax details — ignore them.
This is the main file. It runs the loop from the pseudocode — check for messages, think, respond. Only 6 lines matter. The rest is plumbing.
Look at line 33: db.getNewMessages(lastTs). The db part refers to which "department" of our company?
db. prefix means "go to the database file and run this function." It's like the CEO walking over to the filing cabinet and saying "get me all the new messages since the last time I checked."
This file defines the tools the AI agent can use. Remember the Colab notebook where you gave Claude a calculator? Same idea — but NanoClaw's tools send real WhatsApp messages and schedule real tasks.
Look at line 6: the description says 'Send a message to a WhatsApp chat'. Who reads this description — a human or the AI?
send_message — it sends messages to WhatsApp chats, which is what the user wants." This is why good descriptions matter. The AI is literally reasoning about which tool fits the task.
Without memory, every conversation starts from zero. The filing cabinet stores messages, groups, and sessions so the agent remembers what happened before. It uses SQLite — a simple database stored in a single file on disk.
saveMessage puts a message in the cabinet. getMessagesSince retrieves conversation history. getNewMessages checks for messages the agent hasn't seen yet. The SQL commands (INSERT, SELECT) are how you talk to databases — you'll learn more about these in future sessions.
Why does getMessagesSince need a chatJid parameter? Why not just get ALL messages?
chatJid is like a folder label — it says "only get messages from THIS specific group chat." Good memory isn't just remembering everything — it's remembering the right things.
Let's trace a real scenario through all three files. Someone in a WhatsApp group types: "@claw remind me to submit the report at 5pm"
Three files. One loop. Real-world action.
That's the entire architecture of a production AI agent.
You can read production AI code. NanoClaw has 10,500+ GitHub stars — and you just understood how it works. Not by memorizing syntax, but by understanding the architecture: a CEO that runs the loop, a phone system that provides tools, and a filing cabinet that stores memory.
The gap is smaller than you think. Your Colab notebook was ~50 lines. NanoClaw is ~700. The only difference is that NanoClaw connects to WhatsApp instead of a Python prompt, and uses real tools instead of a calculator. The pattern is identical.
Simplicity wins. NanoClaw beat a 400,000-line competitor with 700 lines. In business and in code, the simplest solution that works is usually the best one.
Want to go deeper? Check out the full code walkthrough with every file and all 700 lines annotated.