Skip to content

Control Claude Code AI assistant through Telegram. Full coding capabilities via chat.

Notifications You must be signed in to change notification settings

Angusstone7/claude-code-telegram

Repository files navigation

Claude Code Telegram

πŸ“± Claude Code Telegram

Control Claude Code AI directly from Telegram β€” code, review, and deploy from anywhere

Features β€’ Quick Start β€’ Deploy β€’ Architecture β€’ Configuration

Python Docker License DDD Tests


🎯 What is This?

Claude Code Telegram transforms your Telegram into a powerful AI coding assistant. It's a bridge between Claude Code (Anthropic's official CLI for Claude) and Telegram, allowing you to:

  • πŸ’» Write code using natural language from your phone
  • πŸ” Review and debug code on the go
  • πŸ“ Manage projects across multiple repositories
  • βœ… Approve AI actions with Human-in-the-Loop (HITL) controls
  • πŸš€ Deploy changes without touching your computer

Think of it as having Claude Code in your pocket, accessible anywhere via Telegram.


✨ Features

πŸ€– AI-Powered Coding

Feature Description
πŸ’¬ Natural Language Just describe what you want β€” Claude writes the code
πŸ”„ Streaming Responses See AI responses in real-time as they're generated
πŸ“ Context Awareness Maintains conversation history per project
🎯 Multi-Model Support Works with Claude Sonnet, Opus, and Haiku

πŸ›‘οΈ Human-in-the-Loop (HITL)

Feature Description
βœ… Tool Approval Approve or deny file changes, commands before execution
⚑ YOLO Mode Auto-approve all actions when you trust the AI
πŸ“‹ Plan Review Review implementation plans before Claude executes them
πŸ” Secure by Default Nothing happens without your explicit consent

πŸ“ Project Management

Feature Description
πŸ—‚οΈ Multi-Project Switch between different codebases seamlessly
πŸ” File Browser Navigate and select projects via Telegram UI
πŸ’Ύ Persistent Context Each project maintains its own conversation history
πŸ“€ File Uploads Send files directly to your project via Telegram

πŸ”Œ Extensibility

Feature Description
🧩 Official Plugins Supports Claude Code plugins (commit, review, etc.)
πŸ“‘ MCP Integration Telegram MCP server for Claude-initiated messages
🐳 Docker Management Control containers on your server
πŸ“Š System Monitoring CPU, memory, disk metrics at a glance

πŸš€ Quick Start

Prerequisites

  • 🐳 Docker & Docker Compose installed
  • πŸ€– Telegram bot token from @BotFather
  • πŸ”‘ Claude Code credentials (see below)
  • πŸ†” Your Telegram user ID (get it from @userinfobot)

πŸ” Claude Code Authentication

Claude Code supports two authentication methods:

Option A: Claude Account (Recommended)

Uses your claude.ai subscription. No API costs β€” uses your existing Claude Pro/Team plan.

  1. Install Claude Code CLI locally:

    npm install -g @anthropic-ai/claude-code
  2. Run and authenticate via browser:

    claude
    # Opens browser for OAuth login to claude.ai
  3. Copy the credentials file to your project:

    cp ~/.config/claude/config.json ./claude_config.json
  4. Mount it in docker-compose.yml:

    volumes:
      - ./claude_config.json:/root/.config/claude/config.json:ro

Option B: API Key

Uses Anthropic API directly. Pay-per-use pricing.

ANTHROPIC_API_KEY=sk-ant-api03-xxxxx

Get your API key from console.anthropic.com

Option C: ZhipuAI (China)

Claude-compatible API with no regional restrictions.

ANTHROPIC_BASE_URL=https://open.bigmodel.cn/api/anthropic
ANTHROPIC_AUTH_TOKEN=your_zhipuai_token

Get your token from open.bigmodel.cn


⚑ One-Command Deploy

Option 1: Interactive Deploy Script (Recommended)

# Download and run the interactive deploy script
git clone https://github.com/Angusstone7/claude-code-telegram.git && \
cd claude-code-telegram && \
chmod +x deploy.sh && \
./deploy.sh

The script will:

  • βœ… Check Docker installation
  • βœ… Prompt for your credentials interactively
  • βœ… Create the .env file automatically
  • βœ… Build and start the container
  • βœ… Show you next steps

Option 2: Quick Deploy (Manual Config)

# Clone, configure, and run β€” all in one command!
git clone https://github.com/Angusstone7/claude-code-telegram.git && \
cd claude-code-telegram && \
cp .env.example .env && \
echo "Now edit .env with your credentials, then run: docker-compose up -d --build"

Option 3: Full One-Liner (if you know your credentials)

