A lightweight, secure Node.js service that acts as a bridge between a specific Telegram chat and the Anthropic Claude CLI tool. This allows you to securely send prompts to Claude from anywhere via Telegram, using your machine's local claude-code CLI.
- Secure by Default: Only accepts messages from a specific authorized Telegram Chat ID or Group ID. It actively logs and ignores commands from unauthorized IDs.
- Background Execution: Transparently bridges your Telegram texts to Claude's CLI, passing inputs and capturing responses.
- Robust Daily Logging: Uses
winstonandwinston-daily-rotate-fileto keep highly organized daily log files (14-day history). Logs contain all communication, including access attempts from unauthorized users. - No Hangs: Perfectly structured non-interactive
child_process.execcalls that won't randomly hang expecting TTY input (using--dangerously-skip-permissions&< /dev/null).
- Node.js
- Claude Code CLI globally installed (
npm install -g @anthropic-ai/claude-code) AND authenticated on your local machine. - A Telegram Bot Token.
- Open Telegram and search for @BotFather.
- Send
/newbotand follow the prompts to create your bot and set a name and username. - Once created, BotFather will give you an HTTP API token (e.g.,
123456789:ABCdefGHIjkl...). Save this securely.
- Your Telegram Chat ID and/or Telegram Group ID. (You can message a bot like
@userinfobotto retrieve your numeric ID, or add a bot to a group to get the group ID).
- Clone this project:
git clone https://github.com/lojik-ng/claude-telegram.git cd claude-telegram - Install the necessary project dependencies:
npm install
- Copy the example environment file:
cp .env.example .env
- Open the
.envfile and insert your configuration:TELEGRAM_BOT_TOKEN="your_bot_token_here"TELEGRAM_CHAT_ID="your_personal_chat_id_here"TELEGRAM_GROUP_ID="your_group_chat_id_here"DEFAULT_DIRECTORY="/path/to/the/folder/where/claude/should/start"
Simply start the bridge application:
npm startThen, send a message to your newly made Telegram bot!
- You will receive a real-time acknowledgment:
processing... - The bot triggers a command in the background running the Claude CLI in your specified directory.
- The entire output from Claude is captured and formatted directly back to you in your Telegram chat.
Check the automatically generated ./logs directory for rotated activity logs. New files are generated per day and old logs are completely rotated out after 14 days.
You can use the provided start.sh script to ensure the application automatically starts and stays running in the background. The script checks if the process is already active, and starts it if it isn't.
-
Make the start script executable:
chmod +x start.sh
-
Open your crontab editor:
crontab -e
-
Add the following line to run the check every minute (ensure the path matches where you cloned the repository):
* * * * * /home/lojik/Documents/GitHub/claude-telegram/start.sh >> /home/lojik/Documents/GitHub/claude-telegram/cron.log 2>&1