← d3dev

NanoClaw Architecture Deep Dive

NanoClaw Architecture Deep Dive

Metadata

FieldValue
Linkhttps://github.com/qwibitai/nanoclaw
TitleNanoClaw — Lightweight Personal Claude Assistant
SourceGitHub (qwibitai/nanoclaw)
Tagsai-agents, architecture, containers, security, claude-code, whatsapp, ipc, skills, agent-swarms
Date Downloaded2026-02-25
Stars14,553
LanguageTypeScript
Created2026-01-31

Sam's TLDR;

NanoClaw is a lightweight alternative to OpenClaw that runs Claude Code agents inside isolated Linux containers (Docker or Apple Container). Single Node.js process, ~15 source files, SQLite for state, WhatsApp as the primary I/O channel. Each chat group gets its own sandboxed filesystem, memory (CLAUDE.md), and IPC namespace. The key innovation is "skills over features" — instead of bloating the codebase, contributors write SKILL.md files that teach Claude Code how to transform your fork. 14.5K stars in under a month. The architecture is directly relevant to what we're building with samir-bot.

Key Points

Full Summary

Architecture Overview

``

WhatsApp (baileys) --> SQLite --> Polling loop --> Container (Claude Agent SDK) --> Response

`

NanoClaw is a single Node.js process that bridges messaging platforms to Claude Code agents running in containers. The data flow is:

  • Inbound: WhatsApp message arrives via baileys library
  • Storage: Message stored in SQLite with chat/group metadata
  • Polling: Main loop polls for new messages every few seconds
  • Routing: Messages grouped by chat JID, trigger word checked for non-main groups
  • Queuing: GroupQueue manages concurrency — max N containers at once
  • Container: Docker/Apple Container spawned with isolated mounts
  • Execution: Claude Agent SDK runs inside the container with the formatted prompt
  • Streaming: Output streamed back via sentinel markers in stdout
  • IPC: Container can send messages, schedule tasks, register groups via filesystem IPC
  • Response: Formatted output sent back to WhatsApp
  • Key Source Files

    FileSizePurpose
    src/index.ts15.7KOrchestrator — state management, message loop, agent invocation
    src/container-runner.ts20.5KContainer lifecycle — mount building, spawning, output parsing
    src/db.ts18.9KSQLite operations — messages, groups, sessions, tasks
    src/ipc.ts12.2KIPC watcher — filesystem-based communication between containers and host
    src/group-queue.ts10.2KConcurrency control — per-group queuing, retries, idle management
    src/mount-security.ts10.6KMount validation — allowlist enforcement, path traversal prevention
    src/task-scheduler.ts7.2KScheduled task execution — cron, interval, one-shot
    src/types.ts3.1KType definitions — RegisteredGroup, Channel, NewMessage, etc.

    Security Model

    The security architecture is container-first, not permission-first:

    Skills System

    The most architecturally interesting decision: no feature PRs. Instead:

  • Contributors create SKILL.md files in .claude/skills/
  • Each skill teaches Claude Code how to transform the codebase
  • Users run /add-telegram (for example) and Claude Code modifies their fork
  • Result: clean, tailored code — not a bloated system with every feature
  • The skills-engine/ directory handles the lifecycle:

    Comparison to Our Architecture (samir-bot)

    AspectNanoClawsamir-bot
    RuntimeSingle Node.js processSingle Express server
    DatabaseSQLiteMongoDB + PostgreSQL + Redis
    Agent executionClaude Code in containersCursor CLI agents
    I/O ChannelWhatsApp (primary)Slack + Dashboard UI
    MemoryCLAUDE.md per groupSOUL.md + MongoDB everything_log
    SkillsSKILL.md (Claude Code transforms)Script-based skills in skills/
    Task queueSQLite + GroupQueue classMongoDB + orchestrator scripts
    SecurityContainer isolationTrust-based (same process)
    ConcurrencyContainer pool with limitsSequential (planning for parallel)

    Ideas Worth Stealing

  • Container isolation for agent execution — We could run sub-agents in containers instead of trusting them in-process
  • Skills-as-transformations — Instead of adding features, teach the agent how to modify itself
  • Per-group/context isolation — Each conversation context gets its own filesystem and memory
  • IPC via filesystem — Simple, debuggable, no socket complexity
  • Mount security allowlists — External config that agents can't tamper with
  • Idle timeout + container reaping — Containers stay alive for follow-up messages, then auto-cleanup
  • Skills engine with rollback — Backup before applying changes, ability to uninstall
  • Dependencies

    Remarkably lean — only 8 runtime dependencies:

    PackagePurpose
    @whiskeysockets/baileysWhatsApp Web API
    better-sqlite3SQLite driver
    cron-parserCron expression parsing for scheduled tasks
    pino + pino-prettyStructured logging
    qrcode + qrcode-terminalWhatsApp QR auth
    yamlYAML parsing
    zod`Schema validation