This document provides comprehensive information about configuring the Claude Code Telegram Bot.
The bot uses a configuration system built with Pydantic Settings v2 that provides:
- Type Safety: All configuration values are validated and type-checked
- Environment Support: Automatic environment-specific overrides
- Feature Flags: Dynamic enabling/disabling of functionality
- Validation: Cross-field validation and runtime checks
Configuration is loaded in this order (later sources override earlier ones):
- Default values defined in the Settings class
- Environment variables
.envfile (if present)- Environment-specific overrides (development/testing/production)
# Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=1234567890:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
TELEGRAM_BOT_USERNAME=your_bot_name
# Security
APPROVED_DIRECTORY=/path/to/your/projects# Comma-separated list of allowed Telegram user IDs
ALLOWED_USERS=123456789,987654321
# Enable token-based authentication (requires AUTH_TOKEN_SECRET)
ENABLE_TOKEN_AUTH=false
AUTH_TOKEN_SECRET=your-secret-key-here# Disable dangerous pattern validation in SecurityValidator (default: false)
# WARNING: This allows characters such as pipes and redirections in validated paths.
DISABLE_SECURITY_PATTERNS=false
# Disable ToolMonitor allowlist/disallowlist checks (default: false)
# WARNING: This only skips tool-name allow/disallow checks; path and Bash safety checks still apply.
DISABLE_TOOL_VALIDATION=false# Authentication
ANTHROPIC_API_KEY=sk-ant-api03-... # Optional: API key for SDK (uses CLI auth if omitted)
# Maximum conversation turns before requiring new session
CLAUDE_MAX_TURNS=10
# Timeout for Claude operations in seconds
CLAUDE_TIMEOUT_SECONDS=300
# Maximum cost per user in USD (lifetime budget for rate limiter)
CLAUDE_MAX_COST_PER_USER=10.0
# Maximum cost per individual request in USD (SDK-level hard cap)
CLAUDE_MAX_COST_PER_REQUEST=5.0
# Allowed Claude tools (comma-separated list; see docs/tools.md for descriptions)
CLAUDE_ALLOWED_TOOLS=Read,Write,Edit,Bash,Glob,Grep,LS,Task,TaskOutput,MultiEdit,NotebookRead,NotebookEdit,WebFetch,TodoRead,TodoWrite,WebSearch# Number of requests allowed per window
RATE_LIMIT_REQUESTS=10
# Rate limit window in seconds
RATE_LIMIT_WINDOW=60
# Burst capacity for rate limiting
RATE_LIMIT_BURST=20# Database URL (SQLite by default)
DATABASE_URL=sqlite:///data/bot.db
# Session management
SESSION_TIMEOUT_HOURS=24 # Session timeout in hours
MAX_SESSIONS_PER_USER=5 # Max concurrent sessions per user
# Data retention
DATA_RETENTION_DAYS=90 # Days to keep old data
AUDIT_LOG_RETENTION_DAYS=365 # Days to keep audit logs# Agentic mode (default: true)
# true = conversational mode with 3 commands (/start, /new, /status)
# false = classic terminal mode with 13 commands and inline keyboards
AGENTIC_MODE=true# Enable Model Context Protocol
ENABLE_MCP=false
MCP_CONFIG_PATH=/path/to/mcp/config.json
# Enable Git integration (classic mode)
ENABLE_GIT_INTEGRATION=true
# Enable file upload handling
ENABLE_FILE_UPLOADS=true
# Enable quick action buttons (classic mode)
ENABLE_QUICK_ACTIONS=true
# Enable voice message transcription
ENABLE_VOICE_MESSAGES=true
VOICE_PROVIDER=mistral # 'mistral' (default) or 'openai'
MISTRAL_API_KEY= # Required when VOICE_PROVIDER=mistral
OPENAI_API_KEY= # Required when VOICE_PROVIDER=openai
VOICE_TRANSCRIPTION_MODEL= # Default: voxtral-mini-latest (Mistral) or whisper-1 (OpenAI)
VOICE_MAX_FILE_SIZE_MB=20 # Max Telegram voice file size to download (1-200MB)# Webhook API Server
ENABLE_API_SERVER=false # Enable FastAPI webhook server
API_SERVER_PORT=8080 # Server port (default: 8080)
# Webhook Authentication
GITHUB_WEBHOOK_SECRET=your-secret # GitHub HMAC-SHA256 secret
WEBHOOK_API_SECRET=your-secret # Bearer token for generic providers
# Job Scheduler
ENABLE_SCHEDULER=false # Enable cron job scheduler
# Notifications
NOTIFICATION_CHAT_IDS=123456,789012 # Default Telegram chat IDs for proactive notifications# Strict project routing via Telegram project topics
ENABLE_PROJECT_THREADS=false
# Mode: private (default) or group
PROJECT_THREADS_MODE=private
# YAML registry file with project slugs/names/paths
PROJECTS_CONFIG_PATH=config/projects.yaml
# Required only for PROJECT_THREADS_MODE=group
PROJECT_THREADS_CHAT_ID=-1001234567890
# Minimum delay (seconds) between Telegram API calls during topic sync
# Set 0 to disable pacing
PROJECT_THREADS_SYNC_ACTION_INTERVAL_SECONDS=1.1PROJECTS_CONFIG_PATH schema:
projects:
- slug: my-app
name: My App
path: my-app
enabled: trueWhen ENABLE_PROJECT_THREADS=true:
PROJECT_THREADS_MODE=private:/startand/sync_threadsare allowed outside topics in private chat.- all other updates must be inside mapped project topics.
PROJECT_THREADS_MODE=group:- behavior remains forum-topic based using
PROJECT_THREADS_CHAT_ID.
- behavior remains forum-topic based using
# Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
LOG_LEVEL=INFO
# Enable anonymous telemetry
ENABLE_TELEMETRY=false
# Sentry DSN for error tracking
SENTRY_DSN=https://your-sentry-dsn@sentry.io/project# Enable debug mode
DEBUG=false
# Enable development features
DEVELOPMENT_MODE=false
# Environment override (development, testing, production)
ENVIRONMENT=development# Webhook URL for bot (leave empty for polling mode)
WEBHOOK_URL=https://your-domain.com/webhook
# Webhook port
WEBHOOK_PORT=8443
# Webhook path
WEBHOOK_PATH=/webhookThe bot automatically applies different settings based on the environment:
Activated when ENVIRONMENT=development or when DEBUG=true:
debug = truedevelopment_mode = truelog_level = "DEBUG"rate_limit_requests = 100(more lenient)claude_timeout_seconds = 600(longer timeout)enable_telemetry = false
Activated when ENVIRONMENT=testing:
debug = truedatabase_url = "sqlite:///:memory:"(in-memory database)approved_directory = "/tmp/test_projects"claude_timeout_seconds = 30(faster timeout)rate_limit_requests = 1000(no effective rate limiting)
Activated when ENVIRONMENT=production:
debug = falselog_level = "INFO"enable_telemetry = trueclaude_max_cost_per_user = 5.0(stricter cost limit)claude_max_cost_per_request = 2.0(per-request SDK cap)rate_limit_requests = 5(stricter rate limiting)session_timeout_hours = 12(shorter session timeout)
Feature flags allow you to enable or disable functionality dynamically:
from src.config import load_config, FeatureFlags
config = load_config()
features = FeatureFlags(config)
if features.agentic_mode_enabled:
# Use agentic mode handlers
pass
if features.api_server_enabled:
# Start webhook API server
passAvailable feature flags:
agentic_mode_enabled: Agentic conversational mode (default: true)api_server_enabled: Webhook API serverscheduler_enabled: Cron job schedulermcp_enabled: Model Context Protocol supportgit_enabled: Git integration commandsfile_uploads_enabled: File upload handlingquick_actions_enabled: Quick action buttonstelemetry_enabled: Anonymous usage telemetrytoken_auth_enabled: Token-based authenticationwebhook_enabled: Telegram webhook mode (vs polling)voice_messages_enabled: Voice message transcription (default: true)development_features_enabled: Development-only features
The configuration system performs extensive validation:
APPROVED_DIRECTORYmust exist and be accessibleMCP_CONFIG_PATHmust exist if MCP is enabled
AUTH_TOKEN_SECRETis required whenENABLE_TOKEN_AUTH=trueMCP_CONFIG_PATHis required whenENABLE_MCP=trueMISTRAL_API_KEYis required whenVOICE_PROVIDER=mistralOPENAI_API_KEYis required whenVOICE_PROVIDER=openai
LOG_LEVELmust be one of: DEBUG, INFO, WARNING, ERROR, CRITICAL- Numeric values must be positive where appropriate
- User IDs in
ALLOWED_USERSmust be valid integers
# No ANTHROPIC_API_KEY needed - SDK will use CLI credentials
# Ensure Claude CLI is installed and authenticated: claude auth loginANTHROPIC_API_KEY=sk-ant-api03-your-key-here-
"Approved directory does not exist"
- Ensure the path in
APPROVED_DIRECTORYexists - Use absolute paths, not relative paths
- Check file permissions
- Ensure the path in
-
"auth_token_secret required"
- Set
AUTH_TOKEN_SECRETwhen usingENABLE_TOKEN_AUTH=true - Generate a secure secret:
openssl rand -hex 32
- Set
-
"MCP config file does not exist"
- Ensure
MCP_CONFIG_PATHpoints to an existing file - Or disable MCP with
ENABLE_MCP=false
- Ensure
- Never commit secrets to version control
- Use environment variables for sensitive data
- Rotate tokens regularly if using token-based auth
- Restrict
APPROVED_DIRECTORYto only necessary paths - Monitor logs for configuration errors and security events