apollostreetcompany/tinyclaw

โ˜… 0Forks 0GitHub โ†—Compare

README

TinyClaw ๐Ÿฆž

Minimal multi-channel AI assistant with WhatsApp integration and queue-based architecture.

๐ŸŽฏ What is TinyClaw?

TinyClaw is a lightweight wrapper around Claude Code that:

  • โœ… Connects WhatsApp (via QR code)
  • โœ… Processes messages sequentially (no race conditions)
  • โœ… Maintains conversation context
  • โœ… Runs 24/7 in tmux
  • โœ… Ready for multi-channel (Telegram, etc.)

Key innovation: File-based queue system prevents race conditions and enables multi-channel support.

๐Ÿ“ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  WhatsApp       โ”‚โ”€โ”€โ”
โ”‚  Client         โ”‚  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
                     โ”œโ”€โ”€โ†’ Queue (incoming/)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚        โ†“
โ”‚  Telegram       โ”‚โ”€โ”€โ”ค   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  (future)       โ”‚  โ”‚   โ”‚   Queue      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚   โ”‚  Processor   โ”‚
                     โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Other Channels โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ†“
                         claude --dangerously-skip-permissions -c -p
                              โ†“
                         Queue (outgoing/)
                              โ†“
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ Channels send   โ”‚
                    โ”‚ responses       โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Tmux Layout

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  WhatsApp    โ”‚    Queue     โ”‚
โ”‚  Client      โ”‚  Processor   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Heartbeat   โ”‚    Logs      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

Prerequisites

  • macOS or Linux
  • Claude Code installed
  • Node.js v14+
  • tmux

Installation

cd /Users/jliao/workspace/tinyclaw

# Install dependencies
npm install

# Make scripts executable
chmod +x *.sh *.js

# Start TinyClaw
./tinyclaw.sh start

First Run

A QR code will appear in your terminal:

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
        WhatsApp QR Code
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

[QR CODE HERE]

๐Ÿ“ฑ Scan with WhatsApp:
   Settings โ†’ Linked Devices โ†’ Link a Device

Scan it with your phone. Done! ๐ŸŽ‰

Test It

Send a WhatsApp message to yourself from a different WhatsApp account:

"Hello Claude!"

You'll get a response! ๐Ÿค–

๐Ÿ“‹ Commands

# Start TinyClaw
./tinyclaw.sh start

# Check status
./tinyclaw.sh status

# Send manual message
./tinyclaw.sh send "What's the weather?"

# Reset conversation
./tinyclaw.sh reset

# View logs
./tinyclaw.sh logs whatsapp
./tinyclaw.sh logs queue

# Attach to tmux
./tinyclaw.sh attach

# Stop
./tinyclaw.sh stop

๐Ÿ”ง Components

1. whatsapp-client.js

  • Connects to WhatsApp via QR code
  • Writes incoming messages to queue
  • Reads responses from queue
  • Sends replies back

2. queue-processor.js

  • Polls incoming queue
  • Processes ONE message at a time
  • Calls claude -c -p
  • Writes responses to outgoing queue

3. heartbeat-cron.sh

  • Runs every 5 minutes
  • Sends heartbeat via queue
  • Keeps conversation active

4. tinyclaw.sh

  • Main orchestrator
  • Manages tmux session
  • CLI interface

๐Ÿ’ฌ Message Flow

WhatsApp message arrives
       โ†“
whatsapp-client.js writes to:
  .tinyclaw/queue/incoming/whatsapp_<id>.json
       โ†“
queue-processor.js picks it up
       โ†“
Runs: claude -c -p "message"
       โ†“
Writes to:
  .tinyclaw/queue/outgoing/whatsapp_<id>.json
       โ†“
whatsapp-client.js sends response
       โ†“
User receives reply

๐Ÿ“ Directory Structure

tinyclaw/
โ”œโ”€โ”€ .claude/              # Claude Code config
โ”‚   โ”œโ”€โ”€ settings.json     # Hooks config
โ”‚   โ””โ”€โ”€ hooks/            # Hook scripts
โ”œโ”€โ”€ .tinyclaw/            # TinyClaw data
โ”‚   โ”œโ”€โ”€ queue/
โ”‚   โ”‚   โ”œโ”€โ”€ incoming/     # New messages
โ”‚   โ”‚   โ”œโ”€โ”€ processing/   # Being processed
โ”‚   โ”‚   โ””โ”€โ”€ outgoing/     # Responses
โ”‚   โ”œโ”€โ”€ logs/
โ”‚   โ”œโ”€โ”€ whatsapp-session/
โ”‚   โ””โ”€โ”€ heartbeat.md
โ”œโ”€โ”€ tinyclaw.sh           # Main script
โ”œโ”€โ”€ whatsapp-client.js    # WhatsApp I/O
โ”œโ”€โ”€ queue-processor.js    # Message processing
โ””โ”€โ”€ heartbeat-cron.sh     # Health checks

