Skip to main content

A lightweight, memory-first, Nostr-primary personal AI assistant

Project description

๐Ÿฆ€ HermitCrab

Your local, private AI companion that actually remembers โ€” and gets better over time

PyPI version Python โ‰ฅ3.11 MIT License

Current release line: 0.1.0b3 beta

This is the current beta line: usable, local-first, and already good for real daily workflows, with beta3 focused on modern Nostr DMs, owner-managed workspace routing, clearer operator diagnostics, and stronger permission/audit surfaces.

What is HermitCrab, really?

HermitCrab is a personal AI agent you run on your own machine.
Itโ€™s not another cloud wrapper, not a bloated framework, not yet another SaaS subscription trap.

Itโ€™s lean, readable, auditable, and built around one simple idea:
Your AI should remember what matters to you โ€” forever โ€” without turning into a black box.

Think of it as a second brain you can carry in your pocket (or copy to a new laptop/VPS in seconds).
Just move the workspace/ folder and youโ€™re back in business โ€” same memories, same personality, same progress.

Why people may be drawn to it

  • Supports fully offline operation with local models (native Ollama or OpenAI-compatible local routes)
  • Remembers things in plain, human-readable Markdown files (Obsidian compatible, git-friendly)
  • Can distill conversations into facts, tasks, decisions, goals, and reflections when that optional background pass is enabled
  • Reflects on itself โ€” spots patterns, mistakes, contradictions, and suggests improvements
  • Talks via Nostr (primary), Telegram, email, or plain CLI โ€” your choice
  • Stays tiny, fast, and cheap โ€” no 100k+ line monolith
  • Aims to stay powerful for operators while still being approachable for normal household use

Same crab, new shell.
Move your workspace anywhere. The agent picks up exactly where it left off.

Quick Start

Easy install

This avoids global pip and installs HermitCrab into its own virtual environment under ~/.local/share/hermitcrab:

curl -fsSL https://raw.githubusercontent.com/talvasconcelos/hermitcrab/main/scripts/install.sh | bash

Optional: also install and enable a user-level gateway service:

curl -fsSL https://raw.githubusercontent.com/talvasconcelos/hermitcrab/main/scripts/install.sh | bash -s -- --systemd-user --enable-service --start-service

The service runs hermitcrab gateway via systemd --user, which is the right long-running mode for channels, reminders, and heartbeat-driven work. The installer itself is meant to be generic for Unix-like systems; the systemd --user service step is Linux-specific.

Manual install (3 commands)

  1. Install

    pip install hermitcrab-ai
    
  2. Set up your workspace & config

    hermitcrab onboard
    

    (creates ~/.hermitcrab/ with config and empty workspace)

  3. Pick a model & run

    Option A: Local Ollama (recommended for privacy & free)

    a. Install Ollama:

    # macOS
    brew install ollama
    
    # Linux
    curl -fsSL https://ollama.com/install.sh | sh
    
    # Start Ollama (runs in background)
    ollama serve
    

    b. Pull a model:

    ollama pull gemma4:e4b  # Fast thinking model
    # Or: ollama pull llama3.1:8b      # General purpose
    # Or: ollama pull qwen3.5:7b # Coding specialist
    

    c. Edit ~/.hermitcrab/config.json:

    {
      "providers": {
        "ollama": {
          "apiKey": "",
          "apiBase": "http://localhost:11434"
        }
      },
      "models": {
        "main": {
          "model": "ollama/gemma4:e4b"
        },
        "localCoder": {
          "model": "ollama/qwen3.5:7b"
        }
      },
      "agents": {
        "modelAliases": {
          "coder": "localCoder"
        },
        "defaults": {
          "model": "main",
          "jobModels": {
            "subagent": "localCoder"
          }
        }
      }
    }
    

    Advanced local Ollama example with named models, cloud-routed models, and optional shorthand aliases:

    {
      "providers": {
        "ollama": {
          "apiKey": "",
          "apiBase": "http://localhost:11434"
        }
      },
      "models": {
        "main": {
          "model": "ollama/glm-5:cloud"
        },
        "coder": {
          "model": "ollama/qwen3.5:4b"
        },
        "fast": {
          "model": "ollama/gemma4:e2b",
          "reasoningEffort": "medium"
        }
      },
      "agents": {
        "modelAliases": {
          "code": "coder"
        },
        "defaults": {
          "model": "main",
          "jobModels": {
            "subagent": "coder",
            "reflection": "fast",
            "reasoningEffort": "medium"
          }
        }
      }
    }
    

    Notes:

    • For Ollama, use the dedicated ollama provider.
    • Set providers.ollama.apiBase to your Ollama server root, typically http://localhost:11434 with no /v1 suffix.
    • Use ollama/... model IDs for local Ollama models and Ollama-routed cloud models.
    • Prefer the top-level models section as the canonical place for model definitions.
    • Per-model providerOptions can be used to tune Ollama behavior such as num_ctx, temperature, max_tokens, and related runtime settings.
    • agents.modelAliases is optional shorthand for runtime ergonomics; it is not required if your named model keys are already concise.
    • Subagents can use named models directly, or aliases when you want shorter operator-facing names.

    Option B: Cloud model (OpenRouter)

    # Get API key at https://openrouter.ai/keys
    

    Edit ~/.hermitcrab/config.json:

    {
      "providers": {
        "openrouter": {
          "apiKey": "sk-or-..."
        }
      },
      "agents": {
        "defaults": {
          "model": "anthropic/claude-sonnet-4"
        }
      }
    }
    

    Then run:

    hermitcrab agent
    

    Notes:

    • OpenRouter should be configured under providers.openrouter, not providers.custom.
    • Recommended model forms are anthropic/..., openai/..., google/..., and similar upstream model IDs.
    • openrouter/anthropic/... also works if you want to be explicit.
    • If OpenRouter is your only configured provider, HermitCrab will still route the default anthropic/claude-opus-4-5 model through OpenRouter.

You're now talking to your own persistent, memory-aware agent.

What's new in beta3

  • Nostr can use modern NIP-17 direct-message handling alongside legacy NIP-04 DMs
  • Gateway routing can map allowed Nostr senders into isolated named workspaces
  • hermitcrab workspaces, status, doctor, and audit expose more operator-visible runtime state
  • Tool permission denials produce structured hints and durable audit events
  • Multi-workspace behavior stays additive: the admin workspace remains the default path and CLI owner surface

Useful first commands

hermitcrab agent      # interactive local chat
hermitcrab status     # quick runtime and config status
hermitcrab doctor     # diagnose config/provider issues
hermitcrab gateway    # run configured channels

How the agent actually thinks & remembers

HermitCrab is not a stateless chat loop.
Every session follows a clean lifecycle:

  1. You talk โ†’ agent responds โ†’ tools run if needed
  2. Session ends (you exit, or 30 min of silence)
  3. Journal synthesis โ€” narrative summary of what happened (cheap model)
  4. Optional distillation โ€” proposes fallback facts, tasks, goals, and decisions when enabled
  5. Reflection โ€” looks for mistakes, contradictions, patterns (smarter model)
  6. Scratchpad archival โ€” per-session transient notes are archived on session end

All extracted knowledge lands as tiny, atomic Markdown notes in workspace/memory/:

workspace/
โ”œโ”€โ”€ memory/
โ”‚   โ”œโ”€โ”€ facts/          # preferences, hard truths
โ”‚   โ”œโ”€โ”€ decisions/      # choices & reasoning (immutable)
โ”‚   โ”œโ”€โ”€ goals/          # long-term objectives
โ”‚   โ”œโ”€โ”€ tasks/          # things to do (with deadlines & status)
โ”‚   โ””โ”€โ”€ reflections/    # self-analysis, cleanups
โ”œโ”€โ”€ knowledge/          # reference library (articles, docs, notes)
โ”œโ”€โ”€ journal/            # narrative session summaries
โ”œโ”€โ”€ scratchpads/        # per-session transient working notes
โ””โ”€โ”€ sessions/           # raw chat logs (for debugging)

Everything is:

  • Human-readable & editable (open in Obsidian, Vim, Notepad)
  • Structured with YAML frontmatter
  • Wikilink-friendly
  • Deterministic โ€” Python, not the LLM, writes the files

No vector databases. No silent embeddings. No hidden state corruption.

Distillation is conservative and optional by design. Explicit memory writes remain authoritative.

Scratchpad and channel prompts

  • Every session has a dedicated scratchpad file at workspace/scratchpads/<session>.md.
  • Scratchpad is transient by design: it is archived to workspace/scratchpads/archive/ on session end.
  • Scratchpad traces are excluded from distillation so transient reasoning doesn't pollute long-term memory.
  • Optional per-channel prompt overlays:
    • workspace/prompts/<channel>.md
    • workspace/prompts/<channel>/<chat_id>.md

Channels โ€” where you talk to your crab

  • Nostr (default / primary) โ€” encrypted DMs via NIP-04 or modern NIP-17
  • Telegram โ€” classic bot
  • Email โ€” IMAP/SMTP
  • CLI โ€” quick local chats

The gateway can route channel traffic to isolated workspaces. By design, sub-workspaces are channel-only; CLI and config.json remain admin-owned surfaces.

Tools โ€” what the agent can actually do

Tool What it does
read_file Peek at files in workspace
write_file Create / overwrite files
edit_file Precise replacements
list_dir Browse directories
exec Run safe shell commands
web_search DuckDuckGo search (no API key needed)
web_fetch Fetch & extract URL content (sanitized)
knowledge_search Search your knowledge library
knowledge_ingest Save articles/docs to library
message Reply to you on the active channel
spawn Launch sub-agents
cron Schedule recurring jobs

Security: Web content is automatically sanitized to remove prompt injection attacks, hidden instructions, and encoded payloads.

Execution is always gated by Python โ€” the LLM can only propose.

Self-Improvement โ€” the part that actually matters

HermitCrab gets smarter over time by:

  • Distilling conversations โ†’ new facts/tasks/goals/reflections
  • Reflecting on patterns โ†’ mistakes, contradictions, model misbehavior
  • Routing jobs to the right model:
    • Interactive replies โ†’ strong model (Claude, GPT-4o, etc.)
    • Journal + distillation โ†’ cheap local (Llama 3.2 3B, Phi-3-mini)
    • Reflection โ†’ medium model

This keeps costs low while letting the agent learn without constant supervision.

Subagents and models

HermitCrab can delegate longer-running or specialized work to subagents while the main agent stays responsive.

  • Define reusable models in top-level models
  • Set a dedicated subagent model in agents.defaults.jobModels.subagent
  • Optionally add short aliases in agents.modelAliases for runtime convenience
  • The agent can use either named models or aliases when spawning delegated work

Example use cases:

  • "Build a simple website for X, use the coder subagent"
  • "Investigate this bug in the background and report back"

Architecture at a glance

HermitCrab is intentionally kept lean enough to read, debug, and adapt without inheriting a giant framework.

hermitcrab/
โ”œโ”€โ”€ agent/         # loop, tools, memory handling
โ”œโ”€โ”€ channels/      # Nostr, Telegram, email, CLI
โ”œโ”€โ”€ providers/     # LLM abstraction (litellm + fallbacks)
โ”œโ”€โ”€ config/        # typed config loading
โ”œโ”€โ”€ cli/           # typer-based interface
โ””โ”€โ”€ utils/         # helpers

Design rules we live by:

  • Python is the source of truth โ€” LLM is untrusted
  • Memory is deterministic & auditable
  • Local-first by default
  • Small enough to read in a weekend
  • Hackable, understandable

Runtime safety defaults

Production-minded defaults are in hermitcrab/config/schema.py and are written into ~/.hermitcrab/config.json on hermitcrab onboard.

  • LLM retries with exponential backoff
  • Max response loop time cap
  • Repeated tool-cycle detection (loop break)
  • Bounded memory context injection
  • Reflection auto-promotion disabled by default (safer file integrity)

Comparison โ€” why this feels different

Aspect HermitCrab Typical AI Framework / Chatbot
Core code size Lean Python codebase 50kโ€“300k+ lines
Memory Atomic Markdown Vector DB or forgotten
Portability Copy workspace โ†’ works Cloud account locked
Transparency Fully auditable Opaque internals
Cost Local models cheap API calls add up fast
Self-improvement Built-in distillation & reflection Rare or manual

Beta focus

For 0.1.0b3, the priorities are:

  • modern Nostr direct-message reliability
  • owner-managed, channel-only multi-workspace routing
  • clearer diagnostics, audit trails, and operator recovery paths
  • safer permission UX without arbitrary dead ends
  • keeping the default single-workspace experience simple and intact

Why I built this

Most AI tools today are:

  • Tied to someone elseโ€™s cloud
  • Forget everything after 4k tokens
  • Impossible to truly understand or audit
  • Expensive to run 24/7

HermitCrab exists to prove a quieter truth:

A personal AI can be small, local, private, deterministic, and still grow with you โ€” without turning into a 200k-line monster or a subscription bill.

Keep it yours. Keep it local. Keep it simple. ๐Ÿฆ€

Get started

curl -fsSL https://raw.githubusercontent.com/talvasconcelos/hermitcrab/main/scripts/install.sh | bash
hermitcrab doctor
hermitcrab agent

Welcome to your own second brain. Let's make it remember everything that matters.

Docker

Dockerfile and docker-compose.yml build/run HermitCrab directly.

  • Build: docker compose build
  • Run gateway: docker compose up -d hermitcrab-gateway

๐Ÿค Acknowledgments

HermitCrab is a fork of nanobot by HKUDS.

We stand on the shoulders of giants:

  • Original nanobot architecture ยฉ HKUDS (MIT License)
  • Inspired by OpenClaw

Thank you to the nanobot team for creating the foundation that made HermitCrab possible.

Persisted data lives at ~/.hermitcrab and can be mounted into containers when you use Docker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hermitcrab_ai-0.1.0b3-py3-none-any.whl (311.1 kB view details)

Uploaded Python 3

File details

Details for the file hermitcrab_ai-0.1.0b3-py3-none-any.whl.

File metadata

File hashes

Hashes for hermitcrab_ai-0.1.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 ab862a724935fb2b014839f5a12255ebb4989cb3be788b1943caeb7b500f37d6
MD5 7b4e1d57a6797e78c9dff36bb39c1a70
BLAKE2b-256 61f4b3d83f84c2d546f6a1c45cc8df390bf84c4beb9e9302a3cd65b3ed993c94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page