A local bridge that lets you control Codex from Telegram and receive Codex notify events in Telegram.
- Telegram long-polling bridge for Codex CLI
- Per-chat session handling (resume latest, resume specific session, or force new session)
- Image support (
codex exec ... -i <image>) - Codex
notifyforwarding to Telegram - Optional local Linux desktop/audio notifications (
notify-send+paplay)
bridge.py: main Telegram polling + Codex bridgenotify_telegram.py: sends Codex notify payloads to Telegramnotify_all.sh: notify hook wrapper (Telegram + optional desktop/audio notification).env.example: configuration templatereset_codex_sessions.sh: helper to clear~/.codex/sessions/*and truncate~/.codex/history.jsonl
- Python 3.12+
codexavailable in PATH- Telegram bot token
- Your Telegram user ID and/or username in the allowlist
- Clone:
git clone <your-repo-url> /path/to/codex-telegram-bridge
cd /path/to/codex-telegram-bridge- Create
.envfrom the template:
cp .env.example .env- Install Python dependencies:
python3 -m pip install -r requirements.txt-
Edit
.envwith your real values. -
Configure Codex notify hook in
~/.codex/config.toml:
notify = ["/path/to/codex-telegram-bridge/notify_all.sh"]- Start the bridge:
python3 /path/to/codex-telegram-bridge/bridge.pyDefault env path:
/path/to/codex-telegram-bridge/.env
Optional env override:
TELEGRAM_BRIDGE_ENV_PATHTELEGRAM_BRIDGE_STATE_PATH
BOT_TOKEN: Telegram bot tokenNOTIFY_CHAT_ID: chat wherenotify_telegram.pysends notify eventsALLOWED_USERNAMES: comma-separated usernames (without@preferred)ALLOWED_USER_IDS: comma-separated Telegram numeric user IDsDEFAULT_CWD: default working directory if/newis used without an explicit pathCODEX_BIN: Codex binary path/name (defaultcodex)POLL_TIMEOUT_SECONDS: Telegram polling timeout (default30)POLL_SLEEP_SECONDS: sleep after polling errors (default1.0)CODEX_TIMEOUT_SECONDS: timeout for Codex command execution (default900)SKIP_GIT_REPO_CHECK:true|false(defaulttrue)LOG_LEVEL:debug|info|warn|error(defaultinfo)
DESKTOP_NOTIFY_TITLE(defaultCodex)DESKTOP_NOTIFY_MESSAGE(defaultResponse ready)NOTIFY_AUDIO_PATH(default$HOME/scripts/codex-done.oga)
If paplay is missing, audio is skipped. If the audio file does not exist, audio is skipped.
/help/sessions/resume/resume latest/resume new/resume <index|session_id>/attach <index|session_id>/current/new/new /path/new ~/new ~/project/ask <prompt>
Plain text messages are treated as /ask.
Unauthorized user.ALLOWED_USERNAMES/ALLOWED_USER_IDSis missing or incorrect.
No sessions found...- You do not have local Codex history/session files yet.
- Notification errors
- Check
state/telegram_error.log.
- Check
- Invalid cwd
- Use
/new <path>(supports/abs/path,~,~/subdir).
- Use
- Copy the service template:
sudo cp /path/to/codex-telegram-bridge/systemd/codex-telegram-bridge.service /etc/systemd/system/codex-telegram-bridge.service- Edit placeholders in the unit file:
- Replace
<your_username>with the Linux user that should run the bridge. - Keep
/path/to/codex-telegram-bridgepointing to your actual clone location.
- Reload and start:
sudo systemctl daemon-reload
sudo systemctl enable --now codex-telegram-bridge- Operate the service:
sudo systemctl status codex-telegram-bridge
sudo journalctl -u codex-telegram-bridge -f
sudo systemctl restart codex-telegram-bridge
sudo systemctl disable --now codex-telegram-bridgepython3installed on the host.- Dependencies installed with
python3 -m pip install -r /path/to/codex-telegram-bridge/requirements.txt. codexavailable inPATHfor the service user.- Valid
/path/to/codex-telegram-bridge/.envwith required variables.
- Service fails immediately:
- Check logs with
sudo journalctl -u codex-telegram-bridge -n 100 --no-pager.
- Check logs with
codex: command not found:- Set an absolute binary path in
.env, for example:CODEX_BIN=/absolute/path/to/codex
- Then restart the service:
sudo systemctl restart codex-telegram-bridge
- Alternatively, set
PATHexplicitly in the systemd unit file for the service user.
- Set an absolute binary path in
SyntaxError: Unexpected reserved wordfromcodex.js:- Your service is likely using an old
nodebinary (for example/usr/bin/node). - If
codexis installed vianvm, ensure thenvmNode bin path is first in the unitPATH, for example:Environment=PATH=/home/<your_username>/.nvm/versions/node/v22.18.0/bin:/home/<your_username>/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- Reload and restart:
sudo systemctl daemon-reloadsudo systemctl restart codex-telegram-bridge
- Your service is likely using an old
- Missing/invalid env values:
- Verify
BOT_TOKEN, allowlist variables, and env file path.
- Verify
/path/to/codex-telegram-bridge/reset_codex_sessions.shThis removes everything under ~/.codex/sessions/ and truncates ~/.codex/history.jsonl.