- Full guide: connect a Claude Code project to a Telegram bot, send it tasks from your phone, and get responses back. Complete code, long-polling bridge, and security included. No server, no webhook.
I requested this guide from Claude Code through a Telegram bot, from my phone, and it wrote the article, published it, and sent me back the link. That is exactly what this guide teaches you to build.
You can control Claude Code directly from Telegram: send it a task from your phone, it runs on your actual project, and sends the response back to your chat. All you need is a Telegram bot and a small script that bridges your messages to the running session. In this guide we'll build that bridge from scratch, with the full code, using simple long-polling, no server and no webhook.
Disclosure: I asked Claude Code to write this guide through a Telegram bot, from my phone. It wrote it, published it, and sent me the link back.
What are we building?
A "bridge" between two sides:
- Telegram to Claude: A script that listens for your messages and wakes the Claude Code session with what you wrote.
- Claude to Telegram: A script that sends Claude's response back to your chat.
In the middle: Claude Code itself, running the task with all the tools it has (editing files, running commands, deploying, calling APIs).
Step 1: Create a Telegram bot and get a token
- Open a chat in Telegram with BotFather (the official bot for creating bots).
- Send
/newbot, choose a name and a username (must end inbot). - You'll receive a token that looks like this:
8927:AA.... This is the key to the entire API. Save it and don't share it, it's like a password.
Step 2: Store your credentials safely
The token and chat ID don't go in your code or in git. Store them in a local file:
# ~/.telegram-creds
TG_TOKEN=the-token-you-got-from-BotFather
TG_CHAT= # will be filled automatically on the first message
chmod 600 ~/.telegram-creds # only you can read it
Step 3: The listening script (Telegram, from you)
The method: long-polling. We ask Telegram "is there a new message?" with a high timeout, and Telegram holds the connection open until a message arrives or the time runs out. Simple, no public address needed.
#!/usr/bin/env bash
set -euo pipefail
set -a; . "${HOME}/.telegram-creds"; set +a
BASE="https://api.telegram.org/bot${TG_TOKEN}"
OFFSET_FILE="${HOME}/.telegram-offset"
offset="$(cat "$OFFSET_FILE" 2>/dev/null || echo 0)"
# timeout=45 -> Telegram holds the connection open for up to 45 seconds (long-polling)
resp="$(curl -s --max-time 60 \
"${BASE}/getUpdates?timeout=45&offset=${offset}&allowed_updates=%5B%22message%22%5D")"
# extract the message + chat id, and advance the offset so we don't read it twice
echo "$resp" | python3 -c '
import sys, json
d = json.load(sys.stdin)
for u in d.get("result", []):
m = u.get("message") or {}
txt = m.get("text")
if txt:
chat = m["chat"]["id"]
print(f"CHAT\t{chat}")
print(f"MSG\t{txt}")
print(f"OFFSET\t{u[\"update_id\"] + 1}")
'
Two important principles here:
- offset: Telegram returns messages in ascending order. We save the last processed number so we don't process the same message again.
- Filter by chat ID: We save the
chatfrom the first message, and from that point we ignore every other chat. This way only you can operate the bot.
Step 4: The sending script (Telegram, from Claude)
#!/usr/bin/env bash
set -euo pipefail
set -a; . "${HOME}/.telegram-creds"; set +a
curl -s -X POST "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" \
--data-urlencode "chat_id=${TG_CHAT}" \
--data-urlencode "text=${1}" \
-d "disable_web_page_preview=true" >/dev/null && echo SENT
Tip: send as plain text (without parse_mode) to avoid all the headaches of escaping in MarkdownV2. Telegram renders Hebrew and RTL perfectly this way.
Step 5: The bridge loop
Now we wire everything together in Claude Code: we ask it to run the listening script, and when a message arrives, it carries out what you asked and returns a response using the sending script. Then it listens again. That's it, a loop:
listen → message arrives → Claude acts → send response → listen again
In practice you tell Claude something like: "Enter Telegram bridge mode: run listen, and for every message that arrives, carry it out and send me a response with send, then listen again." From that point you send it tasks from your phone: "publish the draft", "check how many leads came in today", "run the tests", and it actually does them and reports back in Telegram.
Security: three rules
- Your chat only. Lock to a single
chat id. Messages from anyone else are ignored. - The token is a password. Keep it in a local file with
chmod 600, not in git, not in screenshots. If it leaks, use/revokein BotFather. - Permissions. Claude Code runs with your user's permissions. Give clear instructions, and review what it's about to do when it involves irreversible actions.
Why this is so useful
This turns Claude Code from a tool tied to your desktop into an assistant that's always in your pocket. The same system can also be connected to WhatsApp with Green API, and it's the exact same principle we saw in the meeting scheduling system we built, notifications and commands through chat.
Want to learn to work this way with Claude Code? There's a full Claude Code guide in Hebrew, a Claude Code workshop for organizations, and a private 1-on-1 lesson where we build this together on your own project.
The bottom line
Connecting Claude Code to a Telegram bot is two small bash files and a token from BotFather. No server, no webhook, no HTTPS required, simple long-polling is enough. The result: you control your project from your phone, from anywhere, and get responses in real time.

