Small local bridge that connects Telegram chats to a local codex app-server session.
- Maps each Telegram chat to one Codex thread (
chat_id -> threadId) and persists it. - Starts a Codex turn for each text message.
- Streams live agent output updates to Telegram with edit rate-limiting.
- Handles Codex approval requests with Telegram inline buttons (Accept / Decline).
- Restarts
codex app-serverautomatically and resumes known threads.
- Python 3.12 (pinned via
.python-version) uvpackage managercodexCLI installed and authenticated- Telegram bot token
uv syncCreate a local .env in the project root (already ignored by .gitignore):
TELEGRAM_BOT_TOKEN=<your_telegram_bot_token>
TELEGRAM_ALLOWED_USERS=<telegram_user_id_comma_separated>
CODEX_MODEL=gpt-5.3-codex
CODEX_CWD=C:/Projects/tg-codex
STATE_PATH=./.codex_telegram_state.json
LOG_LEVEL=INFO
CODEX_AUTO_APPROVE_COMMANDS=false
CODEX_AUTO_APPROVE_FILE_CHANGES=falseEnvironment variable reference:
- Required:
TELEGRAM_BOT_TOKEN- Telegram bot token.TELEGRAM_ALLOWED_USERS- comma-separated Telegram user ids (example:123456,987654).
- Optional:
CODEX_MODEL- defaults togpt-5.3-codex(fallback togpt-5.1-codexduring thread creation).CODEX_CWD- defaults to current working directory.STATE_PATH- defaults to./.codex_telegram_state.json.LOG_LEVEL- defaults toINFO.CODEX_AUTO_APPROVE_COMMANDS- whentrue, auto-accepts command execution approvals.CODEX_AUTO_APPROVE_FILE_CHANGES- whentrue, auto-accepts file-change approvals.
Security note:
- Auto-approve flags remove the Telegram human-approval gate. Enable only in trusted local environments.
Run:
uv run --env-file .env python -m codex_telegram_bot/start- help text./new- create and map a new Codex thread for this chat./reset- clear this chat mapping.
Any other text message starts a turn in the mapped thread.
Default state file: ./.codex_telegram_state.json
Stored per chat:
thread_idlast_turn_id- pending approval metadata (
request_id,method,thread_id,turn_id)
uv run pytest -qcodex app-server generate-json-schema --out ./schemas