Skip to content
 
 

Repository files navigation

CCGram — Command & Control Bot

CI PyPI Downloads Python Typed License Ruff

Control AI coding agents from your phone. CCGram bridges Telegram to tmux — monitor output, respond to prompts, and manage sessions without touching your computer. Supports Claude Code, Codex CLI, Gemini CLI, and plain shell sessions with LLM command generation.

Why CCGram?

AI coding agents run in your terminal. When you step away — commuting, on the couch, or just away from your desk — the session keeps working, but you lose visibility and control.

CCGram fixes this. The key insight: it operates on tmux, not any agent's SDK. Your agent process stays exactly where it is, in a tmux window on your machine. CCGram reads its output and sends keystrokes to it. This means:

  • Desktop to phone, mid-conversation — your agent is working on a refactor? Walk away and keep monitoring from Telegram
  • Phone back to desktop, anytimetmux attach and you're back in the terminal with full scrollback
  • Multiple sessions in parallel — Each Telegram topic maps to a separate tmux window, each can run a different agent

Other Telegram bots wrap agent SDKs to create isolated API sessions that can't be resumed in your terminal. CCGram is different — it's a thin control layer over tmux, so the terminal remains the source of truth.

How It Works

graph LR
  subgraph phone["📱 Telegram Group"]
    T1["💬 Topic: api"]
    T2["💬 Topic: ui"]
    T3["💬 Topic: docs"]
    T4["💬 Topic: server"]
  end

  subgraph machine["🖥️ Your Machine — tmux"]
    W1["🟠 window @0<br>claude ↻ running"]
    W2["🧩 window @1<br>codex ↻ running"]
    W3["♊ window @2<br>gemini ↻ running"]
    W4["🐚 window @3<br>shell ↻ ready"]
  end

  T1 -- "text →" --> W1
  W1 -. "← responses" .-> T1
  T2 -- "text →" --> W2
  W2 -. "← responses" .-> T2
  T3 -- "text →" --> W3
  W3 -. "← responses" .-> T3
  T4 -- "text / voice →" --> W4
  W4 -. "← output" .-> T4

  style phone fill:#e8f4fd,stroke:#0088cc,stroke-width:2px,color:#333
  style machine fill:#f0faf0,stroke:#2ea44f,stroke-width:2px,color:#333
  style T1 fill:#fff,stroke:#0088cc,stroke-width:1px,color:#333
  style T2 fill:#fff,stroke:#0088cc,stroke-width:1px,color:#333
  style T3 fill:#fff,stroke:#0088cc,stroke-width:1px,color:#333
  style T4 fill:#fff,stroke:#0088cc,stroke-width:1px,color:#333
  style W1 fill:#fff,stroke:#2ea44f,stroke-width:1px,color:#333
  style W2 fill:#fff,stroke:#2ea44f,stroke-width:1px,color:#333
  style W3 fill:#fff,stroke:#2ea44f,stroke-width:1px,color:#333
  style W4 fill:#fff,stroke:#2ea44f,stroke-width:1px,color:#333
Loading

Each Telegram Forum topic binds to one tmux window running an agent CLI. Messages you type in the topic are sent as keystrokes to the tmux pane; the agent's output is parsed from session transcripts and delivered back as Telegram messages.

Features

Session control

  • Send messages directly to your agent topic
  • /commands shows commands supported by that topic's provider (Claude/Codex/Gemini/Shell)
  • Forwarded slash commands report provider mismatch errors (for example Claude-only /cost in Codex)
  • Command menu auto-switches per user/chat to the active topic provider after interaction
  • Interactive prompts (AskUserQuestion, ExitPlanMode, Permission) rendered as inline keyboards
  • Codex edit approvals are reformatted for Telegram readability (compact summary + short preview, with approval choices preserved)
  • Codex /status replies include a bot-side transcript snapshot (session + token/rate-limit stats) when Codex does not emit a normal transcript message
  • Multi-pane support — auto-detects blocked panes, surfaces prompts, /panes command for overview
  • Terminal screenshots — capture the current pane (or any specific pane) as a PNG image
  • Voice message transcription via Whisper API (OpenAI, Groq) with confirm/discard keyboard
  • Sessions dashboard (/sessions) — overview of all sessions with status and kill buttons
  • Remote Control detection — 📡 topic badge when RC is active, one-tap activation from status keyboard
  • Action toolbar (/toolbar) — persistent inline buttons for RC, Screenshot, Esc, Notify, Ctrl-C

