Back
gh

grinev/opencode-telegram-bot: OpenCode mobile client via Telegram: run and monitor AI coding tasks from your phone while everything runs locally on your machine. Scheduled tasks support. Can be used as lightweight OpenClaw alternative.

OpenCode mobile client via Telegram: run and monitor AI coding tasks from your phone while everything runs locally on your machine. Scheduled tasks support. Can be used as lightweight OpenClaw alternative. - grinev/opencode-telegram-bot

by grinev github.com 1,650 words
View original

OpenCode Telegram Bot

npm version CI License: MIT Node.js

OpenCode Telegram Bot is a secure Telegram client for OpenCode CLI that runs on your local machine.

Run AI coding tasks, monitor progress, switch models, and manage sessions from your phone.

No open ports, no exposed APIs. The bot communicates with your local OpenCode server and the Telegram Bot API only.

Scheduled tasks support. Turns the bot into a lightweight OpenClaw alternative for OpenCode users.

Platforms: macOS, Windows, Linux

Languages: English (en), Deutsch (de), Español (es), Français (fr), Русский (ru), 简体中文 (zh)

OpenCode Telegram Bot screencast

Features

Planned features currently in development are listed in Current Task List.

Prerequisites

Quick Start

1. Create a Telegram Bot

  1. Open @BotFather in Telegram and send /newbot
  2. Follow the prompts to choose a name and username
  3. Copy the bot token you receive (e.g. 123456:ABC-DEF1234...)

You’ll also need your Telegram User ID — send any message to @userinfobot and it will reply with your numeric ID.

2. Start OpenCode Server

Start the OpenCode server:

opencode serve

The bot connects to the OpenCode API at http://localhost:4096 by default.

3. Install & Run

The fastest way — run directly with npx:

npx @grinev/opencode-telegram-bot

Quick start is for npm usage. You do not need to clone this repository. If you run this command from the source directory (repository root), it may fail with opencode-telegram: not found. To run from sources, use the Development section.

On first launch, an interactive wizard will guide you through the configuration — it asks for interface language first, then your bot token, user ID, OpenCode API URL, and optional OpenCode server credentials (username/password). After that, you’re ready to go. Open your bot in Telegram and start sending tasks.

Alternative: Global Install

npm install -g @grinev/opencode-telegram-bot
opencode-telegram start

To reconfigure at any time:

opencode-telegram config

Supported Platforms

PlatformStatus
macOSFully supported
WindowsFully supported
LinuxFully supported (tested on Ubuntu 24.04 LTS)

Bot Commands

CommandDescription
/statusServer health, current project, session, and model info
/newCreate a new session
/abortAbort the current task
/sessionsBrowse and switch between recent sessions
/projectsSwitch between OpenCode projects
/renameRename the current session
/commandsBrowse and run custom commands
/taskCreate a scheduled task
/tasklistBrowse and delete scheduled tasks
/opencode_startStart the OpenCode server remotely
/opencode_stopStop the OpenCode server remotely
/helpShow available commands

Any regular text message is sent as a prompt to the coding agent only when no blocking interaction is active. Voice/audio messages are transcribed and then sent as prompts when STT is configured.

/opencode_start and /opencode_stop are intended as emergency commands — for example, if you need to restart a stuck server while away from your computer. Under normal usage, start opencode serve yourself before launching the bot.

Scheduled Tasks

Scheduled tasks let you prepare prompts in advance and run them automatically later or on a recurring schedule. This is useful for periodic checks, routine code maintenance, or tasks you want OpenCode to execute while you are away from your computer. Use /task to create a scheduled task and /tasklist to review or delete existing ones.

Configuration

Localization

Environment Variables

When installed via npm, the configuration wizard handles the initial setup. The .env file is stored in your platform’s app data directory:

