Skip to main content
OpenAI’s Codex CLI is the same coding agent that powers ChatGPT’s Codex. You can run this coding agent entirely on Azure infrastructure while keeping your data inside your compliance boundary. You get the added advantages of enterprise-grade security, private networking, role-based access control, and predictable cost management. Codex is more than a chat with your code agent – it’s an asynchronous coding agent that you can trigger from your terminal, VS Code, or from a GitHub Actions runner. Codex enables you to automatically open pull requests, refactor files, and write tests by using the credentials of your Foundry project and Azure OpenAI deployments.

Prerequisites

Deploy a model in Foundry

  1. Go to Foundry and create a new project.
  2. From the model catalog select a reasoning model such as gpt-5.3-codex, gpt-5.2-codex,gpt-5.1-codex-max, gpt-5.1-codex, gpt-5.1-codex-mini, gpt-5-codex, gpt-5, gpt-5-mini, or gpt-5-nano.
  3. To deploy the model from the model catalog, select Use this model. If you’re using the Azure OpenAI Deployments pane, select deploy model.
  4. Copy the endpoint URL and the API Key.

Install the Codex CLI

From the terminal, run the following commands to install Codex CLI

Create and configure config.toml

  1. To use Codex CLI with Azure, create and set up a config.toml file. Store the config.toml file in the ~/.codex directory. Create a config.toml file inside this directory or edit the existing file if it already exists:
  2. Copy the following text to use the v1 Responses API. With the v1 API you no longer need to pass api-version, but you must include /v1 in the base_url path. You can’t pass your API key as a string directly to env_key. env_key must point to an environment variable. Update your base_url with your resource name:
  3. After you save the updates to your config.toml file, return to the terminal and create an instance of the environment variable that the config file references.
  4. Run one of the following commands in the terminal to test if your Codex CLI configuration was successful:

Use Codex in Visual Studio Code

You can also use Codex directly inside Visual Studio Code when using the OpenAI Codex extension.
  1. If you don’t already have Visual Studio Code, install it for macOS and Linux.
  2. Install the OpenAI Codex extension. The extension relies on your config.toml file that you configured for Codex CLI.
  3. If you’re in a new terminal session, set up the environment variable for AZURE_OPENAI_API_KEY:
If you use WSL, also set the same environment variable on the Windows host so the extension can read it when needed.
  1. Launch VS Code from the same terminal session. (Launching from an app launcher can result in your API key environment variable not being available to the Codex extension.)
  2. You can now use Codex in Visual Studio Code to chat, edit, and preview changes while toggling between three approval modes.

Approval modes

Approval modes determine how much autonomy and interaction you want to have with Codex.
We recommend reviewing OpenAI’s guidance on Codex security.

Persistent guidance with AGENTS.md

You can give Codex extra instructions and guidance by using AGENTS.md files. Codex looks for AGENTS.md files in the following places and merges them top-down, giving it context about your personal preferences, project-specific details, and the current task:
  • ~/.codex/AGENTS.md – personal global guidance.
  • AGENTS.md at your repository’s root – shared project notes.
  • AGENTS.md in the current working directory – subfolder or feature specifics.
For example, to help Codex understand how to write code for Foundry Agents, you could create an AGENTS.md in your project root with the following content, derived from the Azure AI Agents SDK documentation:
In the previous example, backticks in the Python code block are escaped to allow proper rendering. You can remove the \ characters.

Experiment with Codex CLI

Launch codex with the following initial prompt:
Other suggested tests:

Codex in GitHub Actions

Codex can execute as part of your continuous integration (CI) pipeline. Store your API key in the repository’s secret store as AZURE_OPENAI_KEY and add a job like this to automatically update your changelog before a release:

Troubleshooting