Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

69 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Claude Code Telegram Bot

A Node.js Telegram bot that provides remote access to your existing Claude Code installation. Continue your development workflow through Telegram when away from your computer.

๐Ÿ”„ How It Works

This bot runs on your development machine and connects to your existing Claude Code instance. It allows you to:

  • ๐Ÿ’ฌ Continue coding sessions remotely through Telegram
  • ๐ŸŽ™๏ธ Send voice messages that get transcribed and processed by Claude Code
  • ๐Ÿ“ฑ Access your projects and development environment from your phone
  • ๐Ÿข Manage multiple bot instances for different projects or clients

โš ๏ธ Important: This tool doesn't add any AI functionality. It's a bridge that lets you use your existing Claude Code setup through Telegram with some convenience features.

๐Ÿ“‹ Requirements

Prerequisites

  • ๐Ÿ”ง Claude Code CLI installed and configured on your development machine
  • โšก Node.js 14+
  • ๐Ÿ”‘ Telegram Bot Token from @BotFather
  • ๐Ÿ“‚ Your existing Claude Code projects and tooling setup

Optional

  • ๐ŸŽ™๏ธ Nexara API key for voice message transcription
  • ๐Ÿ”Œ MCP servers configured in Claude Code for enhanced functionality

๐Ÿ“ฆ Installation

Development Setup

git clone <repository-url>
cd claude-code-telegram-control
npm install

PM2 Production Setup

For production deployment with PM2 process manager:

Prerequisites

# Update system
sudo apt update

# Install Node.js and npm (if not already installed)
sudo apt install -y nodejs npm

# Verify installations
node --version    # Should be 14+
npm --version

# Install PM2 globally
npm install -g pm2

Setup Process

# 1. Clone and prepare the project
git clone <repository-url>
cd claude-code-telegram-control
npm install

# 2. Configure your bots (create configs/bot1.json, etc.)
npm run setup   # Interactive setup for each bot

# 3. Install PM2 log rotation
pm2 install pm2-logrotate

# 4. Start bots with PM2
pm2 start ecosystem.config.js

# 5. Setup auto-startup on system boot
pm2 startup
# Run the command PM2 shows you (requires sudo)

# 6. Save current process list
pm2 save

PM2 provides:

  • โœ… Auto-restart on crash (configurable limits)
  • โœ… Auto-start on system boot
  • โœ… No sudo required for daily management
  • โœ… Memory leak protection (auto-restart on limit)
  • โœ… Built-in log rotation
  • โœ… Real-time monitoring with pm2 monit

โš™๏ธ Setup

โšก Quick Setup

npm run setup

The interactive wizard will ask for:

  • ๐Ÿค– Bot name and Telegram token
  • ๐Ÿ“ Working directory (where your projects are)
  • ๐Ÿ‘ค Admin user ID (optional - auto-detected from first message)
  • ๐ŸŽ™๏ธ Nexara API key (optional - for voice messages)
  • ๐Ÿง  Default Claude model (Sonnet/Opus)

๐Ÿ“ Manual Configuration

Create configuration files in configs/ directory:

// configs/bot1.json
{
  "botName": "MyDevBot",
  "token": "your_telegram_bot_token",
  "adminUserId": "your_telegram_user_id",
  "nexaraApiKey": "optional_nexara_key",
  "workingDirectory": "/path/to/your/projects",
  "model": "sonnet"
}

๐Ÿš€ Usage

โ–ถ๏ธ Starting the Bot

Development Mode (Manual)

# Start default bot
npm run bot1

# Start multiple bots
npm run bot2
npm run bot3

# Development mode with auto-restart
npm run dev

Production Mode (PM2 Process Manager)

For production deployment with PM2 process manager:

# Start all bots
pm2 start ecosystem.config.js

# Management commands (NO SUDO REQUIRED!)
pm2 restart bot1        # Restart specific bot
pm2 restart all         # Restart all bots
pm2 stop bot1          # Stop specific bot
pm2 start bot1         # Start specific bot
pm2 delete bot1        # Remove bot from PM2

# Monitoring and logs
pm2 status             # Show all processes
pm2 logs               # Show all logs
pm2 logs bot1          # Show logs for specific bot
pm2 monit              # Interactive monitoring dashboard

# Updates and maintenance
git pull               # Update code
pm2 restart all        # Restart with new code

PM2 process manager provides:

  • โœ… Automatic startup on system boot
  • ๐Ÿ”„ Auto-restart on crash (configurable limits)
  • ๐Ÿ“‹ Centralized logging with rotation
  • ๐Ÿ›ก๏ธ Memory leak protection (512MB restart threshold)
  • ๐Ÿ“Š Real-time monitoring with pm2 monit
  • ๐Ÿš€ Zero-downtime deployments
  • โšก No sudo required for daily operations

