← 开源

Telegram bridge for Claude Code

AI EngineeringBring agent to usersPython
增长势头
+024 小时新增 Star0.0%
611
Star
83
Fork
+-1
本周
1
贡献者
创建于 2026-01-25 · 更新于 2026-12-04 · 今日第 20645 名
主要开发者
README

claudecode-telegram

Telegram bot bridge for Claude Code. Send messages from Telegram, get responses back.

How it works

flowchart LR
    A[Telegram] --> B[Cloudflare Tunnel]
    B --> C[Bridge Server]
    C -->|tmux send-keys| D[Claude Code]
    D -->|Stop Hook| E[Read Transcript]
    E -->|Send Response| A
Loading
  1. Bridge receives Telegram webhooks, injects messages into Claude Code via tmux
  2. Claude Code's Stop hook reads the transcript and sends response back to Telegram
  3. Only responds to Telegram-initiated messages (uses pending file as flag)

Install

# Prerequisites
brew install tmux cloudflared

# Clone
git clone https://github.com/hanxiao/claudecode-telegram
cd claudecode-telegram

# Setup Python env
uv venv && source .venv/bin/activate
uv pip install -e .

Setup

1. Create Telegram bot

Bot receives your messages and sends Claude's responses back.

# Message @BotFather on Telegram, create bot, get token

2. Configure Stop hook

Hook triggers when Claude finishes responding, reads transcript, sends to Telegram.

cp hooks/send-to-telegram.sh ~/.claude/hooks/
nano ~/.claude/hooks/send-to-telegram.sh  # set your bot token
chmod +x ~/.claude/hooks/send-to-telegram.sh

Add to ~/.claude/settings.json:

{
  "hooks": {
    "Stop": [{"hooks": [{"type": "command", "command": "~/.claude/hooks/send-to-telegram.sh"}]}]
  }
}

3. Start tmux + Claude

tmux keeps Claude Code running persistently; bridge injects messages via send-keys.

tmux new -s claude
claude --dangerously-skip-permissions

4. Run bridge

Bridge receives Telegram webhooks and injects messages into Claude Code.

export TELEGRAM_BOT_TOKEN="your_token"
python bridge.py

5. Expose via Cloudflare Tunnel

Tunnel exposes local bridge to the internet so Telegram can reach it.

cloudflared tunnel --url http://localhost:8080

6. Set webhook

Tells Telegram where to send message updates.

curl "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook?url=https://YOUR-TUNNEL-URL.trycloudflare.com"

Bot Commands

Command Description
/status Check tmux session
/clear Clear conversation
/resume Pick session to resume (inline keyboard)
/continue_ Auto-continue most recent
/loop <prompt> Start Ralph Loop (5 iterations)
/stop Interrupt Claude

Environment Variables

Variable Default Description
TELEGRAM_BOT_TOKEN required Bot token from BotFather
TMUX_SESSION claude tmux session name
PORT 8080 Bridge port
排名相邻
同类项目

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载