A Python daemon that bridges Telegram and Claude, allowing you to interact with Claude through Telegram messages.
This bot runs as a daemon on your machine, listening for Telegram messages and executing them with Claude CLI. When you send a message to your bot on Telegram, it:
- Receives the message
- Executes it with Claude CLI
- Sends Claude's response back to you on Telegram
-
Open Telegram and find BotFather
- Search for
@BotFather
in Telegram - Start a chat with BotFather
- Search for
-
Create a new bot
- Send
/newbot
to BotFather - Choose a display name for your bot (e.g., "My Claude Assistant")
- Choose a username ending in
bot
(e.g.,myclaudeassistant_bot
) - BotFather will give you a token like:
9866009637:AAHTj-xtpHlu6rTnzoekRAD-8l-QBGwznME
- Save this token securely - anyone with this token can control your bot
- Send
You need your chat ID so the bot only responds to you. Choose one of these methods:
- Search for
@userinfobot
or@getidsbot
in Telegram - Start a chat with it
- It will immediately tell you your user ID (this is your chat_id)
- Your personal chat ID will be a positive number like
123456789
- Temporarily modify the telegram_daemon.py to print all chat IDs:
async def handle_message(self, update: Update, context: ContextTypes.DEFAULT_TYPE): message = update.message print(f"Received message from chat ID: {message.chat_id}") # Add this line # ... rest of the code
- Run the daemon and send your bot a message
- Look at the console output to see your chat ID
- Remove the debug line once you have your ID
# Replace YOUR_BOT_TOKEN with your actual token
curl https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates
This will show recent messages to your bot in JSON format, including chat IDs.
-
Edit the telegram_daemon.py file Find this line:
chat_id = ""
Replace it with your chat ID:
chat_id = "123456789" # Your actual chat ID
-
Set the bot token Either set it as an environment variable:
export TELEGRAM_BOT_TOKEN=9866009637:AAHTj-xtpHlu6rTnzoekRAD-8l-QBGwznME
Or you can pass it as a command line argument when running.
Run with environment variable:
python telegram_daemon.py
-
Start a conversation
- Open Telegram
- Find your bot by its username
- Send
/start
or any message
-
Send commands to Claude
- Simply type any message and send it
- The daemon will execute it with Claude and send back the response
- Example messages:
- "What's the weather like?"
- "Help me write a Python function to sort a list"
- "Explain quantum computing in simple terms"
-
Special commands
- Send
YOLOLOG
(case insensitive) to get the contents of yolo.log
- Send
- The bot will ONLY respond to messages from your chat ID
- Keep your bot token secret - don't share it or commit it to git
- The daemon runs Claude with
--dangerously-skip-permissions
flag, so be mindful of what commands you send - Consider running the bot on a secure, private server
- Bot not responding: Check that the daemon is running and the token is correct
- "Chat ID not authorized": Make sure you've set the correct chat_id in the code
- Connection errors: Ensure you have internet access and Telegram isn't blocked
- No output: Some Claude commands might not produce output - check the daemon console for errors
- Rate limiting: Telegram has rate limits - avoid sending too many messages too quickly
python-telegram-bot
- Python wrapper for Telegram Bot APIasyncio
- For asynchronous operationssubprocess
- For executing Claude CLI- Claude CLI - Must be installed and accessible in PATH