You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Telegram bot that gives you remote access to `@openai/codex` through a PTY-backed Node.js runtime.
7
-
It is strictly inspired by `RichardAtCT/claude-code-telegram`, but this project is implemented for Codex CLI + MCP + Subagent routing.
6
+
A Telegram bot that gives you remote access to `@openai/codex` through a Node.js runtime with two Codex backends: the Codex SDK and the legacy CLI/PTy path.
7
+
It is strictly inspired by `RichardAtCT/claude-code-telegram`, but this project is implemented for Codex SDK/CLI + MCP + Subagent routing.
8
8
9
9
## What Is This?
10
10
11
-
This bot connects Telegram to Codex CLI and routes tasks to the right execution surface:
11
+
This bot connects Telegram to Codex and routes tasks to the right execution surface:
-**Coding requests** are sent directly to Codex CLI (Codex can use its own MCP stack)
131
+
-**Coding requests** are sent directly to Codex (SDK or CLI backend; Codex can use its own MCP stack)
130
132
-**Bot-side MCP** is only used by explicit `/mcp ...` commands
131
133
132
134
This prevents:
@@ -150,7 +152,7 @@ How they are triggered:
150
152
-`/gh ...` -> GitHub skill
151
153
-`/mcp ...` -> MCP skill
152
154
- Plain text may also route to a subagent when the router sees a supported GitHub-style request such as `git push`, `commit`, or `run test`
153
-
- Everything else falls back to Codex CLI
155
+
- Everything else falls back to Codex
154
156
155
157
Where this happens:
156
158
@@ -175,8 +177,8 @@ General:
175
177
-`/repo recent` - show recent projects for the current chat
176
178
-`/repo -` - switch back to the previous project
177
179
-`/new` - clear the saved Codex conversation for the current project and start fresh on the next message
178
-
-`/exec <task>` - force a one-off `codex exec`
179
-
-`/auto <task>` - force a one-off `codex exec --full-auto`
180
+
-`/exec <task>` - force a one-off Codex run without saving project context
181
+
-`/auto <task>` - force a one-off fully automatic Codex run without saving project context
180
182
-`/plan <task>` - ask Codex for a plan only, without direct file modification intent
181
183
-`/model [name|reset]` - show or set the model override for the current chat
182
184
-`/language [en|zh|zh-HK]` - show or set the system language for the current chat
@@ -188,8 +190,8 @@ General:
188
190
-`/sh <command>` - run a safe allowlisted Linux command in the current project (disabled by default)
189
191
-`/sh --confirm <command>` - confirm a dangerous command when writable mode is enabled
190
192
-`/restart` - restart the bot process explicitly from Telegram
191
-
-`/interrupt` - send `Ctrl+C` to current PTY session
192
-
-`/stop` - terminate current PTY session
193
+
-`/interrupt` - interrupt the active Codex run
194
+
-`/stop` - terminate the active Codex run
193
195
-`/cron_now` - trigger daily summary immediately
194
196
195
197
MCP skill:
@@ -212,9 +214,9 @@ GitHub skill:
212
214
213
215
Telegram adaptation notes:
214
216
215
-
- Plain text messages behave like `codex "task description"`
216
-
-`/exec`behaves like `codex exec "task"`
217
-
-`/auto`behaves like `codex exec --full-auto "task"`
217
+
- Plain text messages behave like a normal Codex conversation turn
218
+
-`/exec`runs a one-off Codex task and does not overwrite the saved project conversation slot
219
+
-`/auto`runs a one-off Codex task with `approvalPolicy=never` on the SDK backend, or `codex exec --full-auto` on the CLI backend
218
220
-`/new` is implemented by the bot and resets the current chat session
219
221
-`/new` only clears the current project's saved Codex conversation slot
220
222
-`/status` is implemented by the bot and reports local runtime state
@@ -228,27 +230,58 @@ Telegram adaptation notes:
228
230
229
231
## Streaming and Reasoning Visualization
230
232
231
-
PTY output is streamed with throttled `editMessageText` updates.
233
+
Codex output is streamed with throttled `editMessageText` updates.
232
234
233
235
- Throttle: controlled by `STREAM_THROTTLE_MS` (default `1200`)
234
236
- Long output: auto-chunked to Telegram-safe message sizes
235
237
- MarkdownV2: escaped to avoid parse failures
236
238
- Reasoning tags: `<think>...</think>` extracted and rendered as:
237
239
- spoiler (`||...||`, default)
238
240
- quote block (if `REASONING_RENDER_MODE=quote`)
239
-
- If `node-pty` cannot spawn on the current host, the runner falls back to `codex exec` for per-request execution
240
-
- In `codex exec` fallback mode, Telegram output is cleaned to hide the Codex banner, raw tool trace, `mcp startup`, and duplicate `tokens used` footer
241
-
- On macOS, startup now auto-repairs `node-pty` helper execute permissions before the first PTY session
241
+
- On `CODEX_BACKEND=sdk`, Telegram streams structured Codex SDK events and persists thread IDs per project
242
+
- On `CODEX_BACKEND=cli`, the bot prefers PTY sessions; if `node-pty` cannot spawn on the current host, it falls back to `codex exec`
243
+
- In CLI exec fallback mode, Telegram output is cleaned to hide the Codex banner, raw tool trace, `mcp startup`, and duplicate `tokens used` footer
244
+
- On macOS, startup auto-repairs `node-pty` helper execute permissions before the first PTY session
242
245
243
246
## Project-Scoped Conversation State
244
247
245
248
Conversation state is now tracked per `chat + project`, not just per chat.
246
249
247
250
- When you switch with `/repo <name>`, the bot keeps that project's last Codex session id in runtime state
248
-
- When you switch back to the same project later, the next plain-text task resumes that project's Codex conversation
251
+
- When you switch back to the same project later, the next plain-text task resumes that project's Codex thread/session
249
252
-`/new` clears only the current project's saved conversation slot; other projects in the same Telegram chat are untouched
250
253
-`/exec`, `/auto`, and `/plan` stay one-off by design and do not replace the saved project conversation
251
-
- On hosts where PTY is unavailable, project restore still works through `codex exec resume`
254
+
- On the SDK backend, project restore uses `resumeThread(threadId)`
255
+
- On the CLI backend, project restore uses PTY resume or `codex exec resume`
256
+
257
+
## Backend Selection
258
+
259
+
Choose the execution backend with `CODEX_BACKEND`:
260
+
261
+
-`sdk` - preferred for new installs; avoids PTY fragility and uses persistent Codex SDK threads
262
+
-`cli` - legacy backend; uses PTY when available and falls back to `codex exec`
@@ -389,7 +431,8 @@ Telegram can manage runtime usage of Bot-side MCP and skills, but not install ar
389
431
## Troubleshooting
390
432
391
433
-**Bot not responding**: verify `BOT_TOKEN` and `ALLOWED_USER_IDS`
392
-
-**Codex not producing output**: verify `CODEX_COMMAND` and `CODEX_WORKDIR`
434
+
-**Codex not producing output**: verify `CODEX_BACKEND`, `CODEX_COMMAND`, and `CODEX_WORKDIR`
435
+
-**SDK backend cannot resume**: verify the host still has access to `~/.codex/sessions` and that the saved thread id belongs to the same working directory
393
436
-**Markdown parse errors**: reduce output size/context; check special characters in tool output
394
437
-**MCP failures**: run `/mcp tools <server>` first to validate server availability
395
438
-**GitHub API failures**: verify `GITHUB_TOKEN` scope (`repo`) and account permissions
@@ -399,4 +442,5 @@ Telegram can manage runtime usage of Bot-side MCP and skills, but not install ar
0 commit comments