Skip to content
Back to skills

Clawbrain

ASecurity

Claw Brain - Personal AI Memory System for OpenClaw/ClawDBot. Provides memory, personality, bonding, and learning capabilities with encrypted secrets support. Auto-refreshes on service restart.

  • 33 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
developmentpythonrustgobashsqltestinggitapidatabasebackend

Works with

  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 20 files and shows the line behind each finding

Scanned May 30, 2026

npx -y skills add dvcrn/openclaw-skills-marketplace --skill clawbrain --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clawbrain?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Clawbrain
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/dvcrn-clawbrain/badge)](https://www.skillsdirectory.com/skills/dvcrn-clawbrain)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: clawbrain
description: "Claw Brain - Personal AI Memory System for OpenClaw/ClawDBot. Provides memory, personality, bonding, and learning capabilities with encrypted secrets support. Auto-refreshes on service restart."
---

# Claw Brain Skill 🧠

Personal AI Memory System with Soul, Bonding, and Learning for OpenClaw/ClawDBot.

> **Auto-Refresh on Restart**: ClawBrain automatically refreshes memory when the service restarts.

## Features

- šŸŽ­ **Soul/Personality** - 6 evolving traits (humor, empathy, curiosity, creativity, helpfulness, honesty)
- šŸ‘¤ **User Profile** - Learns user preferences, interests, communication style
- šŸ’­ **Conversation State** - Real-time mood detection and context tracking
- šŸ“š **Learning Insights** - Continuously learns from interactions and corrections
- 🧠 **get_full_context()** - Everything for personalized responses
- šŸ”„ **Auto-Refresh** - Automatically refreshes memory on service restart
- šŸ” **Encrypted Secrets** - Store API keys and credentials securely

---

## Quick Install

### From PyPI (Recommended)

```bash
# Install with all features
pip install clawbrain[all]

# Run interactive setup
clawbrain setup

# Backup your encryption key (IMPORTANT!)
clawbrain backup-key --all

# Restart your service
sudo systemctl restart clawdbot  # or openclaw
```

The setup command will:
1. Detect your platform (ClawdBot or OpenClaw)
2. Generate a secure encryption key
3. Install the startup hook automatically
4. Test the installation

### Alternative: From Source

```bash
# Clone to your skills directory
cd ~/.openclaw/skills  # or ~/clawd/skills or ~/.clawdbot/skills
git clone https://github.com/clawcolab/clawbrain.git
cd clawbrain
pip install -e .[all]
clawbrain setup
```

---

## Configuration

After installation, optionally configure your agent ID:

```bash
# Create systemd drop-in config
sudo mkdir -p /etc/systemd/system/clawdbot.service.d  # or openclaw.service.d

sudo tee /etc/systemd/system/clawdbot.service.d/brain.conf << EOF
[Service]
Environment="BRAIN_AGENT_ID=your-agent-name"
# Optional: PostgreSQL (for production)
# Environment="BRAIN_POSTGRES_HOST=localhost"
# Environment="BRAIN_POSTGRES_PASSWORD=your-password"
# Optional: Redis (for caching)
# Environment="BRAIN_REDIS_HOST=localhost"
EOF

sudo systemctl daemon-reload
sudo systemctl restart clawdbot  # or openclaw
```

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `BRAIN_AGENT_ID` | Unique ID for this agent's memories | `default` |
| `BRAIN_ENCRYPTION_KEY` | Fernet key for encrypting sensitive data (auto-generated if not set) | - |
| `BRAIN_POSTGRES_HOST` | PostgreSQL host | `localhost` |
| `BRAIN_POSTGRES_PASSWORD` | PostgreSQL password | - |
| `BRAIN_POSTGRES_PORT` | PostgreSQL port | `5432` |
| `BRAIN_POSTGRES_DB` | PostgreSQL database | `brain_db` |
| `BRAIN_POSTGRES_USER` | PostgreSQL user | `brain_user` |
| `BRAIN_REDIS_HOST` | Redis host | `localhost` |
| `BRAIN_REDIS_PORT` | Redis port | `6379` |
| `BRAIN_STORAGE` | Force storage: `sqlite`, `postgresql`, `auto` | `auto` |

---

## How It Works

### On Service Startup
1. Hook triggers on `gateway:startup` event
2. Detects storage backend (SQLite/PostgreSQL)
3. Loads memories for the configured `BRAIN_AGENT_ID`
4. Injects context into agent bootstrap

### On `/new` Command
1. Hook triggers on `command:new` event  
2. Saves current session summary to memory
3. Clears session state for fresh start

### Storage Priority
1. **PostgreSQL** - If available and configured
2. **SQLite** - Fallback, zero configuration needed

---

## Encrypted Secrets

ClawBrain supports encrypting sensitive data like API keys and credentials.

**Setup:**
```bash
# Run setup to generate encryption key
clawbrain setup

# Backup your key (IMPORTANT!)
clawbrain backup-key --all
```

**Usage:**
```python
# Store encrypted secret
brain.remember(
    agent_id="assistant",
    memory_type="secret",  # Memory type 'secret' triggers encryption
    content="sk-1234567890abcdef",
    key="openai_api_key"
)

# Retrieve and automatically decrypt
secrets = brain.recall(agent_id="assistant", memory_type="secret")
api_key = secrets[0].content  # Automatically decrypted
```

**Key Management CLI:**
```bash
clawbrain show-key          # View key info (masked)
clawbrain show-key --full   # View full key
clawbrain backup-key --all  # Backup with all methods
clawbrain generate-key      # Generate new key
```

āš ļø **Important**: Backup your encryption key! Lost keys = lost encrypted data.

---

## CLI Commands

ClawBrain includes a command-line interface:

| Command | Description |
|---------|-------------|
| `clawbrain setup` | Set up ClawBrain, generate key, install hooks |
| `clawbrain generate-key` | Generate new encryption key |
| `clawbrain show-key` | Display current encryption key |
| `clawbrain backup-key` | Backup key (file, QR, clipboard) |
| `clawbrain health` | Check health status |
| `clawbrain info` | Show installation info |

---

## Hooks

| Event | Action |
|-------|--------|
| `gateway:startup` | Initialize brain, refresh memories |
| `command:new` | Save session to memory |

---

## Development Installation

For development or manual installation:

```bash
# Clone to your skills directory
cd ~/.openclaw/skills  # or ~/clawd/skills or ~/.clawdbot/skills
git clone https://github.com/clawcolab/clawbrain.git
cd clawbrain
./install.sh
```

---

## Python API

For direct Python usage (outside ClawdBot/OpenClaw):

```python
from clawbrain import Brain

brain = Brain()
```

#### Methods

| Method | Description | Returns |
|--------|-------------|---------|
| `get_full_context()` | Get all context for personalized responses | dict |
| `remember()` | Store a memory | None |
| `recall()` | Retrieve memories | List[Memory] |
| `learn_user_preference()` | Learn user preferences | None |
| `get_user_profile()` | Get user profile | UserProfile |
| `detect_user_mood()` | Detect current mood | dict |
| `detect_user_intent()` | Detect message intent | str |
| `generate_personality_prompt()` | Generate personality guidance | str |
| `health_check()` | Check backend connections | dict |
| `close()` | Close connections | None |

### get_full_context()

```python
context = brain.get_full_context(
    session_key="telegram_12345",  # Unique session ID
    user_id="username",              # User identifier
    agent_id="assistant",          # Bot identifier
    message="Hey, how's it going?" # Current message
)
```

**Returns:**
```python
{
    "user_profile": {...},        # User preferences, interests
    "mood": {"mood": "happy", ...},  # Current mood
    "intent": "question",         # Detected intent
    "memories": [...],            # Relevant memories
    "personality": "...",         # Personality guidance
    "suggested_responses": [...]  # Response suggestions
}
```

### detect_user_mood()

```python
mood = brain.detect_user_mood("I'm so excited about this!")
# Returns: {"mood": "happy", "confidence": 0.9, "emotions": ["joy", "anticipation"]}
```

### detect_user_intent()

```python
intent = brain.detect_user_intent("How does AI work?")
# Returns: "question"

intent = brain.detect_user_intent("Set a reminder for 3pm")
# Returns: "command"

intent = brain.detect_user_intent("I had a great day today")
# Returns: "casual"
```

---

## Example: Full Integration

```python
import sys
sys.path.insert(0, "ClawBrain")

from clawbrain import Brain

class AssistantBot:
    def __init__(self):
        self.brain = Brain()
    
    def handle_message(self, message, chat_id):
        # Get context
        context = self.brain.get_full_context(
            session_key=f"telegram_{chat_id}",
            user_id=str(chat_id),
            agent_id="assistant",
            message=message
        )
        
        # Generate response using context
        response = self.generate_response(context)
        
        # Learn from interaction
        self.brain.learn_user_preference(
            user_id=str(chat_id),
            pref_type="interest",
            value="AI"
        )
        
        return response
    
    def generate_response(self, context):
        # Use user preferences
        name = context["user_profile"].name or "there"
        mood = context["mood"]["mood"]
        
        # Personalized response
        if mood == "frustrated":
            return f"Hey {name}, I'm here to help. Let me assist you."
        else:
            return f"Hi {name}! How can I help you today?"
    
    def shutdown(self):
        self.brain.close()
```

---

## Storage Backends

### SQLite (Default - Zero Setup)

No configuration needed. Data stored in local SQLite database.

```python
brain = Brain({"storage_backend": "sqlite"})
```

**Best for:** Development, testing, single-user deployments

### PostgreSQL + Redis (Production)

Requires PostgreSQL and Redis servers.

```python
brain = Brain()  # Auto-detects
```

**Requirements:**
- PostgreSQL 14+
- Redis 6+
- Python packages: `psycopg2-binary`, `redis`

```bash
pip install psycopg2-binary redis
```

**Best for:** Production, multi-user, high-concurrency

---

## Files

- `clawbrain.py` - Main Brain class with all features
- `__init__.py` - Module exports
- `SKILL.md` - This documentation
- `skill.json` - ClawdHub metadata
- `README.md` - Quick start guide

---

## Troubleshooting

### ImportError: No module named 'clawbrain'

```bash
# Ensure ClawBrain folder is in your path
sys.path.insert(0, "ClawBrain")
```

### PostgreSQL connection failed

```bash
# Check environment variables
echo $POSTGRES_HOST
echo $POSTGRES_PORT

# Verify PostgreSQL is running
pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT
```

### Redis connection failed

```bash
# Check Redis is running
redis-cli ping
```

### Using SQLite (fallback)

If PostgreSQL/Redis are unavailable, Claw Brain automatically falls back to SQLite:

```python
brain = Brain({"storage_backend": "sqlite"})
```

---

## Learn More

- **Repository:** https://github.com/clawcolab/clawbrain
- **README:** See README.md for quick start
- **Issues:** Report bugs at GitHub Issues

Files in this skill

  • CHANGELOG.md7.2 KB
  • README.md7.9 KB
  • SECURITY_FIXES.md8.3 KB
  • SKILL.md9.9 KB
  • __init__.py960 B
  • brain/README.md132 B
  • brain/__init__.py413 B
  • brain/hooks/clawbrain-startup/HOOK.md1.9 KB
  • brain/hooks/clawbrain-startup/handler.js7.1 KB
  • brain/scripts/brain_bridge.py4 KB
  • brain/scripts/migrate_agent_id.py696 B
  • clawbrain.py61.6 KB
  • clawbrain_cli.py30.5 KB
  • install.sh3.4 KB
  • pyproject.toml2.2 KB
  • remote-install.sh2.7 KB
  • scripts/brain_bridge.py4 KB
  • scripts/migrate_agent_id.py696 B
  • skill.json1.9 KB
  • test_encryption.py5.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…