Control your tmux terminal sessions remotely via Telegram. Perfect for monitoring long-running tasks, managing servers, or using CLI tools like Claude Code from your phone.
- Real-time Output - Stream terminal output to Telegram
- Text Input - Send commands and text to terminal
- Control Keys - Arrow keys, Tab, Esc, Ctrl+C, Backspace, Enter
- Input Modes - Auto (with Enter) or Wait (manual Enter)
- Mobile Friendly - Resize terminal width for phone screens
- Session Management - Create new sessions or connect to existing ones
- User Authentication - Whitelist-based access control
- Python 3.10+
- tmux
- Telegram Bot Token (from @BotFather)
git clone https://github.com/liuxsh9/TerminalBot.git
cd TerminalBot
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync
# Configure
cp .env.example .env
# Edit .env with your settingsEdit .env:
# Get from @BotFather on Telegram
TELEGRAM_BOT_TOKEN=your_bot_token_here
# Your Telegram user ID (get from @userinfobot)
# Multiple users: comma-separated (123,456,789)
AUTHORIZED_USERS=123456789
# Terminal polling interval in seconds (default: 1)
POLL_INTERVAL=1
# Number of terminal lines to display (default: 30)
TERMINAL_LINES=30
# Default working directory for new sessions (default: ~)
DEFAULT_WORK_DIR=~uv run terminalbotFor long-running use, deploy with a process manager to ensure the bot stays running:
# Automated installation (detects environment and recommends best method)
./install/install.sh
# Or specify a method:
./install/install.sh --pm2 # PM2 (recommended, cross-platform)
./install/install.sh --systemd # Linux with systemd
./install/install.sh --launchd # macOS
./install/install.sh --fallback # Simple restart scriptSee Deployment section for details.
Then in Telegram:
/new- Create a new tmux session/connect- Or connect to an existing session- Send text to input to terminal
/keys- Show control keys panel/resize 60- Optimize width for mobile
| Command | Description |
|---|---|
/new [name] |
Create new tmux session and connect |
/list |
List available tmux panes |
/connect |
Connect to a pane (interactive) |
/resize <width> |
Set terminal width (e.g., /resize 60) |
/refresh |
Refresh terminal display |
/disconnect |
Disconnect from session |
/delete |
Delete a tmux session (interactive) |
/start |
Welcome message |
/keys |
Show control keys panel |
/update |
Update bot from git and restart |
/shutdown |
Shutdown the bot (requires manual restart) |
/help |
Show detailed help |
The /keys command shows an inline keyboard:
[Esc] [⬆️] [⌫] [⏎]
[⬅️] [⬇️] [➡️] [Tab]
[^C] [^C^C] [⇧Tab] [Auto]
The /resize command shows preset width options:
[30] [60] [80]
[90] [120] [Reset]
Or use directly: /resize 70
- Auto (default): Messages sent with Enter automatically
- Wait: Messages sent without Enter - press ⏎ manually
Toggle using the Auto/Wait button in the control keys panel.
For production use, TerminalBot includes automatic restart, recovery from system sleep, and deployment configurations.
PM2 provides automatic restarts, log management, and boot startup on Linux, macOS, and WSL.
Quick Start:
# Install Node.js and PM2
npm install -g pm2
# Deploy
pm2 start install/pm2/ecosystem.config.js
pm2 save
pm2 startup # Enable auto-start on bootManagement:
pm2 status # Check status
pm2 logs terminalbot # View logs
pm2 restart terminalbot # Restartcp install/fallback/systemd/terminalbot.service ~/.config/systemd/user/
systemctl --user enable --now terminalbotcp install/fallback/launchd/com.terminalbot.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.terminalbot.plistFor environments without PM2 or system service managers:
# Run in foreground
./install/fallback/run_bot.sh
# Run in background
nohup ./install/fallback/run_bot.sh &All deployment methods include:
- Auto-restart on crash: Bot restarts automatically if it fails
- Sleep/wake recovery: Detects system sleep and reconnects
- Network resilience: Automatic retry with exponential backoff
- Memory limits: Prevents resource exhaustion
- Log management: Centralized logging for troubleshooting
| Method | Location |
|---|---|
| PM2 | ./logs/output.log, ./logs/error.log |
| systemd | journalctl --user -u terminalbot -f |
| launchd | ~/terminal-bot/logs/output.log |
| Fallback script | ./logs/bot.log |
Check logs for errors. Common issues:
.envfile misconfigured (missing TOKEN or USERS)- Telegram token invalid
- Python/uv not in PATH
The bot automatically detects sleep and reconnects. If issues persist:
- Check logs for reconnection attempts
- Verify network connectivity after wake
- Consider using PM2 for additional recovery
The bot includes automatic retry with exponential backoff:
- Transient errors: Retries automatically (1s, 2s, 4s, ... up to 5min)
- Check Telegram API status if persistent
- Verify internet connectivity
PM2:
pm2 startup
pm2 savesystemd:
loginctl enable-linger $USER
systemctl --user enable terminalbotlaunchd:
# Verify plist is in correct location
ls -l ~/Library/LaunchAgents/com.terminalbot.plist- Check deployment-specific README files in
install/directory - Review logs for detailed error messages
- Ensure all requirements are installed (Python 3.10+, tmux, uv)
- Use
/resize 60for comfortable mobile viewing - Unknown
/commandsare forwarded to terminal when connected - Use Wait mode for multi-line input or precise control
MIT