kittenshome

Cc Tg Watchdog — Development skill for Claude Code

Development community

Claude Code + Telegram watchdog script for 24/7 VPS uptime.

How to install Cc Tg Watchdog

This entry records only its repository, not the path inside it, so there is no exact command to give. Open kittenshome/cc-tg-watchdog and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What Cc Tg Watchdog does

Claude Code + Telegram watchdog script for 24/7 VPS uptime.

Alternatives in Development

  • Telegram — Show Telegram bot status and manage global session 1.3k ★
  • Agentlas Connect — Connect Agentlas agents or teams to Telegram 1.1k ★
  • Claude Telegram Relay — Minimal pattern for running Claude Code as an always-on Telegram bot 326 ★

README

Claude Code Telegram 看门狗脚本

一套在 Linux VPS 上守护 Claude Code + Telegram 长驻会话的实用脚本:异常重启、上下文自动换气、漏回消息恢复,以及登录凭证刷新尝试。

[!IMPORTANT] 这是个人环境中长期运行后整理出的脚本,不是 Anthropic/Telegram 官方组件,也不能保证 100% 不丢消息。默认阈值、界面文案和进程特征可能随 Claude Code 或插件版本变化,请先在测试 bot 上验证。

解决什么问题

在 VPS 上跑 `claude --channels plugin:telegram@claude-plugins-official`,迟早会遇到:

  • tmux 进程悄悄死掉
  • 撞上额度弹窗卡住不动
  • Telegram 的 Bun 进程断连
  • API 凭证过期,401 死循环
  • 上下文窗口越来越大,每句话烧一大把 token
  • 换气/重启那一刻刚好来了消息,没人回

这套脚本针对以上故障做自动检测和恢复;实际效果取决于 Claude Code、Telegram 插件版本和你的 VPS 环境。

架构

crontab(每3分钟)
  |
  v
tgbot-watchdog.sh ── 检查健康 ── 正常?跳过
  |                                  |
  |(出问题了)                       |
  v                                  |
tgbot.sh ── 杀旧进程                 |
  |      ── 补回漏掉的消息            |
  |      ── 刷新凭证                  |
  |      ── 启动新 tmux 会话          |
  |      ── 验证 Telegram 连接        |
  v                                  |
claude --channels plugin:telegram  <-+
  (跑在 tmux "tgbot" 里)

快速开始

前置条件

  • 一台 VPS,装好 Claude Code CLI 并登录
  • Telegram 插件(plugin:telegram@claude-plugins-official
  • tmux
  • python3flocktimeoutss(常见 Debian/Ubuntu 可分别由 python3util-linuxcoreutilsiproute2 提供)
  • 已在 Claude Code Telegram 插件中安全配置 bot token

强烈建议 Telegram 单独使用一个 `CLAUDE_CONFIG_DIR`,避免看门狗读到普通 Claude Code 项目的会话,或重启错误的频道实例。不要把 `.credentials.json`、bot token、OAuth token、会话 JSONL、日志或真实记忆补丁提交到仓库。

1. 复制脚本

cp watchdog.sh ~/tgbot-watchdog.sh
cp start.sh ~/tgbot.sh
cp orphan-recovery.py ~/tgbot-orphan.py
chmod +x ~/tgbot-watchdog.sh ~/tgbot.sh

2. 配置

编辑 `tgbot.sh` 和 `tgbot-watchdog.sh`,确保两边使用相同配置。下面是 root 用户示例;非 root 用户请使用自己的 `$HOME`:

# 建议 Telegram 使用独立配置目录(.credentials.json 所在位置)
CLAUDE_CONFIG_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude-tgbot}"

# tmux 会话名
SESSION_NAME="tgbot"

# 使用的模型
MODEL="claude-sonnet-4-6"

如果 Claude 会话不是从 `$HOME` 启动,还要在两个脚本中显式设置该会话的 JSONL 目录:

PROJECT_DIR="/path/to/claude-config/projects/"

脚本不会替你生成 Telegram bot