Skip to main content

Claude Code <-> Telegram bridge

Project description

claude-tg

Claude Code CLI <-> Telegram bridge. Chat with Claude Code from your phone — full agentic experience through Telegram with token-level streaming.

Install

pip install claude-tg

Quick Start

export TELEGRAM_BOT_TOKEN="your_bot_token"   # from @BotFather
export TELEGRAM_CHAT_ID="your_chat_id"       # your Telegram user ID
export CLAUDE_WORK_DIR="/path/to/project"    # optional, defaults to cwd

claude-tg

On first run, the built-in MCP server for file sending is auto-registered in Claude Code.

Commands

Command Description
/clear Reset session (new context)
/compact Compact conversation context
/cancel Stop current task
/cost Show session cost
/model <name> Switch model (no args = show current)
/restart Full process restart (picks up CLI/config changes)

Inline Cancel button is shown on every message during processing.

Media

  • Photos — sent to Claude as file references, Claude can read/analyze them
  • Documents — same for files (PDF, code, etc.)

Voice Messages

Voice messages are transcribed via Groq Whisper API and sent to Claude as text.

export GROQ_API_KEY="your_groq_api_key"  # free at console.groq.com

Without GROQ_API_KEY, the bot replies with a setup hint when a voice message is received.

Triggers (External Prompts)

Enable a localhost HTTP server so cron jobs, scripts, or other processes can inject prompts into your chat:

export CLAUDE_TG_TRIGGER_PORT=9357   # any free port

Then trigger from anywhere:

# Run a prompt through Claude (normal mode)
curl -s -d "Run the /morning skill" localhost:9357

# Send a message directly to Telegram without running Claude (DIRECT mode)
curl -s -d "DIRECT:Deploy complete, all tests pass ✅" localhost:9357

Normal mode — the prompt is processed by Claude and the response appears as a chat message. You can reply and continue the conversation.

DIRECT mode — prefix the body with DIRECT: to send text straight to Telegram, bypassing Claude entirely. Useful for cron notifications, monitoring alerts, or scripts that already have their output ready.

  • If Claude is busy, normal-mode prompts queue and process after the current task
  • Localhost only — not exposed to the network

File Sending (MCP)

Claude can send files back to you via the built-in MCP server:

  • send_telegram_file(file_path, caption?, temp_file?) — sends a file to your Telegram
  • temp_file=True (default) — file is deleted after sending (for generated/temporary files)
  • temp_file=False — file is preserved (for existing project files)

The MCP server (claude-tg-mcp) is auto-registered on launch. No manual setup needed.

Running as Root (VPS / Servers)

Claude Code CLI blocks --dangerously-skip-permissions for root. claude-tg handles this automatically:

  • Non-root — uses --dangerously-skip-permissions as usual
  • Root — uses --allowedTools with dynamically discovered MCP servers (reads ~/.claude.json and .mcp.json)

All registered MCP servers and built-in tools are allowed automatically. No hardcoded server names.

Configuration

Env var Default Description
TELEGRAM_BOT_TOKEN required Bot token from @BotFather
TELEGRAM_CHAT_ID required Your Telegram user ID
CLAUDE_WORK_DIR cwd Working directory for Claude
CLAUDE_TG_VERBOSE 0 Show tool results (1 to enable)
CLAUDE_TG_MODEL Override Claude model
CLAUDE_TG_MAX_BUDGET Max budget in USD
CLAUDE_TG_SESSION_TIMEOUT 3600 Auto-reset after N seconds of inactivity
CLAUDE_TG_UPDATE_INTERVAL 2.0 Telegram message update interval (seconds)
GROQ_API_KEY Groq API key for voice transcription
CLAUDE_TG_TRIGGER_PORT Localhost port for external triggers (e.g. 9357)

Systemd (VPS deployment)

# Install
uv tool install claude-tg

# Create service
cat > /etc/systemd/system/claude-tg.service << 'EOF'
[Unit]
Description=Claude TG
After=network-online.target

[Service]
Type=simple
EnvironmentFile=/path/to/.env
Environment=PATH=/root/.local/bin:/usr/local/bin:/usr/bin
ExecStart=/root/.local/bin/claude-tg --work-dir /root
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

systemctl enable --now claude-tg

Features

  • Token-level streaming with adaptive rate limiting
  • Automatic message chaining for long outputs (splits at ~3800 chars)
  • Photo, file, and voice message support
  • Built-in MCP server for sending files back to the user
  • Inline cancel button on every message
  • Message queuing — send messages while Claude is working, they process after
  • Session auto-reset after inactivity
  • Compact tool call display with emoji icons
  • Root-compatible — auto-discovers and allows all MCP tools
  • Auto-registration of MCP server in Claude Code
  • In-place restart via /restart (no need to touch the server)
  • External triggers — cron/scripts can inject prompts via localhost HTTP
  • Direct message mode — send to Telegram without Claude processing (DIRECT: prefix)

Requirements

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_tg-0.5.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

claude_tg-0.5.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file claude_tg-0.5.1.tar.gz.

File metadata

  • Download URL: claude_tg-0.5.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for claude_tg-0.5.1.tar.gz
Algorithm Hash digest
SHA256 eb983d68fd27b154e8add21dec9ed13ff34ad943e0d8cc2d371dd514e082a970
MD5 03eba2f7ca354fa5267326bc71fe462d
BLAKE2b-256 cfb1a792ee107fa0ec633d5fd5916efea656f9ea30e7fb9d52766556c9c4f177

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_tg-0.5.1.tar.gz:

Publisher: publish.yml on MerkulovDaniil/claude-tg

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_tg-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: claude_tg-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for claude_tg-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2649c2698230d2796bb4f34981113f19253a72c4a22fa0f18491a345f9e68c1d
MD5 5fbd603d51e89a69efd0716b1adbffad
BLAKE2b-256 9a58db44901756677d061563050069377013e250002e39fc1d61f86fb04e48ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_tg-0.5.1-py3-none-any.whl:

Publisher: publish.yml on MerkulovDaniil/claude-tg

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