A self-hosted Python service that forwards Telegram requests to Codex CLI on a Linux machine. Telegram long polling avoids inbound webhooks. Telegram user IDs control who can use the bot, and workspace aliases select Codex's working directory.
Request flow: Telegram → bot and command handlers → Codex wrapper → reply to Telegram. The bot runs one command at a time and supports timeouts, session persistence, and rotating logs. A systemd user service runs the bot in the background.
-
On Linux with systemd and Python 3 with
venv, install Codex CLI and verify thatcodex --versionandcodex loginwork for the service user. -
Create a Telegram bot through
@BotFatherand obtain the numeric Telegram user ID of each person you plan to authorize. -
Clone the repository into the location expected by the bundled service:
git clone https://github.com/Math680/Telegram-Codex-Bridge.git ~/telegram-codex-bridge cd ~/telegram-codex-bridge cp .env.example config.env chmod 600 config.env
-
Edit
config.envbefore starting the service. SetTELEGRAM_BOT_TOKEN,TELEGRAM_USER_ID, the absolute path to Codex inCODEX_BIN, and your workspace paths inALLOWED_DIRS_JSON. SetDEFAULT_DIR_ALIASto one of the configured aliases. SetCODEX_SANDBOX=read-onlyandCODEX_BYPASS_APPROVALS=0as standalone lines to start with the narrowest access. -
Run
bash install.sh, then try/ping,/repos, and/ask List the top-level filesin Telegram.
All configuration lives in config.env.
TELEGRAM_BOT_TOKEN(required)TELEGRAM_USER_ID(required) single userTELEGRAM_ALLOWED_USERSoptional comma‑separated list (overridesTELEGRAM_USER_ID)
ALLOWED_DIRS_JSON(required)- Example:
{"app":"/home/you/projects/my-app","docs":"/home/you/docs"}
- Example:
DEFAULT_DIR_ALIAS(required)
CODEX_BIN(default:/usr/bin/codex)CODEX_TIMEOUT(seconds, default120)DEFAULT_CODEX_MODEL(defaultgpt-5.2-codex)DEFAULT_CODEX_REASONING(defaultmedium)
CODEX_SANDBOX:read-only|workspace-write|danger-full-accessCODEX_BYPASS_APPROVALS:0or1- If
1, the CLI uses--dangerously-bypass-approvals-and-sandbox. - This disables sandboxing, so use only if you trust the environment.
- If
ASK_ON_TEXT:1to treat any normal message as/askASK_ACK_MESSAGE: optional message sent immediately after an/askSYSTEM_PROMPT: default system promptSYSTEM_PROMPT_ENABLED:1to enable by default
/ping→ health check/help→ list commands/status→ bot status, model, session, permissions/repos→ list allowed workspaces/cd <alias>→ switch workspace/ask <text>→ run Codex in active workspace/model <name> [low|medium|high|extra-high]→ set model & reasoning/system <text|on|off|clear>→ manage system prompt/permissions→ show or set sandbox/approval behavior/new→ reset session context
- Grant Telegram access only to trusted users. Authorized users can send prompts to Codex and change its permission mode with
/permissions. - Workspace aliases restrict starting directories. The Codex sandbox controls actual filesystem access, and bypass mode disables that protection.
- Keep the bot token out of Git. Review the configured permissions before allowing write access.
~/telegram-codex-bridge/logs/telegram-codex.log- Log rotation is enabled.
- Service status:
systemctl --user status telegram-codex-bridge
- Logs:
tail -f ~/telegram-codex-bridge/logs/telegram-codex.log
MIT.