Skip to main content

Remote control Claude Code via Telegram - MCP Server with Dynamic Buttons

Project description

Telegram MCP Server

Remote control AI coding assistants (Claude Code / Codex) via Telegram

PyPI Python License

English | 简体中文

Why This Project?

Have you ever encountered these scenarios:

  • 💤 Late at night in bed, you suddenly think of a bug that needs fixing, but don't want to get up and open your laptop?
  • 🚇 On your commute, you want AI to refactor code for you, but your laptop isn't with you?
  • 🏢 Multiple Claude Code or Codex sessions running on remote servers, and you want to check their progress anytime?
  • Long-running tasks (testing, building, refactoring) that take hours, but you don't want to sit in front of the computer?

Telegram MCP Server was created to solve these problems!

Through the MCP (Model Context Protocol), this project allows you to:

  • 📱 Anytime, anywhere view and control AI coding assistants via Telegram
  • 🔄 Multi-session management: Use screen on remote servers to manage multiple projects simultaneously
  • 🌙 True unattended mode: Wait up to 7 days with smart polling, minimal system resources
  • 💬 Simple interaction: Send messages via Telegram to give AI assistants next instructions

Perfect for:

  • 24/7 remote servers
  • Long-running tasks
  • Multi-project parallel development
  • Remote work from anywhere

Features

  • 🌙 True Unattended Mode - Wait up to 7 days with smart progressive polling
  • 📱 Remote Control - Control AI assistants from anywhere via Telegram
  • 🔄 Two-way Communication - Send notifications, receive replies, continuous dialogue
  • 📁 File Operations - View and download project files
  • 🎯 Multi-session Management - Manage multiple projects simultaneously
  • 🤖 Universal Support - Works with both Claude Code and Codex

Quick Start

1. Installation

# Recommended: using uv
uv tool install telegram-mcp-server

# Or using pip
pip install telegram-mcp-server

2. Setup

Option A: Automatic Setup (Recommended)

telegram-mcp-server --setup

Interactive wizard will help you:

  • Create Telegram Bot
  • Get credentials
  • Auto-configure AI assistant

Option B: Manual Setup with mcp add

If you already have your Telegram Bot Token and Chat ID, you can quickly add using the mcp add command:

Claude Code:

claude mcp add \
  --transport stdio \
  telegram \
  --env TELEGRAM_BOT_TOKEN=YOUR_TOKEN_HERE \
  --env TELEGRAM_CHAT_ID=YOUR_CHAT_ID_HERE \
  -- \
  uvx telegram-mcp-server

Codex:

codex mcp add telegram \
  --env TELEGRAM_BOT_TOKEN=YOUR_TOKEN_HERE \
  --env TELEGRAM_CHAT_ID=YOUR_CHAT_ID_HERE \
  -- \
  npx -y telegram-mcp-server

Gemini CLI:

gemini mcp add telegram uvx telegram-mcp-server \
  -e TELEGRAM_BOT_TOKEN=YOUR_TOKEN_HERE \
  -e TELEGRAM_CHAT_ID=YOUR_CHAT_ID_HERE

💡 Tip: Replace YOUR_TOKEN_HERE and YOUR_CHAT_ID_HERE with your actual values

3. Usage

# Recommended: Start with bypass permissions mode
# Avoid interruptions due to permission confirmations during AI-Telegram interaction
# Note: Cannot run as root due to security mechanisms

# Claude Code
claude --permission-mode bypassPermissions

# Codex
codex --dangerously-bypass-approvals-and-sandbox

# In the AI assistant
> Enter unattended mode. Task: analyze project structure

Check results in Telegram and continue the conversation!

How It Works

AI Assistant (Claude Code/Codex)
  ↓ MCP Protocol
MCP Server (telegram-mcp-server)
  ├─ 8 tools (notify, wait, file operations, etc.)
  └─ Telegram Bot (background process)
      ↓ Telegram API
Your Telegram Client

Core Features

MCP Tools (8 tools)

  • telegram_notify - Send structured notifications (recommended)
  • telegram_wait_reply - Wait for user reply (blocking poll)
  • telegram_unattended_mode - Unattended mode (smart loop)
  • telegram_send_code - Send code (with syntax highlighting)
  • telegram_send_image - Send images
  • telegram_send_file - Send files
  • telegram_send - Send free-form messages
  • telegram_get_context_info - Get session context info

Telegram Commands (6 commands)

  • /sessions - List all sessions
  • /status <id> - Check session status
  • /to <id> <msg> - Send message to session
  • /file <id> <path> - View file
  • /delete <id> - Delete session
  • /help - Show help

Smart Polling

Progressive polling strategy, wait up to 7 days:

Wait Time Check Frequency Response Delay
0-30 min Every 30s Max 30s
30-60 min Every 60s Max 60s
1+ hour Every 120s Max 120s

Use Cases

Scenario 1: Overnight Tasks

# 10 PM
> Enter unattended mode. Task: run full test suite and fix all errors

# 8 AM - check results in Telegram

Scenario 2: Remote Work

# At office
> Enter unattended mode. Task: refactor database access layer

# On the road - monitor and control via Telegram

Scenario 3: Multi-project Management (Remote Server + screen)

# SSH to remote server
ssh user@server

# Create multiple screen sessions
screen -S project-a
cd /path/to/project-a
TELEGRAM_SESSION="proj-a" claude --permission-mode bypassPermissions
# Ctrl+A D to detach

screen -S project-b
cd /path/to/project-b
TELEGRAM_SESSION="proj-b" codex --dangerously-bypass-approvals-and-sandbox
# Ctrl+A D to detach

# Manage both projects in Telegram
# Sessions keep running even after closing SSH

Scenario 4: Late Night in Bed

# During the day, start session on server
screen -S night-task
TELEGRAM_SESSION="night-fix" claude --permission-mode bypassPermissions

# At night in bed, send commands via Telegram
/to night-fix Fix null pointer exception in auth.py

# Next morning, check results
/status night-fix

Configuration

Claude Code

Supports three configuration scopes:

MCP Server Configuration:

  • User scope: ~/.claude.json - Global config
  • Project scope: .mcp.json - Team shared
  • Local scope: .claude.json - Project specific

Environment Variables (auto-configured):

  • ~/.claude/settings.json - Contains MCP_TOOL_TIMEOUT=604800000 (7-day timeout)

Codex

Global config: ~/.codex/config.toml

Auto-includes tool_timeout_sec = 604800 (7 days timeout)

Environment Variables

# Custom session name
TELEGRAM_SESSION="my-task" claude

# Custom max wait time
TELEGRAM_MAX_WAIT=86400 claude  # 24 hours

# Custom poll intervals
TELEGRAM_POLL_INTERVAL="10,30,60" claude

Troubleshooting

Issue: Telegram Bot Not Responding

# Check logs
tail -f /tmp/telegram-mcp-server.log

# Quick fix
cd telegram-mcp-server
./quick_fix.sh

Issue: Codex 60s Timeout

# Auto fix
./fix_codex_timeout.sh

Issue: Session Not Registered

# Reconfigure
telegram-mcp-server --setup

Documentation

Requirements

  • Python 3.10+
  • Claude Code or Codex
  • Telegram account

Contributing

Contributions welcome! See CONTRIBUTING.md

License

MIT License - see LICENSE

Support


Let AI coding assistants work for you, not you waiting for them 🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram_mcp_server-0.2.0.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_mcp_server-0.2.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file telegram_mcp_server-0.2.0.tar.gz.

File metadata

  • Download URL: telegram_mcp_server-0.2.0.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for telegram_mcp_server-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7cde856b06a02d61baf7ad06aef10246966905ff31cd429a5abd6831269a54e0
MD5 af7a326481cbe051b3c7ea121bf6deb7
BLAKE2b-256 19c9c04b490fa6575dd0d2503c1f57ba9d961d95c257d86fea3a0ad394917fd3

See more details on using hashes here.

File details

Details for the file telegram_mcp_server-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_mcp_server-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8697a0d6654191ce1ba9ce1d3f36680fe8c915b12d8918c5acb649d0bf2d1b33
MD5 b66d20e4a8840f005fca18cb37befc34
BLAKE2b-256 f44c875ccaca6a24684f85dc59ce8caa4c0b7fe55b25a8140e5b8a6e0c3f40bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page