This guide shows how to run the Claude Code Telegram Bot as a persistent systemd user service.
.env file has DEVELOPMENT_MODE=false and ENVIRONMENT=production for secure operation.
mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/claude-telegram-bot.serviceAdd this content:
[Unit]
Description=Claude Code Telegram Bot
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/ubuntu/Code/oss/claude-code-telegram
ExecStart=/home/ubuntu/.local/bin/poetry run claude-telegram-bot
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
# Environment
Environment="PATH=/home/ubuntu/.local/bin:/usr/local/bin:/usr/bin:/bin"
[Install]
WantedBy=default.targetNote: Update WorkingDirectory to your project path.
# Reload systemd to recognize the new service
systemctl --user daemon-reload
# Enable auto-start on login
systemctl --user enable claude-telegram-bot.service
# Start the service now
systemctl --user start claude-telegram-bot.servicesystemctl --user status claude-telegram-botCheck that the service is running in production mode:
# Check logs for environment mode
journalctl --user -u claude-telegram-bot -n 50 | grep -i "environment\|development"
# Should show:
# "environment": "production"
# "development_mode": false (implied, not shown if false)
# Verify authentication is restricted
journalctl --user -u claude-telegram-bot -n 50 | grep -i "auth"
# Should show:
# "allowed_users": 1 (or more if multiple users configured)
# "allow_all_dev": falseIf you see allow_all_dev: true or environment: development, STOP THE SERVICE and fix your .env file immediately.
# Start service
systemctl --user start claude-telegram-bot
# Stop service
systemctl --user stop claude-telegram-bot
# Restart service
systemctl --user restart claude-telegram-bot
# View status
systemctl --user status claude-telegram-bot
# View live logs
journalctl --user -u claude-telegram-bot -f
# View recent logs (last 50 lines)
journalctl --user -u claude-telegram-bot -n 50
# Disable auto-start
systemctl --user disable claude-telegram-bot
# Enable auto-start
systemctl --user enable claude-telegram-botAfter editing the service file:
systemctl --user daemon-reload
systemctl --user restart claude-telegram-botService won't start:
# Check logs for errors
journalctl --user -u claude-telegram-bot -n 100
# Verify paths in service file are correct
systemctl --user cat claude-telegram-bot
# Check that Poetry is installed
poetry --version
# Test the bot manually first
cd /home/ubuntu/Code/oss/claude-code-telegram
poetry run claude-telegram-botService stops after logout:
Enable lingering to keep user services running after logout:
loginctl enable-linger $USER- Service file:
~/.config/systemd/user/claude-telegram-bot.service - Logs: View with
journalctl --user -u claude-telegram-bot - Project:
/home/ubuntu/Code/oss/claude-code-telegram