> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex with MDM

> Configure Codex CLI and the Codex desktop app through MDM: models, Windows enforcement, ChatGPT subscriptions, and how to verify the TrueFoundry AI Gateway setup.

This page covers the Codex-specific parts of an MDM rollout. Start with the [MDM overview](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md) to create the deployment script, then use these options in its TOML block. Every field is listed in the [configuration reference](https://www.truefoundry.com/docs/ai-gateway/mdm/configuration-reference.md#fields).

One configuration covers both the Codex CLI and the Codex desktop app, on macOS, Linux, and Windows.

## What gets written

| Platform | File | Precedence |
| - | - | - |
| macOS, Linux | `/etc/codex/managed_config.toml` | Overrides the employee's `~/.codex/config.toml` and is reapplied on every launch |
| Windows | `C:\ProgramData\OpenAI\Codex\requirements.toml` | Enforced; overrides the employee's config. Requires Codex 0.156.0 or later |
| Windows | `C:\ProgramData\OpenAI\Codex\config.toml` | Machine defaults, including MCP servers. Lowest precedence |

The binary writes a `truefoundry` model provider that points at your gateway with `wire_api = "responses"`, the employee's sign-in, your default model, and gateway MCP servers, and locks each file. For the Windows file permissions, see [Windows enforcement](#windows-enforcement). Sign-in depends on the [method you chose](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md#choose-how-employees-sign-in):

| Method | What is written |
| - | - |
| Device login | `[model_providers.truefoundry.http_headers]` with `Authorization = "Bearer <token>"`, refreshed on every run |
| OIDC | `[model_providers.truefoundry.auth]` with a `command` that runs the binary with `--_print-oidc-token`. No token is stored; Codex asks the binary when it needs one |
| ChatGPT subscription | `x-tfy-api-key = "<token>"` and `requires_openai_auth = true`. See [Use a ChatGPT Business or Enterprise subscription](#use-a-chatgpt-business-or-enterprise-subscription) |

> [accordion] Example: managed\_config.toml on macOS and Linux
>
> With `model = "gpt-5.4"` and `mcp_servers = ["github"]`:
>
> > [tab] Device login
> >
> > ```toml theme={"dark"}
> > model_provider = "truefoundry"
> > model = "gpt-5.4"
> >
> > [model_providers.truefoundry]
> > name     = "TrueFoundry Gateway"
> > base_url = "https://<your-gateway-url>"
> > wire_api = "responses"
> >
> > [model_providers.truefoundry.http_headers]
> > Authorization = "Bearer <employee-token>"
> >
> > [mcp_servers.github]
> > url = "https://<your-gateway-host>/<tenant>/mcp/github/server"
> > ```
>
> > [tab] OIDC
> >
> > ```toml theme={"dark"}
> > model_provider = "truefoundry"
> > model = "gpt-5.4"
> >
> > [model_providers.truefoundry]
> > name     = "TrueFoundry Gateway"
> > base_url = "https://<your-gateway-url>"
> > wire_api = "responses"
> >
> > [model_providers.truefoundry.auth]
> > command = "/usr/local/bin/tfy-local-ai-setup"
> > args = ["--_print-oidc-token", "--oidc-issuer=<issuer>", "--oidc-client-id=<client-id>"]
> > timeout_ms = 300000
> >
> > [mcp_servers.github]
> > url = "https://<your-gateway-host>/<tenant>/mcp/github/server"
> > ```

> [accordion] Example: requirements.toml and config.toml on Windows
>
> `requirements.toml` has no top-level `model` key, so the default model is under `[models.new_thread]`. With device login:
>
> ```toml requirements.toml theme={"dark"}
> model_provider = "truefoundry"
>
> [model_providers.truefoundry]
> name     = "TrueFoundry Gateway"
> base_url = "https://<your-gateway-url>"
> wire_api = "responses"
>
> [model_providers.truefoundry.http_headers]
> Authorization = "Bearer <employee-token>"
>
> [models.new_thread]
> model = "gpt-5.4"
> ```
>
> `config.toml` holds the same provider block with a top-level `model`, and the `[mcp_servers.<name>]` tables. With OIDC, both files have the `[model_providers.truefoundry.auth]` table instead of `http_headers`, with `command` set to `C:\Program Files\TrueFoundry\tfy-local-ai-setup.exe`.

## Choose a model

Codex needs a [Virtual Model whose slug is a bare OpenAI model ID](https://www.truefoundry.com/docs/ai-gateway/openai-codex-cli.md#why-you-need-a-virtual-model), such as `gpt-5.4`, rather than a provider-prefixed ID:

```toml theme={"dark"}
[agents.codex]
model = "gpt-5.4"
```

`model` is required in an `[agents.codex]` table. Because the model is a Virtual Model, you can change its routing or add fallbacks in TrueFoundry without redeploying the script.

## Use a ChatGPT Business or Enterprise subscription

Use this when your organization pays for Codex through ChatGPT seats instead of an OpenAI API key. Codex sends each employee's own ChatGPT credential to OpenAI, and the gateway authenticates the employee separately, so usage is attributed to the employee on both sides.

**1. Create the OpenAI model account**

In TrueFoundry, add an OpenAI model account with the base URL `https://chatgpt.com/backend-api/codex` and an **empty API key**, as described in the ChatGPT tab of [Configure Codex](https://www.truefoundry.com/docs/ai-gateway/openai-codex-cli.md#1-configure-codex). Create a Virtual Model for it or copy its model ID.

> [!WARNING]
>
> Keep the API key empty. If the account has a key, the gateway uses it instead of the employee's ChatGPT credential and bills the wrong account.

**2. Update the Codex table**

```toml theme={"dark"}
[agents.codex]
auth = "api-key"
auth_mode = "chatgpt-subscription"
model = "gpt-5.4"
```

Replace `model` with the Virtual Model or model ID from the previous step. This mode needs device login; it does not work with OIDC.

**3. Tell employees about the two sign-ins**

Employees complete the TrueFoundry sign-in from the MDM run, and sign in to their ChatGPT account the first time they open Codex.

* **Why two headers:** `requires_openai_auth = true` makes Codex send the employee's ChatGPT credential in `Authorization`, so the TrueFoundry credential moves to `x-tfy-api-key`. The gateway reads them separately: `x-tfy-api-key` identifies the employee to TrueFoundry, and the `Authorization` token authenticates the request to OpenAI.
* A Virtual Model can have only **one** ChatGPT subscription target, because each employee's credential is valid for one ChatGPT account. Targets backed by an OpenAI API key can sit alongside it.
* One employee reaching their ChatGPT limit does not affect anyone else's routing.

## Restrict MCP servers

Gateway MCP servers from `mcp_servers` are added alongside servers the employee configures. To allow only approved servers, Codex uses an MCP allowlist in `requirements.toml`, which the binary does not write:

* **macOS and Linux:** deploy `/etc/codex/requirements.toml` with your MDM alongside the script. See OpenAI's [managed configuration](https://learn.chatgpt.com/docs/enterprise/managed-configuration) for the format, and the [MCP example](https://www.truefoundry.com/docs/ai-gateway/openai-codex-cli.md#fleet-wide-enforcement).
* **Windows:** the binary rewrites `requirements.toml` on every run to enforce the gateway, so a separately deployed allowlist in that file is replaced.

## Windows enforcement

On Windows, the binary enforces the gateway through `C:\ProgramData\OpenAI\Codex\requirements.toml`, which overrides the employee's configuration, and writes machine defaults, including MCP servers, to `config.toml` in the same directory. Codex applies them in this order:

```text theme={"dark"}
requirements.toml          ← written by MDM, enforced, highest priority
  └── ~/.codex/config.toml   ← the employee's own settings
        └── config.toml        ← written by MDM, machine defaults, lowest priority
```

> [!WARNING]
>
> **On Windows, enforcement requires Codex 0.156.0 or later.** Older versions ignore the provider in `requirements.toml` and use only `config.toml`, which an employee can override in their own configuration. Check `codex --version` across your fleet.

The binary locks these files so that only administrators can change them:

* `requirements.toml` and `config.toml` give SYSTEM full control and Administrators and Users read-only access. Inherited permissions are removed.
* The `C:\ProgramData\OpenAI\Codex` directory is owned by Administrators, with inherited permissions removed. SYSTEM and Administrators have full control, and Users can read and run but not create, replace, or delete files in it. Codex loads any configuration it finds in that directory, so do not relax this permission.

Windows Codex no longer reads `managed_config.toml`. A copy left in `%USERPROFILE%\.codex` by an older setup only produces a warning; delete it.

## Windows Subsystem for Linux

To configure Codex inside WSL, see [Windows Subsystem for Linux](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md#windows-subsystem-for-linux) in the overview.

## Data retention

For OpenAI-side retention and what the gateway logs, see [Data retention](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md#data-retention) in the overview.

## Verify the deployment

After the [lock check and test request](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md#deploy-to-a-pilot-device) on the pilot device:

1. **Check the sign-in block.** With device login, look for `Authorization = "Bearer ...` under `[model_providers.truefoundry.http_headers]`. With OIDC, look for `[model_providers.truefoundry.auth]` with `--_print-oidc-token` and no token. On Windows, the default model is under `[models.new_thread]`.
2. **Check the version on Windows.** `codex --version` must be 0.156.0 or later for enforcement.

```bash macOS and Linux theme={"dark"}
cat /etc/codex/managed_config.toml
```

```powershell Windows theme={"dark"}
Get-Content C:\ProgramData\OpenAI\Codex\requirements.toml
Get-Content C:\ProgramData\OpenAI\Codex\config.toml
codex --version   # 0.156.0 or later for enforcement
```

## Troubleshooting

| Symptom | Likely cause | Fix |
| - | - | - |
| Codex prints `Ignoring deprecated managed config file` on Windows | A `managed_config.toml` from an older setup is in `%USERPROFILE%\.codex` | Delete it. Windows Codex no longer reads that file |
| An employee moved Codex off the gateway on Windows | Codex is older than 0.156.0, so only `config.toml` applies | Update Codex |
| Model errors on every request | `model` is a provider-prefixed ID instead of a Virtual Model with a bare OpenAI slug | [Use a Virtual Model](#choose-a-model) |
| `401` or `403` with a ChatGPT subscription | The ChatGPT session or the TrueFoundry sign-in expired | If the ChatGPT session expired, the employee runs `codex` and signs in again. If the TrueFoundry sign-in expired, trigger the MDM script again |
| Codex prompts to trust a hook | You deployed [prompt blocking](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md#block-an-agent) | The employee reviews the hook in `/hooks` |

For issues that affect every agent, see [Troubleshooting](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md#troubleshooting) in the overview.

## Related

* [Codex integration](https://www.truefoundry.com/docs/ai-gateway/openai-codex-cli.md): manual configuration, Virtual Models, and web search
* [Set up OIDC sign-in](https://www.truefoundry.com/docs/ai-gateway/mdm-setup.md#set-up-oidc-sign-in): the public OIDC client that Claude Code, Codex, and Claude Desktop share
* [Claude Code and Claude Desktop with MDM](https://www.truefoundry.com/docs/ai-gateway/mdm/claude.md): policy, MCP allowlist, models, and Desktop preferences
* [Configuration reference](https://www.truefoundry.com/docs/ai-gateway/mdm/configuration-reference.md): every `mdm.toml` field, CLI flag, and file path


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.