git clone https://github.com/Angusstone7/claude-code-telegram.git && cd claude-code-telegram && \
cat > .env << 'EOF'
TELEGRAM_TOKEN=your_bot_token_here
ANTHROPIC_API_KEY=sk-ant-your-key-here
ALLOWED_USER_ID=your_telegram_id_here
EOF
docker-compose up -d --build

Just replace:

  • your_bot_token_here β†’ Your Telegram bot token
  • sk-ant-your-key-here β†’ Your Anthropic API key
  • your_telegram_id_here β†’ Your Telegram user ID

Option 4: Step-by-Step Deploy

πŸ“– Click to expand detailed instructions

1️⃣ Clone the Repository

git clone https://github.com/Angusstone7/claude-code-telegram.git
cd claude-code-telegram

2️⃣ Create Configuration

cp .env.example .env

3️⃣ Edit .env File

# Required settings
TELEGRAM_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
ANTHROPIC_API_KEY=sk-ant-api03-xxxxx
ALLOWED_USER_ID=123456789

# Optional: Multiple users (comma-separated)
# ALLOWED_USER_ID=123456789,987654321

# Optional: Use Claude Sonnet 4 (default) or other models
# ANTHROPIC_MODEL=claude-sonnet-4-20250514

4️⃣ Launch with Docker

docker-compose up -d --build

5️⃣ Check Logs

docker-compose logs -f claude-bot

6️⃣ Open Telegram

Find your bot and send /start πŸŽ‰


πŸ“± Usage

Basic Commands

Command Description
/start πŸ“± Open main menu
/yolo ⚑ Toggle auto-approve mode
/cancel πŸ›‘ Cancel current AI task

Main Menu

After /start, you'll see an inline keyboard with options:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ’¬ Chat with Claude Code       β”‚  ← Start coding session
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  πŸ“ Projects                    β”‚  ← Browse & switch projects
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  πŸ‘€ Account                     β”‚  ← Manage API credentials
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  βš™οΈ Settings                    β”‚  ← Configure bot behavior
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Workflow Example

You: Create a Python function that validates email addresses

Claude: I'll create an email validation function for you.

πŸ“„ Creating file: utils/validators.py
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ [βœ… Approve] [❌ Deny] [πŸ‘οΈ View]  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

You: [Clicks βœ… Approve]

Claude: βœ… Created utils/validators.py with email validation function.
        The function uses regex pattern matching and handles edge cases...

HITL (Human-in-the-Loop) Controls

When Claude wants to perform an action, you'll see approval buttons:

Button Action
βœ… Approve Allow Claude to proceed
❌ Deny Block the action
πŸ‘οΈ View See what Claude wants to do
⚑ YOLO Approve all future actions

πŸ—οΈ Architecture

This project follows Domain-Driven Design (DDD) with clean architecture:

claude-code-telegram/
β”œβ”€β”€ 🎯 domain/                    # Core business logic
β”‚   β”œβ”€β”€ entities/                 # User, Session, Project, Message
β”‚   β”œβ”€β”€ value_objects/            # UserId, Role, AIProviderConfig
β”‚   β”œβ”€β”€ repositories/             # Repository interfaces
β”‚   └── services/                 # Domain service contracts
β”‚
β”œβ”€β”€ πŸ“¦ application/               # Use cases & orchestration
β”‚   └── services/
β”‚       β”œβ”€β”€ bot_service.py        # Main orchestration
β”‚       β”œβ”€β”€ project_service.py    # Project management
β”‚       β”œβ”€β”€ context_service.py    # Conversation context
β”‚       └── account_service.py    # Auth mode switching
β”‚
β”œβ”€β”€ πŸ”§ infrastructure/            # External integrations
β”‚   β”œβ”€β”€ claude_code/
β”‚   β”‚   β”œβ”€β”€ sdk_service.py        # Claude SDK (preferred)
β”‚   β”‚   └── proxy_service.py      # CLI fallback
β”‚   β”œβ”€β”€ persistence/              # SQLite repositories
β”‚   └── messaging/                # AI service adapters
β”‚
β”œβ”€β”€ 🎨 presentation/              # Telegram interface
β”‚   β”œβ”€β”€ handlers/                 # Message, callback, command handlers
β”‚   β”œβ”€β”€ keyboards/                # Inline keyboard builders
β”‚   └── middleware/               # Auth middleware
β”‚
β”œβ”€β”€ πŸ”Œ telegram-mcp/              # MCP server (TypeScript)
β”‚   └── src/index.ts              # Telegram tools for Claude
β”‚
└── πŸ§ͺ tests/                     # Test suite (143+ tests)

Backend Modes