๐Ÿ“ Basic Commands

  • /start - ๐ŸŽฆ Initialize bot and show keyboard
  • /status - ๐Ÿ“ˆ Show active Claude Code processes
  • /new - โœจ Start new Claude Code session
  • /sessions - ๐Ÿ“‚ Browse previous sessions
  • /model - ๐Ÿง  Switch Claude model (Sonnet/Opus)
  • /files - ๐ŸŒ Open web-based file browser with public URL
  • /cancel - ๐Ÿ›‘ Stop all running processes

โŒจ๏ธ Persistent Keyboard

Always available buttons:

๐Ÿ›‘ STOP        ๐Ÿ“Š Status       ๐Ÿ“‚ Projects
๐Ÿ”„ New Session ๐Ÿ“ Sessions     ๐Ÿค– Model  
๐Ÿง  Thinking    ๐Ÿ“ Path        ๐Ÿ” Git Diff

๐ŸŽ™๏ธ Voice Messages

If Nexara API is configured:

  1. Send voice message to bot
  2. Bot transcribes speech to text
  3. Shows Execute/Cancel/Edit buttons
  4. Execute sends command to Claude Code
  5. Receive streaming response

โœจ Features

๐Ÿ“ Session Management

  • โฏ๏ธ Resume conversations using Claude Code's --resume flag
  • ๐Ÿ“‚ Session history with browsable past conversations
  • ๐Ÿข Multi-instance support - run separate bots for different projects

๐Ÿ”„ Real-time Streaming

  • โšก Live updates as Claude Code processes commands
  • ๐Ÿงฎ Smart message chunking for Telegram's 4096 character limit
  • ๐Ÿ“ Progressive message editing to show work in progress

๐Ÿข Multi-Bot Configuration

  • ๐Ÿ”„ Independent instances with separate configs
  • ๐Ÿ“ Different working directories per bot
  • ๐Ÿ‘ฅ Separate admin users for each bot
  • ๐Ÿ”’ Isolated session storage

๐Ÿ”„ Git Workflow Management

  • ๐Ÿ“Š Comprehensive git interface - complete git workflow through Telegram
  • ๐ŸŒฟ Branch management - create, switch, list branches with validation
  • ๐Ÿ“ฆ Staging operations - stage/unstage files individually or in bulk
  • ๐Ÿ“ Smart file view - examine diffs with context-aware staging buttons
  • ๐Ÿ“ฑ Mobile-optimized UI - pagination and touch-friendly controls
  • โšก Real-time status - live git status with ahead/behind tracking
  • ๐Ÿ”„ Interactive workflows - guided git operations with error handling

๐ŸŒ File Browser (Web Interface)

  • ๐Ÿ“ Web-based file browsing - navigate project files through a modern web interface
  • ๐Ÿ”— Public URL access - secure ngrok tunnel provides remote access from anywhere
  • ๐Ÿ“ฑ Mobile-optimized interface - responsive design perfect for mobile devices
  • ๐ŸŽจ Syntax highlighting - view code files with proper syntax coloring
  • ๐Ÿ”’ Security-first design - access restricted to project directory only
  • โšก Auto-lifecycle management - server starts/stops with bot automatically
  • ๐Ÿ’ก Banner-free access - automated ngrok warning bypass headers

๐Ÿ”’ Security

  • ๐Ÿ‘ค Admin-only access - only configured users can use the bot
  • โœ… Command confirmation for voice messages
  • โฐ Process timeouts and emergency stop functionality

๐Ÿ  Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Telegram      โ”‚โ—„โ”€โ”€โ–บโ”‚  StreamTelegram โ”‚โ—„โ”€โ”€โ–บโ”‚  Claude CLI     โ”‚
โ”‚   Bot API       โ”‚    โ”‚  Bot (bot.js)   โ”‚    โ”‚  Process        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
                                โ–ผ
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                        โ”‚ ClaudeStream    โ”‚
                        โ”‚ Processor +     โ”‚
                        โ”‚ TelegramFormat  โ”‚
                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Components

  • ๐Ÿค– bot.js - Main Telegram bot implementation
  • ๐Ÿ”„ claude-stream-processor.js - Claude CLI integration and streaming
  • ๐Ÿ“ telegram-formatter.js - Message formatting and chunking
  • ๐Ÿงผ telegram-sanitizer.js - Message sanitization

๐Ÿ“‚ Project Structure

claude-code-telegram-control/
โ”œโ”€โ”€ configs/                   # Bot configurations
โ”‚   โ”œโ”€โ”€ bot1.json             # Bot instance configs
โ”‚   โ”œโ”€โ”€ bot2.json
โ”‚   โ””โ”€โ”€ *.json.example        # Example configurations
โ”œโ”€โ”€ scripts/                   # Management scripts
โ”‚   โ”œโ”€โ”€ start-bot.js          # Bot launcher
โ”‚   โ””โ”€โ”€ setup-bot.js          # Interactive setup
โ”œโ”€โ”€ bot.js                     # Main bot implementation
โ”œโ”€โ”€ claude-stream-processor.js # Claude CLI integration
โ”œโ”€โ”€ telegram-formatter.js     # Message formatting
โ”œโ”€โ”€ telegram-sanitizer.js     # Message sanitization
โ””โ”€โ”€ package.json              # Dependencies and scripts

๐Ÿ”ง Troubleshooting

โš ๏ธ Common Issues

๐Ÿค– Bot doesn't respond:

  • Check Telegram token is valid
  • Verify bot is started with correct config
  • Check admin user ID in config

๐Ÿ”ง Claude Code integration fails:

  • Ensure claude command works in terminal
  • Check working directory exists and has proper permissions
  • Verify Claude Code is logged in and configured

๐ŸŽ™๏ธ Voice messages don't work:

  • Check Nexara API key in config
  • Verify internet connectivity
  • Check Nexara account balance

๐Ÿ” Debug Commands

Development Mode

# Check configured bots
npm run list-bots

# Test Claude Code connection
claude --version

# View bot logs
npm run bot1 # Check console output

Production Mode (PM2)

# Check process status
pm2 status

# View live logs
pm2 logs bot1 -f

# View recent logs
pm2 logs bot1 --lines 100

# View all processes logs
pm2 logs

# Interactive monitoring
pm2 monit

# Process information
pm2 info bot1

๐Ÿ”„ Using Git Workflow Features

The bot includes a comprehensive Git management interface accessible through Telegram:

๐Ÿ“Š Git Overview

  • Send /start or click the git button to access the main git interface
  • View current branch, ahead/behind status, file counts
  • Navigate to branches, staging, files, and remote operations

๐ŸŒฟ Branch Management

  • View branches: See current branch with ahead/behind tracking
  • Switch branches: Safe switching with uncommitted changes handling
  • Create branches: Text input with full git validation
    • Type branch name when prompted
    • Automatic validation against git naming rules
    • Conflict detection for existing branches

๐Ÿ“ฆ Staging Operations

  • Staging overview: Separate sections for staged/modified/untracked files
  • Individual file staging: Stage/unstage specific files from file view
  • Bulk operations: Stage All / Unstage All with smart state handling
  • File selection: Paginated interfaces for selecting multiple files

๐Ÿ“ File Operations

  • File browsing: Navigate through changed files with pagination
  • Diff viewing: Examine file changes with configurable context
  • Smart buttons: Context-aware staging/unstaging buttons per file
  • Mobile-optimized: Touch-friendly interface with clear navigation

๐ŸŽฏ Workflow Tips

  • Use the ๐Ÿ“ฆ Staging button from any interface for quick access
  • File view shows real-time staging status for each file
  • Error handling provides helpful guidance for git issues
  • All operations include confirmation and next steps guidance

๐ŸŒ Using File Browser (Web Interface)

The bot includes a modern web-based file browser accessible via public URL:

๐Ÿš€ Getting Started

  • Send /files command to start the file browser server
  • Bot automatically creates a secure ngrok tunnel and provides public URL
  • Click ๐ŸŒ Open File Browser button or copy the URL to any browser

๐Ÿ“ฑ Interface Features

  • ๐Ÿ“ Directory Navigation: Click folders to navigate through your project
  • ๐Ÿ“„ File Viewing: Click files to view content with syntax highlighting
  • ๐Ÿงญ Breadcrumb Navigation: Quick navigation to parent directories
  • ๐Ÿ“ฑ Mobile-Responsive: Optimized for both desktop and mobile devices
  • ๐Ÿ”’ Secure Access: Restricted to your project directory only

๐Ÿ› ๏ธ Server Management

  • ๐Ÿ”„ Auto-Start: Server starts automatically when using /files command
  • โŒ Manual Stop: Use "Stop Server" button to shut down when not needed
  • ๐Ÿ”„ Refresh URL: Get current URL or restart server if needed
  • โšก Auto-Cleanup: Server automatically stops when bot shuts down

๐ŸŒ Remote Access Setup

To enable remote access, you'll need an ngrok account:

  1. Sign up at ngrok.com (free tier available)
  2. Get your auth token from ngrok dashboard
  3. Add token to bot config files:
    {
      "botName": "YourBot",
      "botToken": "...",
      "ngrokAuthToken": "your_ngrok_token_here"
    }
  4. Add to all bot configs: configs/bot1.json, configs/bot2.json, configs/bot3.json, configs/bot4.json
  5. Restart bots to apply changes: pm2 restart all

Note: Bot config files are git-ignored, so your ngrok token stays secure.

๐Ÿ’ก Bypass Warning Banner

To skip ngrok's browser warning, add this header to requests:

ngrok-skip-browser-warning: true

๐Ÿ‘จโ€๐Ÿ’ป Development

๐Ÿš€ Running in Development Mode

npm run dev  # Uses nodemon for auto-restart

๐Ÿงช Testing

npm test    # Run test suite

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make changes
  4. Test with your Claude Code setup
  5. Submit a pull request

๐Ÿ“œ License

MIT License - see LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages