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.polylane]
url = "https://mcp.polylane.com/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 polylane
Production is the context Codex usually lacks: it can read the code that failed, but not the logs, traces and deploys that show how. Polylane 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 Polylane.
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.
Boris Tane is the founder of Polylane. He previously founded Baselime, observability for the future of the cloud, which Cloudflare acquired. At Cloudflare he built and led the Workers observability team.
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
- PlanetScale MCP Server: Setup and Production Permissions Connect the official PlanetScale MCP Server to Claude Code, Cursor and Codex. Set narrow permissions, inspect Insights and review writes before execution.
- Railway activity feed filters and cron jobs in the CLI Railway's 16 October 2026 update: filter the activity feed by service, list and trigger cron runs with railway cron, and migrate railway.json to IaC.
- Cloudflare Tunnel: 50,000 routes and Tunnels for Platforms Cloudflare raised Tunnel routes to 50,000 per account on 16 October 2026 and launched Tunnels for Platforms at $4.50 a tunnel. Limits, setup and gotchas.
- How to deploy Vite apps to Cloudflare with Void Void, announced by Cloudflare on 15 October 2026, deploys Vite apps to Workers in one command. Setup steps, secrets, migrations, CI and the gotchas.
- CloudWatch log centralisation: GovCloud and 13 new Regions AWS added CloudWatch log centralisation to GovCloud (US) and 13 commercial Regions on 16 October 2026. Setup steps, pricing, limits and gotchas.