Mode Description When Used
SDK Direct Python integration via claude-agent-sdk Primary (preferred)
CLI Subprocess calls to claude CLI Fallback

βš™οΈ Configuration

Environment Variables

πŸ”§ Click to see all configuration options

Required

Variable Description
TELEGRAM_TOKEN Bot token from @BotFather
ANTHROPIC_API_KEY API key (Anthropic or ZhipuAI)
ALLOWED_USER_ID Telegram user ID(s), comma-separated

AI Provider

Variable Default Description
ANTHROPIC_MODEL claude-sonnet-4-20250514 Default model
ANTHROPIC_BASE_URL β€” Custom API endpoint

Claude Code

Variable Default Description
CLAUDE_WORKING_DIR /root/projects Default working directory
CLAUDE_MAX_TURNS 50 Max conversation turns
CLAUDE_TIMEOUT 600 Command timeout (seconds)
CLAUDE_PERMISSION_MODE default default, auto, or never

Optional Features

Variable Default Description
SSH_HOST host.docker.internal Host for SSH commands
SSH_PORT 22 SSH port
LOG_LEVEL INFO Logging verbosity
DEBUG false Enable debug mode

🐳 Docker Details

Volumes

Host Path Container Path Purpose
./data /app/data SQLite database
./logs /app/logs Application logs
./projects /root/projects Your code projects
./claude_sessions /root/.claude Claude Code sessions
./claude_config.json /root/.config/claude/config.json Claude Account credentials (optional)

Useful Commands

# Start the bot
docker-compose up -d --build

# View logs
docker-compose logs -f claude-bot

# Restart
docker-compose restart

# Stop
docker-compose down

# Update to latest version
git pull && docker-compose up -d --build

πŸ”Œ MCP Integration

The bot includes a Telegram MCP server that allows Claude to proactively send messages:

Tool Description
send_message Send text notifications to Telegram
send_file Send files with optional captions
send_plan Create and send plan documents

To rebuild after changes:

cd telegram-mcp && npm install && npm run build

πŸ§ͺ Development

Local Setup

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or: venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

# Run locally
python main.py

Running Tests

# All tests
pytest tests/

# With coverage
pytest tests/ --cov=. --cov-report=html

# Specific test file
pytest tests/unit/domain/test_ai_provider_config.py -v

Code Quality

# Format code
black application/ domain/ infrastructure/ presentation/ shared/

# Type checking
mypy application/ domain/ infrastructure/ presentation/ shared/

πŸ“Š Project Stats

Metric Value
πŸ“ Python LOC ~28,100
πŸ“„ Python Files 112
πŸ§ͺ Unit Tests 143+
πŸŽ›οΈ Handlers LOC ~9,000
πŸ”Œ MCP Server LOC ~10,000

πŸ›‘οΈ Security

User Authorization (Whitelist)

Access to the bot is controlled via ALLOWED_USER_ID environment variable:

# Single user (this user becomes admin)
ALLOWED_USER_ID=123456789

# Multiple users (first user is admin, others are regular users)
ALLOWED_USER_ID=123456789,987654321,555555555
Feature Description
πŸ” Whitelist Only users in ALLOWED_USER_ID can access the bot
πŸ‘‘ Auto Admin First user in the list automatically gets admin role
🚫 Access Denied Unauthorized users see their Telegram ID (for requesting access)
⚠️ Open Mode If ALLOWED_USER_ID is empty, bot is open to everyone (warning logged)

Other Security Features

  • βœ… HITL Controls β€” Every AI action requires explicit approval
  • βœ… No Credentials in Code β€” All secrets via environment variables
  • βœ… SSH Key Auth β€” Secure server access (optional feature)
  • βœ… Role-Based Access β€” Admin, DevOps, User, ReadOnly roles

πŸ› Troubleshooting

Bot doesn't respond
  1. Check logs: docker-compose logs -f claude-bot
  2. Verify TELEGRAM_TOKEN is correct
  3. Ensure your user ID is in ALLOWED_USER_ID
Claude Code not working
  1. Check if API key is valid
  2. Verify ANTHROPIC_API_KEY is set
  3. Look for SDK/CLI status in startup logs
Permission denied errors
chmod -R 755 ./data ./logs ./projects

🀝 Contributing

Contributions are welcome! Please:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’Ύ Commit your changes (git commit -m 'Add amazing feature')
  4. πŸ“€ Push to the branch (git push origin feature/amazing-feature)
  5. πŸ”ƒ Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


πŸ™ Acknowledgments

Built with these amazing tools:


Made with ❀️ for developers who code on the go

Report Bug β€’ Request Feature

About

Control Claude Code AI assistant through Telegram. Full coding capabilities via chat.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages