What Is Codex CLI? OpenAI's Terminal Coding Agent Explained (2026)
Codex is OpenAI's coding agent, and Codex CLI is the version that runs in your terminal. You describe a task in plain language, and it reads the code in your current directory, proposes changes, edits files, runs commands, and asks you to confirm before any sensitive action. If you are trying to work out what Codex is and how to get started, think of it as a coding assistant that lives on the command line. You can sign in with a ChatGPT account, an OpenAI API key, or a compatible endpoint.
Product details in this article (commands, config options, plan coverage) change between versions, so treat OpenAI's official documentation and repository README as the source of truth.
What is Codex, and how is it different from ChatGPT on the web?
ChatGPT on the web is a chat window: you paste code in, get suggestions back, and copy them into your project yourself. Codex CLI works directly inside your project directory:
- It can read project files and understand the directory structure.
- It can edit files directly instead of only giving you code snippets.
- It can run commands in the terminal, such as running tests or reading errors, then keep going based on the results.
- It has an approval mechanism: by default, writing files and running commands require your permission first.
The name "Codex" appears in more than one OpenAI product. Besides the command line, there are a web version, editor extensions, and other entry points, and their exact form is described in OpenAI's own materials. This article covers only the command-line version.
What is it good for, and what is it not?
Good fits:
- Getting a tour of an unfamiliar project: "Where is the entry point of this repo, and how does a request flow through it?"
- Small refactors, adding unit tests, or fixing a bug that has a clear error message.
- Writing scripts, reformatting in bulk, and generating boilerplate.
Use caution when:
- The refactor is large and has no tests as a safety net. It can introduce problems you will not notice.
- The directory involves secrets, a production database, or deploy commands. We recommend not granting automatic execution permissions there.
Whatever the task, review the diff and run the tests afterward. Treat it as a very fast collaborator whose work still needs checking.
How do you install Codex CLI?
The usual way is a global npm install, which requires Node.js first:
npm install -g @openai/codex
codex --version
After installing, go to your project directory and run codex to open the interactive interface. You can also install through other package managers or the official prebuilt binaries; check the official repository README for the exact commands. For a step-by-step walkthrough of installation, login, and your first run, see How to use Codex CLI: install, sign in, and run it for the first time.
What are the ways to sign in and pay?
| Method | What you need | Billing | Best for |
|---|---|---|---|
| ChatGPT account login | A working ChatGPT account | Included with a ChatGPT subscription; coverage depends on your plan | People already paying for ChatGPT |
| OpenAI API key | An OpenAI developer account and a key | Pay-as-you-go based on actual API usage | People who want usage-based billing and precise cost control |
| Custom endpoint | An OpenAI-compatible endpoint URL and key | Set by the endpoint provider | People without a ChatGPT account, or who want to standardize on one gateway |
Do not guess whether your subscription includes Codex or how much quota you get. See Does ChatGPT Plus include Codex? How to check what your subscription covers. To decide among the three, read Which plan to use for Codex: ChatGPT subscription, API key, or a compatible gateway.
One reminder: OpenAI services are only available in supported regions. Check the official page to confirm your region is supported, and follow the terms of service and local regulations.
How do you point Codex at a custom endpoint?
Codex CLI lets you declare a model provider in its config file. The general idea is to specify a provider name, an endpoint URL (the base URL), and the name of the environment variable that holds the key. The config file usually lives in a .codex folder in your home directory, and the exact field names and format are defined in the official docs.
Here is an illustration (the fields are for explanation only; verify them against the official docs before using them):
model_provider = "myprovider"
[model_providers.myprovider]
name = "My Provider"
base_url = "https://example.com/v1"
env_key = "MY_PROVIDER_API_KEY"
Then set the matching environment variable in your terminal and start codex. For how to set the endpoint URL and which tools read OPENAI_BASE_URL, see How to set the OPENAI_BASE_URL environment variable and which tools read it and Custom API endpoint setup for Claude Code, Codex, and OpenCode.
What if you don't have a ChatGPT account?
One option is a gateway that speaks the OpenAI-compatible API format. Take AGI Plan as an example: it is a multi-provider LLM aggregation gateway with monthly subscriptions, billed in RMB (Chinese yuan), and it does not require an overseas credit card. Its Codex tutorial says you do not need a ChatGPT account; you only change the endpoint URL to the one it provides, and the same quota can be switched between different capability groups. AGI Plan is a commercial partner of cdnping. It states clearly that it is not an officially authorized channel, and some models are marked "overseas only." Check AGI Plan's models page for specifics. The setup steps are on the AGI Plan getting-started page, and plan prices are on the pricing page.
Whether to use it depends on your budget and habits. If you already have a working ChatGPT subscription, just sign in with it.
Checklist before your first run
- Confirm Node.js is installed and that
node -vprints a version number. - After installing, run
codex --versionto confirm the command works. - Pick a sign-in method (account, API key, or custom endpoint). Do not put your key in files that get committed; see What is a .env file? How to read it in Python and Node.
- Try it first in a throwaway test directory, and keep the default approval mode.
- If the connection fails, check the OpenAI status page and Is Codex down? for an outage before troubleshooting your local network. For latency issues, see How to read latency when accessing AI APIs from China.
- After each change, check
git diffbefore deciding whether to keep it.
What to read next
If you have not decided between a command-line tool, an editor plugin, and an AI IDE, start with How to choose an AI coding tool. If you are already considering Claude Code, compare it in Claude Code vs. Codex CLI: how to choose. To get hands-on, follow the install guide, set up Codex CLI, and ask it to explain the project structure in a test directory. That is the lowest-risk first task.