A Telegram bot that acts as a gateway to an OpenCode server, allowing users to interact with the OpenCode AI agent directly from Telegram. It functions a bit like OpenClaw.
Both OpenCode CLI AND this binary are required to run the bot.
- OpenCode CLI installed (
opencodecommand available)
curl -sSL https://raw.githubusercontent.com/martins6/opencode-telegram/main/install.sh | bashThis will install the binary to ~/.local/bin. Make sure to add it to your PATH:
export PATH="$HOME/.local/bin:$PATH"Or install system-wide with sudo:
curl -sSL https://raw.githubusercontent.com/martins6/opencode-telegram/main/install.sh | bash -s -- -p /usr/local/binInstall a specific version:
curl -sSL https://raw.githubusercontent.com/martins6/opencode-telegram/main/install.sh | bash -s -- -v v0.1.0For developers who want to build from source, use local_install.sh:
./local_install.shRequirements:
- Go 1.21+ installed
- OpenCode CLI installed (
opencodecommand available)
This script builds the binary from local source code instead of downloading from GitHub releases.
- Open Telegram and search for @BotFather
- Send
/newbotto create a new bot - Follow the instructions and get your bot token
opencode-telegram newThis creates a workspace at ~/.opencode-telegram/ with template files.
Use the opencode auth login, choose your provider. Then also set it for opencode-telegram. Please, check models.dev for the standard reference of names for providers and models used in OpenCode. You can also inspect the logs for any mismatch of the naming.
To set the specific settings for your bot, you can use the following commands:
# Set your bot token
opencode-telegram config set bot.token "YOUR_BOT_TOKEN"
# Add your Telegram user ID to allowed users
opencode-telegram config set bot.allowed_users [123456789, "YourUserName"]
# Optional: Set default agent
opencode-telegram config set defaults.agent "telegram-agent"
# Optional: Set default model
opencode-telegram config set defaults.model "MiniMax-M2.5"
# Optional: Set default provider
opencode-telegram config set defaults.provider "minimax-coding-plan"
# View current configuration
opencode-telegram config listopencode-telegram startThis will:
- Initialize the Telegram bot
- Begin handling messages
Press Ctrl+C to stop gracefully.
The configuration file is stored at ~/.opencode-telegram/config.toml:
[bot]
token = "YOUR_BOT_TOKEN"
allowed_users = [123456789]
[workspace]
path = "~/.opencode-telegram/"
[defaults]
agent = "telegram-agent"
model = "MiniMax-M2.5"
provider = "minimax-coding-plan"| Command | Description |
|---|---|
opencode-telegram config set <key> <value> |
Set a config value |
opencode-telegram config get <key> |
Get a config value |
opencode-telegram config list |
List all config values |
| Key | Description |
|---|---|
bot.token |
Telegram bot token |
bot.allowed_users |
List of allowed Telegram user IDs |
workspace.path |
Workspace directory path |
defaults.agent |
Default agent name |
defaults.model |
Default LLM model |
defaults.provider |
Default LLM provider |
| Command | Description | Example |
|---|---|---|
/start |
Start the bot | /start |
/help |
Show help message | /help |
/set-agent <name> |
Set active agent | /set-agent coder |
/set-model <name> |
Set LLM model | /set-model claude-sonnet-4-5 |
/set-provider <name> |
Set LLM provider | /set-provider anthropic |
/workspace <path> |
Set workspace path | /workspace /path/to/folder |
~/.opencode-telegram/
├── AGENTS.md # Agent definitions
├── SOUL.md # System operator behavior
├── USER.md # User information
├── IDENTITY.md # Model identity
├── BOOTSTRAP.md # First-time setup
├── TOOLS.md # Tool definitions
├── downloads/
│ ├── images/ # Downloaded images
│ ├── audio/ # Downloaded audio
│ ├── documents/ # Downloaded documents
│ └── videos/ # Downloaded videos
├── conversations/ # Per-user conversation history
└── .logs/
└── YYYY-MM-DD.log # Daily log files
Logs are stored in ~/.opencode-telegram/.logs/ with format YYYY-MM-DD.log.
# View today's logs
opencode-telegram logs today
# View specific date
opencode-telegram logs 2026-03-05Log format:
[INPUT] [2026-03-05 10:30:45] User 123456789: "Hello"
[OUTPUT] [2026-03-05 10:30:46] Response text...
Log retention is 30 days (auto-cleanup).
When you send media to the bot:
- The bot downloads the file from Telegram
- Saves it to
workspace/downloads/{type}/ - Constructs a prompt with the file path
- Sends to OpenCode server with context
| Telegram Type | Workspace Folder |
|---|---|
| Photo | downloads/images/ |
| Audio | downloads/audio/ |
| Voice | downloads/audio/ |
| Document | downloads/documents/ |
| Video | downloads/videos/ |
| Command | Description |
|---|---|
opencode-telegram start |
Start bot + OpenCode server |
opencode-telegram config |
Configuration management |
opencode-telegram new [path] |
Initialize new workspace |
opencode-telegram logs [date] |
View logs |
.
├── cmd/ # CLI commands
│ ├── root.go
│ ├── start.go
│ ├── config.go
│ ├── new.go
│ └── logs.go
├── internal/
│ ├── bot/ # Telegram bot
│ ├── config/ # Configuration
│ ├── logger/ # Logging
│ ├── media/ # Media handling
│ ├── opencode/ # OpenCode integration
│ ├── session/ # Session management
│ └── workspace/ # Workspace templates
├── main.go
└── go.mod
github.com/go-telegram/bot- Telegram Bot APIgithub.com/spf13/cobra- CLI frameworkgithub.com/spf13/viper- Configurationgithub.com/google/uuid- UUID generation
MIT