VariableDescriptionRequiredDefault
TELEGRAM_BOT_TOKENBot token from @BotFatherYes
TELEGRAM_ALLOWED_USER_IDYour numeric Telegram user IDYes
TELEGRAM_PROXY_URLProxy URL for Telegram API (SOCKS5/HTTP)No
OPENCODE_API_URLOpenCode server URLNohttp://localhost:4096
OPENCODE_SERVER_USERNAMEServer auth usernameNoopencode
OPENCODE_SERVER_PASSWORDServer auth passwordNo
OPENCODE_MODEL_PROVIDERDefault model providerYesopencode
OPENCODE_MODEL_IDDefault model IDYesbig-pickle
BOT_LOCALEBot UI language (supported locale code, e.g. en, de, es, fr, ru, zh)Noen
SESSIONS_LIST_LIMITSessions per page in /sessionsNo10
PROJECTS_LIST_LIMITProjects per page in /projectsNo10
COMMANDS_LIST_LIMITCommands per page in /commandsNo10
TASK_LIMITMaximum number of scheduled tasks that can exist at onceNo10
SERVICE_MESSAGES_INTERVAL_SECService messages interval (thinking + tool calls); keep >=2 to avoid Telegram rate limits, 0 = immediateNo5
HIDE_THINKING_MESSAGESHide 💭 Thinking... service messagesNofalse
HIDE_TOOL_CALL_MESSAGESHide tool-call service messages (💻 bash ..., 📖 read ..., etc.)Nofalse
RESPONSE_STREAMINGStream assistant replies while they are generated across one or more Telegram messagesNotrue
MESSAGE_FORMAT_MODEAssistant reply formatting mode: markdown (Telegram MarkdownV2) or rawNomarkdown
CODE_FILE_MAX_SIZE_KBMax file size (KB) to send as documentNo100
STT_API_URLWhisper-compatible API base URL (enables voice/audio transcription)No
STT_API_KEYAPI key for your STT providerNo
STT_MODELSTT model name passed to /audio/transcriptionsNowhisper-large-v3-turbo
STT_LANGUAGEOptional language hint (empty = provider auto-detect)No
LOG_LEVELLog level (debug, info, warn, error)Noinfo

Keep your .env file private. It contains your bot token. Never commit it to version control.

Voice and Audio Transcription (Optional)

If STT_API_URL and STT_API_KEY are set, the bot will:

  1. Accept voice and audio Telegram messages
  2. Transcribe them via POST {STT_API_URL}/audio/transcriptions
  3. Show recognized text in chat
  4. Send the recognized text to OpenCode as a normal prompt

Supported provider examples (Whisper-compatible):

If STT variables are not set, voice/audio transcription is disabled and the bot will ask you to configure STT.

Model Configuration

The model picker uses OpenCode local model state (favorite + recent):

To add a model to favorites, open OpenCode TUI (opencode), go to model selection, and press Cmd+F/Ctrl+F on the model.

Security

The bot enforces a strict user ID whitelist. Only the Telegram user whose numeric ID matches TELEGRAM_ALLOWED_USER_ID can interact with the bot. Messages from any other user are silently ignored and logged as unauthorized access attempts.

Since the bot runs locally on your machine and connects to your local OpenCode server, there is no external attack surface beyond the Telegram Bot API itself.

Development

Running from Source

git clone https://github.com/grinev/opencode-telegram-bot.git
cd opencode-telegram-bot
npm install
cp .env.example .env
# Edit .env with your bot token, user ID, and model settings

Build and run:

npm run dev

Available Scripts

ScriptDescription
npm run devBuild and start (development)
npm run buildCompile TypeScript
npm startRun compiled code
npm run release:notes:previewPreview auto-generated release notes
npm run lintESLint check (zero warnings policy)
npm run formatFormat code with Prettier
npm testRun tests (Vitest)
npm run test:coverageTests with coverage report

Note: No file watcher or auto-restart is used. The bot maintains persistent SSE and long-polling connections — automatic restarts would break them mid-task. After making changes, restart manually with npm run dev.

Troubleshooting

Bot doesn’t respond to messages

“OpenCode server is not available”

No models in model picker

Linux: permission denied errors

Contributing

Please follow commit and release note conventions in CONTRIBUTING.md.

Community

Have questions, want to share your experience using the bot, or have an idea for a feature? Join the conversation in GitHub Discussions.

License

MIT © Ruslan Grinev