Real-time monitoring

  • Assistant responses, thinking content, tool use/result pairs, and command output
  • Live status line showing what the agent is currently doing
  • Entity-based formatting with automatic plain text fallback

Session management

  • Directory browser for creating new sessions from Telegram
  • Auto-sync: create a tmux window manually and the bot auto-creates a matching topic
  • Fresh/Continue/Resume recovery when a session dies
  • Message history with paginated browsing (/history)
  • Persistent state — bindings and read offsets survive restarts

Multi-provider support

  • Claude Code (default), OpenAI Codex CLI, Google Gemini CLI, and Shell
  • Per-topic provider selection — different topics can use different agents simultaneously
  • Auto-detects provider from externally created tmux windows (process name, with ps-based TTY detection fallback for JS-runtime-wrapped CLIs like bun/node)
  • Provider-aware recovery (Continue/Resume buttons adapt to each provider's capabilities)
  • Emdash integration — auto-discovers emdash tmux sessions; bind Telegram topics to emdash-managed agents with zero configuration

Shell provider

  • Chat-first: type natural language → LLM generates a shell command → approve with one tap → output streams back
  • Raw mode: prefix with ! to bypass the LLM and send commands directly
  • Voice-to-command: voice messages transcribed via Whisper, then routed through the LLM for command generation
  • Dangerous command detection with extra confirmation step
  • BYOK LLM — supports OpenAI, Anthropic, xAI, DeepSeek, Groq, Ollama (zero new dependencies)
  • See docs/providers.md for LLM configuration

Extensibility

  • Global Telegram menu includes bot commands + default provider commands (with prefix); provider-scoped menus auto-refresh per chat/user/topic context with Telegram-scope fallbacks
  • Tmux session auto-detection — when running inside tmux, auto-discovers the session and picks up existing agent windows; duplicate instance prevention
  • Multi-instance support — run separate bots per Telegram group on the same machine
  • Configurable via environment variables

Quick Start

Prerequisites

  • Python 3.14+
  • tmux — installed and in PATH
  • At least one agent CLIclaude (default), codex, or gemini installed and authenticated (or use the plain shell provider with no extra install required)

Install

# Recommended
uv tool install ccgram

# Alternatives
pipx install ccgram                   # pipx
brew install alexei-led/tap/ccgram    # Homebrew (macOS)

Configure

  1. Create a Telegram bot via @BotFather
  2. Configure bot settings in BotFather:
    • Allow Groups: Enabled (Bot Settings > Groups & Channels > Allow Groups? > Turn on)
    • Group Privacy: Disabled (Bot Settings > Groups & Channels > Group Privacy > Turn off) — Required to see all messages in topics
    • Topics: Enabled (Bot Settings > Groups & Channels > Edit Topics > Enable)
  3. Add the bot to a Telegram group with Topics enabled.
  4. Promote the bot to Administrator and ensure it has these permissions:
    • Create Topics (required for the bot to automatically sync and manage session topics)
    • Pin Messages (required for the General-topic usage hint)
    • Note: the bot also uses message reactions in the General topic — this requires no extra permission.
  5. Create ~/.ccgram/.env:
TELEGRAM_BOT_TOKEN=your_bot_token_here
ALLOWED_USERS=your_telegram_user_id
CCGRAM_GROUP_ID=your_telegram_group_id

Get your user ID from @userinfobot on Telegram. Get the group ID by adding -100 in front of the Peer ID found in the Group Info (or use @RawDataBot).

Install hooks (Claude Code only)

ccgram hook --install

This registers Claude Code hooks (SessionStart, Notification, Stop, StopFailure, SessionEnd, SubagentStart, SubagentStop, TeammateIdle, TaskCompleted) for automatic session tracking, instant interactive UI detection, API error alerting, session lifecycle cleanup, and agent team notifications. Not needed for Codex or Gemini — those providers are discovered from hookless transcripts and tmux window/provider detection.

If hooks are missing, ccgram warns at startup with the fix command. Hooks are optional — terminal scraping works as fallback.

Configure LLM for Shell Provider (optional)

To enable natural language → shell command generation in shell topics, add an LLM provider:

CCGRAM_LLM_PROVIDER=openai   # or: anthropic, xai, deepseek, groq, ollama

See docs/providers.md for all options. Without an LLM, shell topics forward text as raw commands.

Run

ccgram

Open your Telegram group, create a new topic, send a message — a directory browser appears. Pick a project directory, choose your agent (Claude, Codex, Gemini, or Shell), then choose session mode (✅ Standard or 🚀 YOLO), and you're connected.

Migrating from ccbot

CCGram was previously named ccbot. If upgrading from v1.x:

# Install new package
pip install ccgram   # or: brew install alexei-led/tap/ccgram

# Migrate config directory
mv ~/.ccbot ~/.ccgram

# Update environment variables: CCBOT_* → CCGRAM_*
# Old CCBOT_* vars still work as fallback with deprecation warnings

# Re-install hooks (replaces legacy "ccbot hook" entries)
ccgram hook --install

Documentation

  • docs/guides.md — CLI reference, configuration, upgrading, multi-instance setup, session recovery, testing
  • docs/providers.md — Provider details (Claude, Codex, Gemini, Shell), session modes, LLM configuration, custom launch commands

Development

git clone https://github.com/alexei-led/ccgram.git
cd ccgram
uv sync --extra dev

make check        # fmt + lint + typecheck + unit + integration tests
make test-e2e     # E2E tests (requires agent CLIs, see docs/guides.md)

Acknowledgments

CCGram started as a fork of ccbot by six-ddc, who created the original Telegram-to-Claude-Code bridge. This project has since been rewritten and developed independently with multi-provider support, topic-based architecture, interactive UI, and a comprehensive test suite. Thanks to six-ddc for the initial idea and implementation.

License

MIT

ccgramctl — Control Panel

ccgramctl is a companion CLI that wraps CCGram's daemon lifecycle, tmux session management, and first-time setup into simple, memorable commands.

Install ccgramctl

curl -fsSL https://raw.githubusercontent.com/afialho/ccgram/main/scripts/install-ctl.sh | bash

Or manually:

mkdir -p ~/.local/bin
curl -fsSL https://raw.githubusercontent.com/afialho/ccgram/main/scripts/ccgramctl -o ~/.local/bin/ccgramctl
chmod +x ~/.local/bin/ccgramctl

First-Time Setup

ccgramctl setup

The interactive wizard walks you through everything step by step:

  1. Prerequisites — checks for Python, tmux, and Claude Code
  2. Install CCGram — installs from the fork via uv, pipx, or pip
  3. Create Telegram Bot — step-by-step BotFather instructions
  4. Get User ID — how to find your Telegram user ID via @userinfobot
  5. Create Group — how to set up a Topics-enabled group and get the group ID
  6. Voice Transcription — optional Whisper setup via Groq (free tier available)
  7. Project Directory — set the default directory for the Telegram file browser

All credentials are saved to ~/.ccgram/.env with 600 permissions.

Day-to-Day Commands

ccgramctl up          # Start the daemon
ccgramctl down        # Stop the daemon
ccgramctl restart     # Restart (applies config changes)
ccgramctl status      # Show status and active sessions
ccgramctl logs        # Attach to daemon tmux (Ctrl+B, D to detach)

Session Management

ccgramctl sessions    # List active tmux windows
ccgramctl kill <n>    # Kill a specific window by number

Tip: use /sessions in Telegram for interactive management with kill buttons.

Configuration

ccgramctl env                     # Open ~/.ccgram/.env in your editor
ccgramctl root ~/workspace/labs   # Change default project directory
ccgramctl doctor                  # Run CCGram diagnostics
ccgramctl upgrade                 # Upgrade CCGram from fork

Changing the Root Directory

The root directory controls where the Telegram directory browser starts when you create a new session.

ccgramctl root                        # See current root
ccgramctl root ~/workspace/labs       # Change it
ccgramctl restart                     # Apply

How ccgramctl Works

ccgramctl is a thin wrapper around tmux and the ccgram binary — no background services, no launch agents. up starts a detached tmux session, sources ~/.ccgram/.env, changes to the root directory, and runs ccgram. root saves the path to ~/.ccgram/.root, which up reads at launch.

ccgramctl File Locations

File Purpose
~/.local/bin/ccgramctl The CLI script
~/.ccgram/.env Tokens and configuration
~/.ccgram/.root Default project directory

Compatibility

macOS, Linux, and Windows (WSL). Requires bash 4+, tmux, and Python 3.10+.

About

Telegram ↔ tmux bridge for Claude Code, Codex CLI, and Gemini CLI. Monitor output, respond to prompts, manage parallel sessions. Control AI coding agents from your phone.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages