Mirror your local Claude Code sessions into a single Telegram group and drive them back from your phone. Every session shows up tagged, so you can watch several at once and reply to the exact one you mean.
Pure Python 3 standard library — no pip dependencies. Companion to claude-code-toast.
⚠️ Read the Security section before installing. WithbypassPermissions(the default), anyone who can post to your Telegram group can run commands on your machine as you.
Claude Code session ──hooks──▶ bridge daemon ──▶ Telegram group
(any number, live) ◀── your replies
- Mirror: when a session asks for input or finishes a turn, its prompt/answer is posted to the group, tagged like
[myproject#4a1c](folder name + short session id). - Reply: reply to a mirrored message — or write
#tag your text— and the bridge resumes that session with your text viaclaude -p --resume. The answer mirrors straight back. - Multiple sessions in parallel: each Claude Code window is a distinct tag. Plain text (no reply, no tag) goes to the most recently active session.
- Commands:
/sessionslists what's live,/new <dir> <prompt>starts a fresh session in a directory,/help.
Claude Code ships an official Telegram channel (research preview). It pushes messages into one paired session and needs Bun. It's great for a single session — use it if that's all you need. This project is different: it mirrors every session at once through hooks and routes replies by tag, using only Python stdlib. One bot token drives one group; one getUpdates poller (two pollers on the same token collide with a 409).
- Python 3.8+ (
py --version) — stdlib only - Claude Code CLI on your PATH
- A Telegram bot token (@BotFather →
/newbot) and a group chat id - Windows is first-class (installer + Scheduled Task). macOS/Linux run the same daemon; see macOS / Linux.
irm https://raw.githubusercontent.com/petrosalex/claude-code-tg-bridge/main/install.ps1 | iexThen:
- Create the bot & group. Make a bot with BotFather, create a Telegram group, add the bot to it. Get the group's chat id: add the bot, post a message, open
https://api.telegram.org/bot<TOKEN>/getUpdates, readchat.id(group ids are negative). - Fill in the config at
~/.claude/tg-bridge.json: setbot_tokenandchat_id. - Start the daemon — either enable autostart:
Installing from a clone lets you pass
irm https://raw.githubusercontent.com/petrosalex/claude-code-tg-bridge/main/install.ps1 | iex; # then: # re-run the local installer with -Autostart, or start manually: pythonw -X utf8 "$env:USERPROFILE\.claude\tg-bridge\bridge.py"
-Autostartto register a logon Scheduled Task:git clone https://github.com/petrosalex/claude-code-tg-bridge.git cd claude-code-tg-bridge .\install.ps1 -Autostart schtasks /Run /TN ClaudeTgBridge
- Restart open Claude Code sessions so the hooks load. New turns start mirroring.
The installer copies bridge.py to ~/.claude/tg-bridge/, the hook to ~/.claude/hooks/, and merges three hooks (Stop, UserPromptSubmit, SessionStart) into ~/.claude/settings.json alongside whatever hooks you already have (timestamped backup first, idempotent, validated).
irm https://raw.githubusercontent.com/petrosalex/claude-code-tg-bridge/main/uninstall.ps1 | iexRemoves the hooks (only ours), the daemon files, and the Scheduled Task. Your ~/.claude/tg-bridge.json is left in place.
| Key | Default | Meaning |
|---|---|---|
bot_token |
— | BotFather token (required) |
chat_id |
— | Group chat id, quoted string, usually negative (required) |
allowed_user_ids |
[] |
If non-empty, only these Telegram user ids may drive sessions |
port |
8765 |
localhost port the daemon listens on for hook events |
permission_mode |
bypassPermissions |
Passed to claude -p --permission-mode |
exec_timeout |
1800 |
Seconds before a runaway claude -p is killed (process tree) |
max_age_min |
15 |
Telegram messages older than this are skipped (backlog after downtime) |
claude_cmd |
claude |
Executable name/path; auto-resolved with fallbacks |
mirror |
true |
Set false to disable outbound mirroring (still accept commands) |
This tool lets a Telegram chat run code on your computer. Treat it like SSH.
bypassPermissionsruns tools without asking. A message routed to a session executes with whateverpermission_modeyou set. The default skips permission prompts — convenient, but it means the group is a remote shell. Use a private group.- Lock down senders. Set
allowed_user_idsto just your own Telegram user id so a leaked/guessed group can't drive your machine. The daemon already hard-filters to the single configuredchat_idand silently drops everything else. - The bot token is a credential. It lives only in your local config; it is never committed. Anyone with it can post as your bot.
- The daemon binds 127.0.0.1 only — hooks reach it locally; nothing is exposed to the network.
- Hooks (
hooks/tg-post.ps1/.sh) read the hook JSON on stdin and POST it to127.0.0.1:<port>with a short timeout, always exit 0, and print nothing — a stopped daemon never slows Claude down. They runasync, so they never block a turn. - The daemon (
bridge.py) runs three things feeding one worker thread (the only writer of state and the only sender to Telegram, so there's no interleaving): an HTTP receiver for hook events, agetUpdateslong-poll, and a bounded pool ofclaude -pexecutors. - Mirroring:
Stopparses the tail of the session's JSONL transcript for the last assistant text turn;UserPromptSubmitmirrors the prompt. - Routing survives a lost state file: the tag is embedded in every mirrored message, so a reply resolves even if the in-memory message→session map missed.
- Resume behavior: verified that
claude -p --resume <id>(without--fork-session) keeps the same session id, so a TG-driven turn stays the same session and its answer mirrors back through the same hooks. The code also handles the fork case defensively. - Prompts are passed to
claudeon stdin, never as an argv string, so arbitrary Telegram text can't be shell-interpreted (Windows.cmdargument-injection class, CVE-2024-24576) and long/multi-line prompts work.
The daemon is cross-platform. Install the hook and wire it yourself:
mkdir -p ~/.claude/tg-bridge ~/.claude/hooks
curl -fsSL https://raw.githubusercontent.com/petrosalex/claude-code-tg-bridge/main/bridge.py -o ~/.claude/tg-bridge/bridge.py
curl -fsSL https://raw.githubusercontent.com/petrosalex/claude-code-tg-bridge/main/hooks/tg-post.sh -o ~/.claude/hooks/tg-post.sh
chmod +x ~/.claude/hooks/tg-post.shAdd these to ~/.claude/settings.json (alongside existing hooks), then create ~/.claude/tg-bridge.json:
{
"hooks": {
"Stop": [{ "matcher": "", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/tg-post.sh", "async": true, "timeout": 10 }] }],
"UserPromptSubmit":[{ "matcher": "", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/tg-post.sh", "async": true, "timeout": 10 }] }],
"SessionStart": [{ "matcher": "", "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/tg-post.sh", "async": true, "timeout": 10 }] }]
}
}Run the daemon with python3 -X utf8 ~/.claude/tg-bridge/bridge.py. A sample systemd user unit:
# ~/.config/systemd/user/claude-tg-bridge.service
[Unit]
Description=claude-code-tg-bridge
[Service]
ExecStart=%h/.claude/tg-bridge/venvless python3 -X utf8 %h/.claude/tg-bridge/bridge.py
Restart=on-failure
[Install]
WantedBy=default.targetsystemctl --user enable --now claude-tg-bridge (adjust the python3 path).
- Answers are truncated (~3500 chars, at most 2 messages). Plain text only, no Markdown.
- No inline buttons, no permission-prompt relay (in
-p, prompts can't be answered interactively — setpermission_modeinstead), no file/image transfer, no progress streaming. - One bot, one group, basic groups (no forum topics).
- Resuming a session that's also open interactively in a terminal right now is not guaranteed by Claude Code; drive a given session from one place at a time.
- The inbound path (Telegram →
claude -p) is covered by unit routing tests plus a real--resumerun; the mirror-back and outbound paths are verified live end-to-end.
Sibling of claude-code-toast. Inspired by community bridges like ccgram. MIT.