๐Ÿ”„ Reset Conversation

Via CLI

./tinyclaw.sh reset

Via WhatsApp

Send: !reset or /reset

Next message starts fresh (no conversation history).

โš™๏ธ Configuration

Heartbeat Interval

Edit heartbeat-cron.sh:

INTERVAL=300  # seconds (5 minutes)

Heartbeat Prompt

Edit .tinyclaw/heartbeat.md:

Check for:

1. Pending tasks
2. Errors
3. Unread messages

Take action if needed.

๐Ÿ“Š Monitoring

View Logs

# WhatsApp activity
tail -f .tinyclaw/logs/whatsapp.log

# Queue processing
tail -f .tinyclaw/logs/queue.log

# Heartbeat checks
tail -f .tinyclaw/logs/heartbeat.log

# All logs
./tinyclaw.sh logs daemon

Watch Queue

# Incoming messages
watch -n 1 'ls -lh .tinyclaw/queue/incoming/'

# Outgoing responses
watch -n 1 'ls -lh .tinyclaw/queue/outgoing/'

๐ŸŽจ Features

โœ… No Race Conditions

Messages processed sequentially, one at a time:

Message 1 โ†’ Process โ†’ Done
Message 2 โ†’ Wait โ†’ Process โ†’ Done
Message 3 โ†’ Wait โ†’ Process โ†’ Done

โœ… Multi-Channel Ready

Add Telegram by creating telegram-client.js:

// Write to queue
fs.writeFileSync(
  '.tinyclaw/queue/incoming/telegram_<id>.json',
  JSON.stringify({ channel: 'telegram', message, ... })
);

// Read responses
// Same format as WhatsApp

Queue processor handles it automatically!

โœ… Clean Responses

Uses claude -c -p:

  • -c = continue conversation
  • -p = print mode (clean output)
  • No tmux capture needed

โœ… Persistent Sessions

WhatsApp session persists across restarts:

# First time: Scan QR code
./tinyclaw.sh start

# Subsequent starts: Auto-connects
./tinyclaw.sh restart

๐Ÿ” Security

  • WhatsApp session stored locally in .tinyclaw/whatsapp-session/
  • Queue files are local (no network exposure)
  • Each channel handles its own authentication
  • Claude runs with your user permissions

๐Ÿ› Troubleshooting

WhatsApp not connecting

# Check logs
./tinyclaw.sh logs whatsapp

# Re-authenticate
rm -rf .tinyclaw/whatsapp-session/
./tinyclaw.sh restart

Messages not processing

# Check queue processor
./tinyclaw.sh status

# Check queue
ls -la .tinyclaw/queue/incoming/

# View queue logs
./tinyclaw.sh logs queue

QR code not showing

# Use helper script
./show-qr.sh

# Or attach to tmux
tmux attach -t tinyclaw

๐Ÿš€ Production Deployment

Using systemd

sudo systemctl enable tinyclaw
sudo systemctl start tinyclaw

Using PM2

pm2 start tinyclaw.sh --name tinyclaw
pm2 save

Using supervisor

[program:tinyclaw]
command=/path/to/tinyclaw/tinyclaw.sh start
autostart=true
autorestart=true

๐ŸŽฏ Use Cases

Personal AI Assistant

You: "Remind me to call mom"
Claude: "I'll remind you!"
[5 minutes later via heartbeat]
Claude: "Don't forget to call mom!"

Code Helper

You: "Review my code"
Claude: [reads files, provides feedback]
You: "Fix the bug"
Claude: [fixes and commits]

Multi-Device

  • WhatsApp on phone
  • Telegram on desktop
  • CLI for scripts All share the same Claude conversation!

๐Ÿ™ Credits

๐Ÿ“„ License

MIT


TinyClaw - Small but mighty! ๐Ÿฆžโœจ

Contributors

jlia0

Issues