@royhk920/codex-telegram
v0.20.0
Published
Telegram bot bridge for Codex CLI on Linux
Downloads
21
Readme
codex-telegram
Telegram bot bridge for Codex CLI on Linux.
npm install
For a global install:
npm install -g codex-telegram
codex-telegram-install
codex-telegramThe npm package stores:
- config in
~/.config/codex-telegram/config.json - runtime data in
~/.local/share/codex-telegram/ - env token in
~/.config/codex/codex-telegram.env
If you prefer not to install globally:
npx codex-telegram-install
npx codex-telegramFeatures
- Send prompts to Codex from Telegram
- Streaming responses (JSONL events)
- Queueing (multiple messages)
- Per-chat session using Codex
thread_id - Saved session list with preview and manual session switching
- Automatic session compaction into a fresh thread when long-running context crosses configured thresholds
Setup (Ubuntu)
1) Install Node.js
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs2) Install Codex CLI
Install the Codex CLI in your environment and ensure codex is on PATH.
3) Configure the bot
cp config.example.json config.json
nano config.jsonFill in:
telegram.tokenorTELEGRAM_BOT_TOKENin the env filetelegram.allowedUserstelegram.adminChatIdcodex.model(optional)codex.path(optional, ifcodexnot on PATH)openai.adminKey(optional, for /costs)
Optional environment-based setup:
mkdir -p ~/.config/codex
cp .env.example ~/.config/codex/codex-telegram.env
nano ~/.config/codex/codex-telegram.envBy default the bot loads TELEGRAM_BOT_TOKEN from ~/.config/codex/codex-telegram.env before reading config.json. It also accepts the legacy fallback path ~/.config/opencode/codex-telegram.env for backward compatibility.
If you keep the token in the env file, config.json still needs telegram.allowedUsers and telegram.adminChatId so the bot knows who is allowed to use it.
Optional long-session controls in config.json:
defaults.autoCompact.enabled- turn automatic compaction on or offdefaults.autoCompact.maxTurns- compact after this many completed turns in one threaddefaults.autoCompact.maxChars- compact when recorded prompt+response chars exceed this budgetdefaults.autoCompact.maxTokens- compact when cumulative Codexturn.completed.usageinput+output tokens exceed this budgetdefaults.autoCompact.strategy-softfirst asks Codex to summarize the current thread into carry-forward memory before rotating to a fresh session;hardskips that step
4) Install dependencies
npm install5) Start
chmod +x start.sh
./start.sh6) Systemd service (optional)
This template assumes the repo lives at ~/codex-telegram. If you keep the repo elsewhere, edit WorkingDirectory in codex-telegram.service before copying it.
mkdir -p ~/.config/codex
cp .env.example ~/.config/codex/codex-telegram.env
nano ~/.config/codex/codex-telegram.env
mkdir -p ~/.config/systemd/user
cp codex-telegram.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable codex-telegram
systemctl --user start codex-telegramCheck status and logs:
systemctl --user status codex-telegram --no-pager
journalctl --user -u codex-telegram -n 50 --no-pagerFresh Machine Quick Start
For a clean Ubuntu machine, the shortest path is:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g @openai/codex
npm install
mkdir -p ~/.config/codex
cp .env.example ~/.config/codex/codex-telegram.env
nano ~/.config/codex/codex-telegram.env
cp config.example.json config.json
nano config.json
./start.shInstaller Mode vs Manual Mode
You can set up codex-telegram in two ways:
install.shmode: Use the menu-driven installer when you want a step-by-step CLI wizard that asks for your Telegram token, your Telegram user ID, your admin chat ID, and optional Codex settings, then writesconfig.jsonand~/.config/codex/codex-telegram.envfor you.- manual mode: Follow the commands in this README when you want explicit control over each step or when debugging an installation issue.
As a rule of thumb, use install.sh for first-time setup and manual mode when you need to inspect or customize the environment more closely.
Wizard flow:
./install.shThen choose:
4to install npm dependencies5to run the setup wizard7to start the bot
Development
Run tests locally:
npm testSyntax check locally:
node --check bot.js
node --check telegram.js
node --check codex-client.jsCI Status
The repository includes a basic GitHub Actions workflow at .github/workflows/ci.yml.
Current CI scope:
- install dependencies with
npm ci - run the Node test suite with
npm test
For a quick local health check without opening the installer menu:
./install.sh --checkIf you later publish this repository to GitHub, you can add a workflow badge once the final repository URL is known.
Runtime Files
These files and folders are created locally while the bot runs and are ignored by Git:
config.jsonsessions.jsonjobs.jsonlong-term-memory.jsonuploads/bot.log.env
Troubleshooting
Bot does not start
- Check that
codexis installed and available onPATH - Check
config.jsonor~/.config/codex/codex-telegram.env - Check that
telegram.allowedUsersandtelegram.adminChatIdare set inconfig.json - Run
npm testfirst to confirm the local Node environment is healthy
Telegram bot does not respond
- Confirm
TELEGRAM_BOT_TOKENis valid - Confirm your Telegram user ID is included in
telegram.allowedUsers - Check logs with:
journalctl --user -u codex-telegram -n 50 --no-pagersystemd service fails
- Reload the user daemon after copying the service file:
systemctl --user daemon-reload- Re-check status:
systemctl --user status codex-telegram --no-pagerConfig changes do not apply
- Restart the process after editing config or env values:
systemctl --user restart codex-telegram- If you are not using systemd, stop the running process and start
./start.shagain
Commands
/helpshow help/newclear conversation thread/sessionslist saved sessions for this chat/sessionswitch to a saved session, or rename one withrename/compressrefresh a compact carry-forward summary for the current thread/modelset model/thinkingset reasoning effort/modeset execution mode (safe,workspace,danger)/systemset system prompt/skillselect skills for the current chat/memoryshow or manage session + long-term memory/mcpstatusshow configured MCP servers/codexshow Codex CLI status/costsshow OpenAI costs (requires admin key)/usageshow API usage & costs/diskcheck disk usage/cronmanage background cron jobs/stopstop current response + clear queue/clearclear queued messages/restartrestart bot/statusshow status
Memory
When codex-session-memory is selected in /skill, the bot keeps two layers of memory:
- thread memory: summary, pinned notes, and recent decisions for the current Codex thread
- long-term memory:
chat-scoped notes stored in
long-term-memory.jsonand retrieved by local search for future prompts
Useful commands:
/compress
/compress Preparing to split this task into a new thread.
/memory
/memory pin Use Cantonese / HK style unless I ask otherwise.
/memory remember Implement long-term memory before subagent orchestration.
/memory search subagent orchestration
/memory forget mem_abc123
/memory clearNotes:
/compressasks Codex to condense the current thread into carry-forward memory and shows the result/memory pinsaves to the current thread and also persists the same note into long-term memory/memory clearonly clears the current thread memory/memory forgetremoves long-term memory for the current chat only
Background jobs
Background jobs run in separate Codex sessions, so they do not reuse the foreground chat thread or queue.
Examples:
/cron
/cron add
/cron add Daily report | daily:09:30 | Summarize open work, blockers, and the next priority.
/cron run job_abc123
/cron pause job_abc123
/cron resume job_abc123
/cron delete job_abc123Wizard flow:
/cron add- Choose
One TimeorRecurring - Send a natural-language schedule such as
in 10m,tomorrow 09:30,every 2h, ordaily 09:30 - Send the job prompt in natural language
Supported schedule formats:
every:5mevery:1hevery:1ddaily:09:30
