Screen-based auto-responder watchdog for Claude Code TUI
Project description
claude-code-telegrammer
Screen-based auto-responder watchdog for Claude Code TUI
Problem
Claude Code's TUI blocks on permission prompts (y/n, y/y/n) and goes idle after completing tasks. Running Claude Code as an autonomous agent -- for example, as a Telegram bot -- requires something to detect these states and respond automatically, or the agent stalls within seconds.
Solution
claude-code-telegrammer polls a GNU Screen session, detects Claude Code's TUI state via pattern matching, and sends the appropriate keystrokes to keep the agent running unattended. No modifications to Claude Code itself -- just screen buffer inspection and keystroke injection.
Claude Code (in screen)
|
+-- telegrammer-watchdog polls screen buffer every 1.5s
| |
| +-- Detects "y/n" prompt --> sends "1" (accept)
| +-- Detects "y/y/n" prompt --> sends "2" (accept all)
| +-- Detects idle/waiting --> sends "/speak-and-call"
|
+-- telegrammer-guard ensures single instance via lock file
Installation
Requires Python >= 3.10 and GNU Screen.
pip install claude-code-telegrammer
Or install from source:
git clone https://github.com/ywatanabe1989/claude-code-telegrammer.git
cd claude-code-telegrammer
pip install -e .
Quickstart
# Start an agent from a YAML config
telegrammer start --config config/telegram-master.yaml
# Check status
telegrammer status
# Attach to the screen session to observe
screen -r cld-telegram # Ctrl-A D to detach
Components
telegrammer
Main CLI entry point. Manages the full lifecycle of a Claude Code Telegram agent in a screen session.
telegrammer start --config telegram-master.yaml
telegrammer stop
telegrammer status
telegrammer restart
telegrammer-watchdog
The core auto-responder. Polls a screen session at a configurable interval, detects Claude Code's TUI state, and sends keystrokes.
telegrammer-watchdog --session cld-telegram --interval 1.5
telegrammer-watchdog --dry-run # detect without responding
telegrammer-watchdog --self-test # run built-in state detection tests
telegrammer-guard
Lock/exclusivity guard. Ensures only one telegrammer instance controls a session at a time.
telegrammer-guard acquire --lock ~/.claude/channels/telegram/telegram.lock
telegrammer-guard release
telegrammer-guard status
telegrammer-guard check # exit 0 if locked, 1 if not
telegrammer-guard force # force-remove lock
telegrammer-init
Sends startup commands to a running Claude Code screen session and optionally configures Telegram access.json.
telegrammer-init --session cld-telegram --config telegram-master.yaml
State Detection
The watchdog reads the screen buffer and matches against these patterns:
| State | Pattern | Response |
|---|---|---|
| Permission prompt (y/n) | Claude asking for single approval | Send 1 (yes) |
| Permission prompt (y/y/n) | Claude asking with "yes to all" option | Send 2 (yes to all) |
| Idle / waiting | Agent completed task, waiting for input | Send /speak-and-call |
Responses are configurable via YAML or environment variables:
export TELEGRAMMER_RESP_Y_N="1"
export TELEGRAMMER_RESP_Y_Y_N="2"
export TELEGRAMMER_RESP_WAITING="/speak-and-call"
Configuration
apiVersion: telegrammer/v1
kind: Agent
metadata:
name: telegram-master
spec:
model: opus[1m]
channels:
- plugin:telegram@claude-plugins-official
flags:
- --dangerously-skip-permissions
- --continue
workdir: ~/proj
env:
CLAUDE_AGENT_ROLE: telegram
CLAUDE_AGENT_ID: telegram-master
screen:
name: cld-telegram
watchdog:
enabled: true
interval: 1.5
responses:
y_n: "1"
y_y_n: "2"
waiting: "/speak-and-call"
lock:
path: ~/.claude/channels/telegram/telegram.lock
restart:
enabled: false
max_retries: 3
backoff: exponential
Part of SciTeX
claude-code-telegrammer is part of SciTeX. It is the low-level watchdog engine used by scitex-agent-container for higher-level agent lifecycle management.
pip install scitex-agent-container[telegram]
When used together, scitex-agent-container handles lifecycle management (health checks, restart policies, hooks) while claude-code-telegrammer handles the screen-level auto-response.
Four Freedoms for Research
- The freedom to run your research anywhere -- your machine, your terms.
- The freedom to study how every step works -- from raw data to final manuscript.
- The freedom to redistribute your workflows, not just your papers.
- The freedom to modify any module and share improvements with the community.
AGPL-3.0 -- because we believe research infrastructure deserves the same freedoms as the software it runs on.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_code_telegrammer-0.2.0.tar.gz.
File metadata
- Download URL: claude_code_telegrammer-0.2.0.tar.gz
- Upload date:
- Size: 390.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2dc3a3448d43edd4a82bf38f8b059c502da21ed23bd6dae6497f88c3c0ecb36
|
|
| MD5 |
47a719242fcb1afffc91eaf94a7a05a9
|
|
| BLAKE2b-256 |
5cc3bc0aecc2fe960ec6aafd5b39feed49c2aff6fd19cc180d83fee959486adc
|
File details
Details for the file claude_code_telegrammer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: claude_code_telegrammer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a35aace477defb584e7081b8b0802fa442fe10a21e7a8a4733463de0f93856f4
|
|
| MD5 |
3694dffa1a61fc4c566259125bc356ac
|
|
| BLAKE2b-256 |
3703b258721f2994a3ef21d6214bd12d6c9a9eb039ace9b1f524ceec187d5238
|