Skip to main content

Custom Telegram MCP server + TUI auto-responder for running Claude Code as an autonomous Telegram agent

Project description

claude-code-telegrammer

SciTeX

Custom Telegram MCP server + TUI auto-responder for running Claude Code as an autonomous Telegram agent

PyPI version Documentation Tests License: AGPL-3.0

Documentation · pip install claude-code-telegrammer


What it is: a self-contained Telegram bridge for Claude Code — a Bun MCP server that turns any Claude Code session into an autonomous agent you talk to over Telegram, plus a TUI watchdog that keeps it running unattended. Each agent runs its own bot, its own message store, and fails loud on misconfiguration.

Problem and Solution

# Problem Solution
1

Hardcoded paths

The official plugin hardcodes ~/.claude/ as its state directory (#851), making it impossible to run multiple bots or customize where access.json lives.

Configurable state directory

All state (DB, lock, access config) lives under CLAUDE_CODE_TELEGRAMMER_AGENT_STATE_DIR. Run as many bots as you want, each with its own isolated state.
2

409 Conflict crashes

No single-instance guard — multiple sessions polling the same bot get 409 errors and crash each other (#1075).

PID-based lock

Automatic single-instance enforcement via PID lock file. Second instance detects the conflict and waits instead of crashing.
3

Zombie CPU consumption

After session ends, the plugin process lingers at 100% CPU — requires manual kill (#1146).

Clean shutdown

Exits gracefully on stdin close, SIGTERM, or SIGINT. No zombies, no manual cleanup.
4

Only 3 basic tools

The official plugin provides just send, get_updates, and set_reaction — no history, no search, no file handling, no message editing.

10 MCP tools

reply, react, edit_message, get_history, get_unread, mark_read, download_attachment, send_document, search_messages, get_context — everything an autonomous agent needs.
5

No message persistence

Messages vanish after delivery. No way to search past conversations, track read status, or build context from history.

SQLite message store

All messages persisted in WAL-mode SQLite with full-text search, reply threading (reply_to_message_id), read/replied tracking, and attachment metadata.
6

No access control for groups

Basic allowlist only — no per-group policies, no hot-reload when config changes.

DM + group policies

Allowlist-based access control with separate DM and group chat policies via access.json, hot-reloaded on file change (mtime-based).
7

No attachment support

Cannot download inbound files or upload documents to chats.

Full attachment handling

Inbound photos, documents, voice, audio, and video are auto-downloaded. Upload local files via send_document tool.
8

Sessions stall unattended

Claude Code halts at permission prompts or idle states with no way to recover — the agent just stops working.

TUI Watchdog

Polls GNU Screen buffer, detects TUI state via pattern matching, sends keystrokes to auto-accept prompts and re-engage on idle. Throttled with burst limits.

Table 1. Eight issues with the official Telegram plugin (as of April 2026) and how claude-code-telegrammer addresses each.

Quickstart

Prerequisites: Bun ≥ 1.0 (MCP server); GNU Screen (watchdog, optional).

git clone https://github.com/ywatanabe1989/claude-code-telegrammer.git
cd claude-code-telegrammer/ts && bun install

1. Get a bot token — message @BotFather, send /newbot, and copy the token (123456789:AAH...). Open your bot and send it any message. Verify: curl -s "https://api.telegram.org/bot<TOKEN>/getMe".

2. Register the MCP server with Claude Code — copy .mcp.json.example to .mcp.json (gitignored) and set CLAUDE_CODE_TELEGRAMMER_BOT_TOKEN + CLAUDE_CODE_TELEGRAMMER_ALLOWED_USERS (your Telegram user id, from @userinfobot). Full env reference: docs/configuration.md.

3. Run:

claude --dangerously-skip-permissions \
       --dangerously-load-development-channels server:claude-code-telegrammer

You should see Listening for channel messages from: server:claude-code-telegrammer. Message your bot from Telegram — Claude Code receives it as a channel notification.

Architecture

flowchart LR
    op["Operator<br/>(Telegram app)"]
    bot["Telegram Bot API<br/>per-agent bot token"]
    op <-->|messages| bot

    subgraph agent["One agent — isolated home"]
        direction TB
        srv["telegram-server.ts<br/>(Bun MCP server)"]
        gate{"allowlist gate<br/>CCT_ALLOWED_USERS<br/>+ access.json"}
        db[("state dir · per-agent<br/>messages.db · lock<br/>CCT_AGENT_STATE_DIR")]
        cc["Claude Code<br/>(the agent)"]
        srv -->|inbound| gate
        gate -->|"allowed → channel notification"| cc
        cc -->|"reply · react · send_document (MCP stdio)"| srv
        srv <--> db
    end

    bot -->|"getUpdates (long-poll)"| srv
    srv -->|sendMessage| bot

The MCP server long-polls Telegram, gates inbound messages through the allowlist, and delivers them to Claude Code as channel notifications; the agent replies through MCP tools. Each agent is self-contained — its own bot token, its own per-agent state dir, its own poller — and fails loud at startup on any misconfiguration (missing/invalid token, unexpanded ${…}, or a renamed env var). Deep dive: docs/architecture.md.

Interfaces

  • MCP server — 11 tools over stdio (reply, react, edit_message, get_history, get_unread, mark_read, download_attachment, send_document, search_messages, get_context, health) with a built-in responsiveness policy. See docs/interfaces.md.
  • config probebun run ts/telegram-server.ts config [--check] prints the resolved config as JSON for orchestrator preflight.
  • health (doctor)bun run ts/telegram-server.ts health (also exposed as the health MCP tool) runs 10 checks — env hygiene, token presence/validity, webhook absence, poller liveness, allowlist, state dir, DB schema/offset — and prints {package, ok, checks[], summary}; every failing check carries an actionable hint. See docs/interfaces.md.
  • Skill — bundled at src/claude_code_telegrammer/_skills/claude-code-telegrammer/SKILL.md.

Part of SciTeX

claude-code-telegrammer is part of SciTeX — the Telegram communication layer and TUI watchdog used by scitex-agent-container (lifecycle, health, restart) and scitex-orochi (agent definitions, dashboard) for autonomous agent operation. See the agent stack.

References

Four Freedoms for Research

  1. The freedom to run your research anywhere -- your machine, your terms.
  2. The freedom to study how every step works -- from raw data to final manuscript.
  3. The freedom to redistribute your workflows, not just your papers.
  4. 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.


SciTeX

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

claude_code_telegrammer-0.5.7.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_code_telegrammer-0.5.7-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file claude_code_telegrammer-0.5.7.tar.gz.

File metadata

  • Download URL: claude_code_telegrammer-0.5.7.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for claude_code_telegrammer-0.5.7.tar.gz
Algorithm Hash digest
SHA256 55412574e0ca8376aed1837e9cba46585e3db6caa478e0cee4087f778cce059c
MD5 a478ce4e5331af326d10ced05534b54e
BLAKE2b-256 5e26611662b404685165026ca83411cfd6fe756658070257bee6245dde92f864

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_code_telegrammer-0.5.7.tar.gz:

Publisher: pypi-publish-and-github-release-on-tag.yml on scitex-ai/claude-code-telegrammer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file claude_code_telegrammer-0.5.7-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_code_telegrammer-0.5.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6ae29c04503bba0b7c5f52d75f5105e43040bf049f5ab1d1e740fdef01a7c400
MD5 df4ff756bfa7beccf65546f009b4c5f4
BLAKE2b-256 7b75bf200c09e6210effeb4f40ddde6da4adebb5328c9f947c00b759e156251f

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_code_telegrammer-0.5.7-py3-none-any.whl:

Publisher: pypi-publish-and-github-release-on-tag.yml on scitex-ai/claude-code-telegrammer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page