How to use Codex CLI: install, AGENTS.md, MCP and exec
Explore with AI
To use Codex CLI, install it with OpenAI's installer, run codex in your project and sign in with your ChatGPT account. Run /init to create an AGENTS.md, use /permissions to choose what Codex may do, and codex resume to reopen a chat. For scripts and CI, use codex exec, and add MCP servers with codex mcp add.
To use Codex CLI, install it, run codex in your project, sign in with ChatGPT, and run /init to give it an AGENTS.md. Choose what it may do with /permissions, reopen work with codex resume, and use codex exec when a script or CI job runs it instead of you.
Codex CLI is OpenAI’s coding agent for the terminal. It reads your repository, edits files and runs commands from a session in your shell. The steps below follow OpenAI’s Codex CLI documentation.
1. Install Codex CLI and sign in
On macOS and Linux, the standalone installer is one line:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Then start it from a project:
cd ~/code/my-app
codex
The first run asks you to sign in. Choose Sign in with ChatGPT to use your ChatGPT plan.
2. Give it an AGENTS.md
Codex reads project instructions from an AGENTS.md file. Create one from inside a session:
/init
/init writes an AGENTS.md with instructions for Codex based on your repository. Edit it down to what a new engineer would need: how to build, how to run the tests, the conventions that are easy to get wrong. Commit it, so every session and every teammate starts from the same rules.
3. Choose what Codex may do
Codex asks before it acts outside what you have allowed. Use the /permissions slash command to choose what Codex is allowed to do in the session. Start strict on a repository you care about, and loosen it once you trust how it works there.
The other slash commands worth learning first:
| Command | What it does |
|---|---|
/model | Choose the model and its reasoning effort |
/status | Show the current session configuration |
/review | Review your changes and find issues |
/init | Create an AGENTS.md |
4. Pick up where you left off
codex resume
codex resume reopens a recent chat from the current repository, with its history, so you don’t have to explain the task again.
5. Run it from scripts with codex exec
codex exec runs Codex without the interactive UI, which is how you use it from repeatable workflows and pipelines:
codex exec "update the changelog for the commits since the last tag"
Keep scripted tasks narrow, with a clear definition of done, and review what they change before it merges.
6. Add MCP servers
Codex calls tools outside your repository through the Model Context Protocol. Each server is a [mcp_servers.<name>] table in ~/.codex/config.toml, or in a trusted project’s .codex/config.toml.
A local server needs the command that starts it:
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
A remote server needs a url. If it takes a bearer token, name the environment variable that holds it with bearer_token_env_var:
[mcp_servers.praxen]
url = "https://mcp.getpraxen.app/mcp"
You can also add servers from the command line with codex mcp add. For a server that uses OAuth, finish the sign-in with:
codex mcp login praxen
Production is the context Codex usually lacks: it can read the code that failed, but not the logs, traces and deploys that show how. Praxen Inc. gives Codex that context through the one remote server above, covering every provider you connect.
Using Codex? See how to give Codex production context with Praxen Inc..
Common questions.
How do I sign in to Codex CLI?
Run codex in a project directory. The first time, it asks you to sign in, and you can choose Sign in with ChatGPT.
Where does Codex read project instructions from?
From AGENTS.md. Run /init inside Codex to create one with instructions for your repository, then edit it and commit it.
How do I run Codex without the interactive UI?
Use codex exec. It is the entry point for repeatable workflows and pipelines, such as a CI job.
Where is Codex's config file?
~/.codex/config.toml by default. A trusted project can also have its own .codex/config.toml.
How do I connect Codex to an MCP server that uses OAuth?
Add the server with its URL, then run codex mcp login with the server's name to complete the sign-in.
About the author
Founder of Praxen Inc.
More in this series
Using coding agents: Claude Code, Cursor, Codex and more
- 1 How to use Claude Code: a practical guide
- 2 How to add MCP servers to Cursor
- 3 How to use Codex CLI: install, AGENTS.md, MCP and exec
- 4 How to use OpenCode: install, plan and build, MCP
- 5 How to add MCP servers to GitHub Copilot in VS Code
- 6 How to use the Pi coding agent
Related
- How to correlate incidents with deploys using evidence Learn how to correlate incidents with deploys using release markers, metrics, logs and verified GitHub, Vercel, Cloudflare and Kubernetes change events.
- What is change intelligence? A production safety guide What is change intelligence? Learn how deploys, config, flags, infrastructure and dependency changes connect to incidents, using tools you already have.
- Turn your app into a context graph Agents that run software need a context graph of the app: every resource, what it connects to, the repository that deploys it and the team that owns it. How we built one on Durable Objects, keep it fresh across every provider without polling AWS, decide what counts as a change, and delete from it safely.
- How to use Claude Code to debug production issues Debug production issues with Claude Code: get logs and traces into the session, test hypotheses against evidence, stay read-only and ship a verified fix.
- Is it safe to give an AI SRE read access to production? Read access for an AI SRE is a sound first step if you scope it. The risks are secrets, customer data and exfiltration. Here are the controls and a checklist.