/guides/telegram-bot
Telegram bot
Deploy free-claude-code as a Telegram bot. Remote autonomous coding with session persistence and voice message support.
Telegram bot
Control Claude Code remotely from Telegram. Same features as Discord: tree-based threading, session persistence, live progress, and voice messages.
Prerequisites
You need:
- A Telegram account
- The Telegram mobile or desktop app
- free-claude-code installed and running
Step 1: Create a Telegram bot
- Message @BotFather on Telegram
- Send
/newbot - Follow prompts:
- Enter a name for your bot (displayed to users)
- Enter a username (must end in
bot, e.g.,claudecode_proxy_bot)
- BotFather will give you a token like
123456789:ABCdefGHIjklMNOpqrSTUvwxYZ - Save this token
Step 2: Get your user ID
- Message @userinfobot
- It will reply with your user ID (a number like
123456789) - Save this ID
This restricts the bot to respond only to you.
Step 3: Configure free-claude-code
Edit .env:
MESSAGING_PLATFORM="telegram"
TELEGRAM_BOT_TOKEN="123456789:ABCdefGHIjklMNOpqrSTUvwxYZ"
ALLOWED_TELEGRAM_USER_ID="123456789"
Replace with your actual token and user ID.
Configure the workspace:
CLAUDE_WORKSPACE="./agent_workspace"
ALLOWED_DIR="/home/yourname/projects"
Step 4: Start the server
uv run uvicorn server:app --host 0.0.0.0 --port 8082
The bot connects to Telegram and will respond to your messages.
Using the bot
Basic usage
Message your bot directly:
Create a React component that displays a sortable table with pagination
The bot streams thinking tokens (if enabled), executes tools, and returns the result.
Threading
Reply to any bot message to continue that conversation:
[Your original request]
↳ [Bot response]
↳ [Your reply: "Add column filtering too"]
In Telegram, this creates a message thread. Each branch is isolated from others.
Commands
| Command | Action |
|---|---|
/stop | Cancel current task |
/stop (as reply) | Cancel specific task |
/clear | Reset all sessions |
/clear (as reply) | Clear branch only |
/stats | Show usage statistics |
Voice messages
Send a voice message in Telegram. The bot:
- Downloads the
.oggaudio - Transcribes using configured Whisper backend
- Processes the text as a normal prompt
Configure voice transcription:
VOICE_NOTE_ENABLED=true
WHISPER_DEVICE="cpu"
WHISPER_MODEL="base"
Install voice extras:
uv sync --extra voice_local # Local Whisper
uv sync --extra voice # NVIDIA NIM voice
For NVIDIA NIM voice:
WHISPER_DEVICE="nvidia_nim"
WHISPER_MODEL="openai/whisper-large-v3"
NVIDIA_NIM_API_KEY="nvapi-your-key"
Differences from Discord
| Feature | Discord | Telegram |
|---|---|---|
| Channels | Multiple allowed channels | Direct message only |
| User control | ALLOWED_DISCORD_CHANNELS | ALLOWED_TELEGRAM_USER_ID |
| Threading | Tree-based (complex) | Linear replies (simpler) |
| Voice | Discord voice messages | Telegram voice messages |
| UI | Rich embeds | Plain text with Markdown |
Telegram is simpler for personal use. Discord scales better for team collaboration.
Security
- Restrict to your user ID:
ALLOWED_TELEGRAM_USER_IDensures only you can interact with the bot - Use a strong bot token: If compromised, regenerate via BotFather with
/revoke - Set allowed directories:
ALLOWED_DIRlimits filesystem access
Troubleshooting
Bot doesn’t respond: Check logs for connection errors. Verify the token is correct.
“User not allowed” errors: Your Telegram user ID changed or was mistyped. Re-check with @userinfobot.
Voice messages fail: Verify voice extras are installed. Check WHISPER_DEVICE is configured.
Sessions lost: Ensure CLAUDE_WORKSPACE is persistent. Check disk space.
Switching from Discord
To switch an existing installation from Discord to Telegram:
- Stop the server
- Change
MESSAGING_PLATFORM="telegram" - Add
TELEGRAM_BOT_TOKENandALLOWED_TELEGRAM_USER_ID - Remove or comment out Discord settings
- Restart the server
The proxy handles one platform at a time. For both simultaneously, run separate instances on different ports.