ByteNoteByteNote

字节笔记本

2026年5月3日

claudecode-telegram - Claude Code 的 Telegram 桥接工具

API中转
¥120

Telegram bot bridge for Claude Code,通过 Telegram 与 Claude Code 交互,支持持久会话和远程控制。

工作原理

核心流程

  1. Bridge 接收 Telegram webhooks,通过 tmux 将消息注入到 Claude Code
  2. Claude Code 的 Stop hook 读取对话记录并将响应发送回 Telegram
  3. 仅响应由 Telegram 发起的消息(使用 pending 文件作为标志)

核心功能

特性说明
双向通信从 Telegram 发送消息,接收 Claude Code 响应
持久会话使用 tmux 保持 Claude Code 持续运行
隧道暴露通过 Cloudflare Tunnel 暴露本地服务
Hook 集成利用 Claude Code Stop hook 自动响应

安装与使用

前置要求

bash
brew install tmux cloudflared

安装步骤

bash
git clone https://github.com/hanxiao/claudecode-telegram
cd claudecode-telegram
uv venv && source .venv/bin/activate
uv pip install -e .

配置步骤

  1. 在 Telegram 中给 @BotFather 发消息,创建 bot 并获取 token
  2. 配置 Stop Hook 脚本
  3. 启动 tmux + Claude Code
  4. 运行 Bridge 服务
  5. 通过 Cloudflare Tunnel 暴露服务
  6. 设置 Telegram Webhook

Bot 命令

命令描述
/status检查 tmux 会话状态
/clear清空当前对话
/resume选择要恢复的会话
/continue_自动继续最近的会话
/loop <prompt>启动 Ralph Loop(5 次迭代)
/stop中断 Claude 执行

适用场景

  • 移动端访问:通过 Telegram 在手机上使用 Claude Code
  • 持续会话:保持 Claude Code 长时间运行
  • 自动化:结合 Ralph Loop 实现自主任务执行
  • 远程控制:从任何地方控制本地 Claude Code

相关链接

Claude 系列模型在长上下文和安全性方面有独特的优势。200K 的上下文窗口让 Claude 可以一次性处理整本小说或完整的代码库,大幅减少了多轮交互的需求。Claude Code 作为 CLI 编程助手,提供了和 Cursor、GitHub Copilot 不同的交互体验,更加适合熟悉终端的开发者使用。Sonnet 模型在速度和质量的平衡上表现很好,适合作为日常开发的主力模型。Opus 模型追求极致的质量,适合处理复杂推理和创意任务。Anthropic 对模型安全的重视也值得关注,通过宪法 AI 等技术手段让模型更安全、更可控。对于企业用户来说,Claude 的安全特性和可解释性是选择的重要因素。

分享: