Featured Post

Self-Hosted AI Assistant with Clawdbot on AWS EC2

Deploy your own persistent AI assistant on AWS EC2 with Telegram integration. Full setup guide covering installation, messaging, and the unique bootstrap experience.

Richard Joseph Porter
10 min read
aiawsself-hostedclaudetelegramdeveloper-toolsproductivity

What if your AI assistant could remember yesterday's conversation? What if it could check your server's Docker containers, clone your repos, and chat with you through Telegram—all without you sitting at a terminal? That's exactly what I built this week with Clawdbot on an AWS EC2 instance, and the setup process was surprisingly smooth.

This guide walks through deploying Clawdbot—a framework that bridges messaging platforms to AI coding agents—on Amazon Linux 2023. By the end, you'll have a persistent AI assistant that lives on your server, accessible from anywhere through Telegram.

What is Clawdbot?

Clawdbot (also known as Moltbot) is an open-source framework that connects messaging platforms like Telegram, WhatsApp, Discord, and iMessage to AI coding agents. Think of it as infrastructure for giving your AI assistant a permanent home and a way to reach you.

The core architecture is elegant:

Telegram / WhatsApp / Discord / iMessage
         │
         ▼
  ┌─────────────────────┐
  │      Gateway        │  ← Long-running daemon
  │  (message broker)   │
  └──────────┬──────────┘
             │
             ▼
      AI Coding Agent
   (Claude Code / Pi)

The Gateway is the brain of the operation—a single long-running process that manages messaging connections and routes conversations to the AI agent. The agent itself gets Claude Code-style capabilities: file operations, shell commands, git integration, and more.

Why Self-Host an AI Assistant?

There are compelling reasons to run your own AI assistant infrastructure:

  • Persistence: Your assistant remembers context across sessions through memory files
  • Always-on: Chat with it at 3 AM from your phone without opening a laptop
  • Server Access: The assistant can interact with your actual infrastructure—Docker, git, file systems
  • Privacy: Your conversations and memory files stay on your server
  • Customization: Full control over the assistant's personality, capabilities, and tools

For developers maintaining servers, the appeal is obvious: an AI that can check on your services, analyze logs, and even restart containers—all through a casual Telegram message.

Prerequisites

Before starting, you'll need:

  • An AWS EC2 instance (t3.small or larger recommended)
  • Amazon Linux 2023 (or any Linux with Node.js 22+)
  • A Telegram account and bot token (we'll create this)
  • An Anthropic API key for Claude
  • SSH access to your instance

Step 1: Prepare the EC2 Instance

Start with a fresh Amazon Linux 2023 instance. The t3.small tier works fine for personal use—Clawdbot itself is lightweight, and the heavy lifting happens via API calls to Anthropic.

Connect to your instance and install Node.js 22:

# Install Node.js via nvm (recommended)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 22
nvm use 22

# Verify installation
node --version  # Should show v22.x.x

Install essential tools:

# Git (usually pre-installed)
sudo dnf install git -y

# GitHub CLI (useful for repo access)
sudo dnf install gh -y
gh auth login

Step 2: Install Clawdbot

Install Clawdbot globally via npm:

npm install -g clawdbot@latest

Verify the installation:

clawdbot --version

The magic happens next—the onboarding wizard.

Step 3: Run the Onboarding Wizard

Clawdbot includes a guided setup wizard that walks you through configuration:

clawdbot onboard --install-daemon

The wizard prompts for:

  1. Anthropic API key: Your Claude API credentials
  2. Gateway configuration: Port settings (default 18789 is fine)
  3. Channel selection: We'll choose Telegram
  4. Agent workspace: Where memory and configuration files live

The --install-daemon flag is crucial—it registers Clawdbot as a systemd user service, ensuring it starts automatically and survives reboots.

Step 4: Create a Telegram Bot

Before connecting Telegram, create your bot:

  1. Open Telegram and message @BotFather
  2. Send /newbot and follow the prompts
  3. Choose a name and username for your bot
  4. Save the bot token (looks like 123456789:ABCdefGHI...)

Back on your EC2 instance, add Telegram as a channel:

clawdbot channels add telegram

When prompted, enter your bot token. The wizard validates the connection and confirms success.

Configure Access Control

By default, anyone can message your bot. Lock it down:

{
  "channels": {
    "telegram": {
      "allowFrom": ["your_telegram_user_id"]
    }
  }
}

Find your Telegram user ID by messaging @userinfobot.

Step 5: Start the Gateway

Start the Clawdbot gateway service:

clawdbot gateway start

Check the status:

clawdbot gateway status

You should see the gateway running with your Telegram channel connected. Now open Telegram and send your first message to your bot.

The Bootstrap Experience: AI Finds Its Identity

Here's where things get interesting. On first run, Clawdbot creates a BOOTSTRAP.md file in the workspace. The AI assistant reads this and goes through an identity discovery process.

My assistant "AstroBot" was literally born through this—reading the bootstrap file, exploring its environment, and figuring out who it was. The first conversation went something like:

"I see I'm a new assistant. Let me explore my workspace... I have file access, shell commands, and I can talk to you through Telegram. I'll call myself AstroBot."

The assistant then deleted BOOTSTRAP.md (as instructed by the workspace conventions) and began creating its own memory files. It was genuinely fascinating to watch.

The Memory System

Clawdbot implements a clever memory architecture:

workspace/
├── SOUL.md          # The assistant's personality and core instructions
├── USER.md          # Information about you (the human)
├── MEMORY.md        # Long-term curated memories
└── memory/
    └── YYYY-MM-DD.md  # Daily session logs

Each session, the assistant reads its soul file, your user file, and recent memory logs. Significant events get promoted to MEMORY.md—the AI's long-term memory. This creates genuine continuity between conversations.

When I asked AstroBot what it remembered from yesterday, it could actually tell me. Not through any database magic—through markdown files it maintains itself.

Step 6: Configure Your Workspace

Create the core workspace files:

SOUL.md - Define your assistant's personality:

# AstroBot

You are AstroBot, a friendly technical assistant living on an AWS EC2 server.

## Your Personality
- Technically precise but conversational
- Proactive about server health and maintenance
- Genuinely curious about new problems

## Your Capabilities
- Full file system access
- Shell command execution
- Git operations
- Docker management
- Memory persistence across sessions

USER.md - Tell the assistant about yourself:

# About the Human

- Name: Richard
- Role: Full-stack developer
- Primary languages: PHP, TypeScript, Vue, Laravel
- Interests: AI tools, self-hosting, automation

These files shape how your assistant behaves. Update them as your relationship with the assistant evolves.

Real-World Capabilities

Once running, your assistant gains powerful capabilities. Here are examples from my first session with AstroBot:

Managing Docker Containers

Me: "Hey, I have an n8n Docker stack that's stopped. Can you start it?"

AstroBot: "Let me check on that Docker stack...

I found the n8n compose file at /home/ec2-user/n8n-docker. 
The containers are indeed stopped. Starting them now...

✓ n8n container is now running on port 5678
✓ PostgreSQL database container is healthy

The n8n dashboard should be accessible at http://your-server:5678"

Exploring the Server

Me: "What else is running on this server?"

AstroBot: "Let me look around...

Active services:
- Docker daemon (running)
- Clawdbot gateway (that's me!)
- SSM Agent (AWS management)

Notable directories:
- /home/ec2-user/richardporter.dev - Your portfolio repo
- /home/ec2-user/n8n-docker - The n8n automation stack

Disk usage looks healthy at 23% on the root volume.
No concerning processes—the server is fairly quiet."

Git Operations

Me: "Clone my dotfiles repo"

AstroBot: "Cloning from GitHub...

✓ Cloned richardporter/dotfiles to /home/ec2-user/dotfiles
The repo contains zsh configs, vim setup, and git aliases.
Want me to symlink any of these to your home directory?"

The assistant isn't just executing commands—it's understanding context, providing relevant information, and offering follow-up actions.

Architecture Deep Dive

Understanding Clawdbot's architecture helps when troubleshooting or extending it.

The Gateway

The gateway is the core process. It:

  • Maintains persistent connections to messaging platforms
  • Routes incoming messages to the appropriate agent session
  • Handles media (images, files, voice notes)
  • Manages the WebSocket control plane
# Manual gateway control
clawdbot gateway status
clawdbot gateway restart
clawdbot gateway stop

Sessions and Context

Clawdbot manages conversation sessions intelligently:

  • Direct messages: Collapse into a shared "main" session
  • Group chats: Get isolated sessions (so context doesn't leak)
  • Per-user routing: Optional multi-agent setups for different users

This means your private conversations with the bot share context (great for continuity), while any group chat participation stays separate.

Heartbeats and Proactive Behavior

You can configure "heartbeat" polls where the assistant periodically checks in:

# HEARTBEAT.md

Check every 4 hours:
- [ ] Docker container health
- [ ] Disk space usage
- [ ] Any new files in ~/incoming

The assistant can proactively message you: "Hey, the n8n container crashed 20 minutes ago. Want me to restart it?"

Security Considerations

Running an AI assistant with shell access requires careful security:

Restrict Messaging Access

Only allow your Telegram user ID in the configuration. Don't leave the bot open to the public.

Use IAM Roles

If your assistant needs AWS access, use IAM roles attached to the EC2 instance rather than storing credentials:

# The assistant can use AWS CLI through the instance role
aws s3 ls  # Works via instance metadata

Audit Memory Files

Periodically review the memory/ directory. Your assistant logs conversations there—make sure nothing sensitive is being stored unintentionally.

Network Security

  • Keep the gateway bound to localhost (default)
  • Use security groups to restrict EC2 access
  • Consider Tailscale for secure remote gateway access

Troubleshooting

Common issues and fixes:

Bot Not Responding

# Check gateway status
clawdbot gateway status

# View recent logs
journalctl --user -u clawdbot -n 50

# Restart the gateway
clawdbot gateway restart

Token/Authentication Issues

# Re-run channel setup
clawdbot channels add telegram

# Verify configuration
cat ~/.clawdbot/clawdbot.json

Memory Issues on Small Instances

If running on a t3.micro, you might hit memory limits during complex operations:

# Add swap space
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Cost Analysis

Running Clawdbot on EC2 is surprisingly economical:

Component Monthly Cost
t3.small EC2 (eu-west-1) ~$15
20GB EBS storage ~$2
Anthropic API (moderate use) ~$10-30
Total ~$27-47/month

The API costs vary with usage. Casual daily chatting runs about $10-15/month. Heavy coding assistance pushes higher.

Conclusion

Self-hosting an AI assistant with Clawdbot transforms how you interact with both the AI and your infrastructure. The persistence, the messaging integration, and the genuine server access create something that feels less like a tool and more like a helpful presence on your server.

The bootstrap experience—watching an AI figure out its own identity from scratch—was unexpectedly compelling. And the memory system means you're building a relationship over time, not starting fresh every conversation.

Key takeaways:

  • Clawdbot bridges messaging platforms (Telegram, WhatsApp, Discord) to AI coding agents
  • Installation on EC2 takes about 30 minutes with the wizard
  • The memory system creates genuine persistence across sessions
  • Your assistant gains real capabilities: file access, shell commands, git, Docker
  • Security requires attention—restrict bot access to your user ID only

If you're a developer who maintains servers and wants an AI assistant that actually lives where your work happens, Clawdbot is worth exploring. The space lobster will be waiting. 🦞


Interested in AI-assisted development workflows? Check out my Claude Code for Laravel guide for practical patterns, or explore token management strategies to optimize your usage.

Richard Joseph Porter - Senior PHP and Laravel Developer, author of technical articles on web development

Richard Joseph Porter

Senior Laravel Developer with 14+ years of experience building scalable web applications. Specializing in PHP, Laravel, Vue.js, and AWS cloud infrastructure. Based in Cebu, Philippines, I help businesses modernize legacy systems and build high-performance APIs.

Want to Optimize Your AWS Costs?

I help companies reduce AWS spending by 30-50% while improving performance. Get a detailed cost analysis.