Codex CLI is OpenAI’s terminal coding agent, built in Rust. The codex runner invokes codex exec --json --full-auto as a subprocess and parses its structured JSONL output to stream responses to Telegram in real time.
Requirements
- Codex CLI installed (
npm install -g @openai/codex)
- A ChatGPT Plus, Pro, Business, Edu, or Enterprise subscription or a
CODEX_API_KEY (OpenAI API key)
Install Codex CLI:
Verify the installation:
Authentication
Codex CLI supports two authentication modes:
Option A — API key
Set a CODEX_API_KEY (your OpenAI API key) during remoteagent init. RemoteAgent.CHAT injects it at runtime — no manual environment variable setup required.
Option B — Device login (no browser on the server needed)
Run codex login --device-auth. Codex displays a short URL and a code. Open that URL on any device — your phone, laptop, or any browser — and enter the code to authenticate your ChatGPT account. No browser is needed on the server where the agent runs.
Credentials are stored in ~/.codex/auth.json and reused automatically on every subsequent run.
Option C — Already authenticated
If you have previously logged in with codex login or codex login --device-auth, you can skip the auth step during remoteagent init — the stored credentials will be used automatically.
Setup
Or choose codex when prompted by the interactive wizard.
During remoteagent init, the wizard will ask:
- Auth method — API key, device login (
codex login --device-auth), or skip if already authenticated
- Model — optional; defaults to
gpt-5.4. Enter any model ID supported by Codex CLI.
How it works
The runner executes:
--json — structured JSONL output on stdout for reliable parsing
--full-auto — alias for --sandbox workspace-write, allows file writes in the working directory
--skip-git-repo-check — allows running outside of a git repository
-m gpt-5.4 — model selection (gpt-5.4 is the current recommended model)
-- — separator that prevents prompts starting with - from being parsed as flags
RemoteAgent.CHAT parses the JSONL event stream and forwards text to Telegram as it arrives:
Pros and cons
Model selection
The default model is gpt-5.4. To use a different model, specify it during remoteagent init or update your agent config:
gpt-5.3-codex is deprecated and causes WebSocket reconnect loops. Use gpt-5.4 or a newer model.
Updating Codex CLI
Restart the agent after updating: