How to Connect OpenAI Codex CLI to AGNT
Connect your OpenAI Codex CLI to AGNT and use GPT Codex models directly from your desktop. This guide covers installation, authentication, and troubleshooting.
Prerequisites
Before connecting, you need the Codex CLI installed on your machine.
Install Codex CLI
npm install -g @openai/codexVerify the installation:
codex --versionNote: AGNT auto-discovers the Codex binary from common locations (npm global, nvm, fnm, Homebrew, Volta, asdf). If you installed Codex through any of these, AGNT should find it automatically.
Supported Models
Once connected, AGNT gives you access to these Codex models:
| Model | Description |
|---|---|
gpt-5.2-codex |
Latest GPT Codex model |
gpt-5.1-codex |
Previous generation GPT Codex model |
These models run through OpenAI's Codex Responses API and require OAuth authentication (not a standard API key).
Connecting Codex to AGNT
You can connect from two places in the AGNT UI. Both use the same device authentication flow.
Option A: Connectors Page
- Open Connectors from the left sidebar
- Go to the Auth Connections section
- Find OpenAI Codex and click Connect
- Follow the device login flow (see below)
Option B: Integration Health Panel
- Open any Chat panel
- In the right sidebar, find the Connected Integrations section
- Click the connect button next to OpenAI Codex
- Follow the device login flow (see below)
Device Login Flow
Codex uses OpenAI's device authorization flow β no passwords are entered in AGNT.
Step 1: Start Device Login
When you click Connect, AGNT starts the device auth process and displays a modal with:
- A URL (e.g.,
https://auth.openai.com/codex/device) - A one-time code (e.g.,
ABCD-1234)
Step 2: Authenticate with OpenAI
- Open the URL in your browser
- Enter the one-time code shown in AGNT
- Sign in to your OpenAI account
- Authorize the connection
Step 3: Confirm in AGNT
Return to AGNT and click I have logged in. AGNT will verify the connection and show a success message.
That's it β Codex models are now available in your agent chats.
Where Are Credentials Stored?
Codex credentials are stored locally on your machine, shared with the official Codex CLI:
~/.codex/auth.jsonThis file contains your OAuth tokens (access token, refresh token). AGNT reads from and writes to this file β it never sends your credentials to any third-party server.
Token Auto-Refresh
AGNT automatically refreshes your Codex OAuth token before it expires. OpenAI uses refresh token rotation, meaning each refresh issues a new refresh token. AGNT handles this transparently β you shouldn't need to re-authenticate unless you explicitly disconnect or your refresh token is revoked.
Environment Variables (Optional)
| Variable | Description | Default |
|---|---|---|
CODEX_BIN |
Explicit path to the codex binary |
Auto-discovered |
CODEX_HOME |
Override the Codex config directory | ~/.codex |
CODEX_OAUTH_CLIENT_ID |
Override the OAuth client ID | OpenAI's public client ID |
Most users don't need to set any of these.
Troubleshooting
"spawn script ENOENT"
Cause: Older versions of AGNT used a Unix script command to wrap the Codex CLI process. This fails on systems where script is not installed (Docker containers, minimal Linux installs).
Fix: Update AGNT to the latest version. This was fixed in v0.5.0+. As a workaround, you can authenticate directly in your terminal:
codex login --device-authOnce authenticated, AGNT will pick up the tokens from ~/.codex/auth.json automatically.
"HTTP error! status: 400"
Cause: Your OAuth access token has expired and failed to refresh. This typically happens when:
- You haven't used Codex in a while and the refresh token was rotated/revoked
- The token was already used by another client (OpenAI enforces refresh token rotation)
Fix: Disconnect and reconnect:
- Click Disconnect on the Codex integration
- Click Connect and complete the device login flow again
Or re-authenticate via terminal:
codex login --device-auth"Codex CLI not found"
Cause: AGNT cannot locate the codex binary on your system.
Fix:
- Verify Codex CLI is installed:
codex --version - If not installed:
npm install -g @openai/codex - If installed but AGNT can't find it, set the path explicitly in your
.env:
CODEX_BIN=/path/to/codex"Device code was not returned yet"
Cause: The Codex CLI is slow to respond or the device auth endpoint is rate-limited.
Fix: Wait a moment and try again. If you see this repeatedly, OpenAI may be rate-limiting device code requests. Wait 1β2 minutes before retrying.
Connection shows "Not Connected" after restart
This is expected if your OAuth token expired while AGNT was closed. AGNT will attempt to auto-refresh on next use. If auto-refresh fails, simply reconnect using the device login flow.
How It Works Under the Hood
βββββββββββββββ device-auth ββββββββββββββββ OAuth βββββββββββββββ
β AGNT UI β ββββββββββββββββββββ β AGNT Server β ββββββββββββ β OpenAI β
β (Connect) β β (Express) β β auth.openai β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β
spawns codex CLI
β
βββββββββββββββ
β ~/.codex/ β
β auth.json β
βββββββββββββββ- Frontend triggers device auth via the Vuex store
- Backend spawns
codex login --device-authand parses the device URL/code from stdout - User authenticates with OpenAI in their browser
- Codex CLI writes OAuth tokens to
~/.codex/auth.json - AGNT reads the tokens and uses them with the Codex Responses API at
chatgpt.com/backend-api/codex - Auto-refresh kicks in 5 minutes before token expiry, posting to
auth.openai.com/oauth/tokenwith the refresh token
FAQ
Q: Do I need an OpenAI API key?
No. Codex uses OAuth device authentication, not API keys. You sign in with your OpenAI account.
Q: Is my OpenAI account billed for Codex usage?
Codex usage follows your OpenAI account's plan and billing. Check your OpenAI dashboard for details.
Q: Can I use Codex and regular OpenAI at the same time?
Yes. Codex CLI and standard OpenAI are separate providers in AGNT. You can connect both simultaneously β they use independent credentials.
Q: Does AGNT share my credentials with anyone?
No. Credentials are stored locally in ~/.codex/auth.json on your machine. AGNT communicates directly with OpenAI's API β no credentials pass through any third-party server.