# Codex CLI (Mac/Linux)

> Install and configure the Codex CLI on Mac / Linux to connect to the LMU AI API, including how to enable the 1M-token long context in config.toml.

URL: https://docs.lmuai.ai/docs/tools/codex-cli-mac





After installing the Codex CLI, create two config files by hand (`config.toml` + `auth.json`) to connect to the LMU AI API — no third-party config tool needed.

***

## Step 1 — Install Node.js [#step-1--install-nodejs]

You need &#x2A;*Node.js 20+** — download: [https://nodejs.org/en/download](https://nodejs.org/en/download)

Click through the installer, then verify in the terminal:

```bash
node --version
# A version number (e.g. v23.7.0) means it installed correctly
```

## Step 2 — Install the Codex CLI [#step-2--install-the-codex-cli]

```bash
npm i -g @openai/codex
```

If you hit network issues, switch to a China mirror first:

```bash
npm config set registry https://registry.npmmirror.com
npm i -g @openai/codex
```

Verify the install:

```bash
codex --version
# A version number means it installed correctly
```

## Step 3 — Create the config files [#step-3--create-the-config-files]

The config directory is &#x2A;*`~/.codex/`** (create it if missing; overwrite any old files). Create/overwrite these two files in it:

### config.toml [#configtoml]

```toml
model = "gpt-5.4"
model_reasoning_effort = "xhigh"
disable_response_storage = true
sandbox_mode = "danger-full-access"
windows_wsl_setup_acknowledged = true
approval_policy = "never"
file_opener = "vscode"
model_provider = "codex"
web_search = "cached"
suppress_unstable_features_warning = true

[history]
persistence = "save-all"

[tui]
notifications = true

[shell_environment_policy]
inherit = "all"
ignore_default_excludes = false

[sandbox_workspace_write]
network_access = true

[features]
plan_tool = true
apply_patch_freeform = true
view_image_tool = true
unified_exec = false
streamable_shell = false
rmcp_client = true
elevated_windows_sandbox = true

[profiles.auto-max]
approval_policy = "never"
sandbox_mode = "workspace-write"

[profiles.review]
approval_policy = "on-request"
sandbox_mode = "workspace-write"

[notice]
hide_gpt5_1_migration_prompt = true

[model_providers.codex]
name = "codex"
base_url = "https://api.lmuai.ai"
wire_api = "responses"
requires_openai_auth = true
```

### auth.json [#authjson]

```json
{
  "OPENAI_API_KEY": "your sk- key generated in the console"
}
```

## Step 4 — Launch the Codex CLI [#step-4--launch-the-codex-cli]

After saving the config files, reopen the terminal and run the following to launch and sign in automatically:

```bash
codex --dangerously-bypass-approvals-and-sandbox
```

Or the short form:

```bash
codex --yolo
```

> This launch command skips security approvals, so you do not approve each auto-executed step.

On a successful launch, the interface shows the current model as `gpt-5.4 xhigh` (the model set by the `model` field in `config.toml`).

<Callout type="info" title="About switching models">
  If you accidentally switch to a different model in a session, change the `model` field in `~/.codex/config.toml` back to `gpt-5.4` and restart the terminal to restore it.
</Callout>

***

## Enabling the 1M context in Codex (optional) [#enabling-the-1m-context-in-codex-optional]

`gpt-5.4` supports a **1M-token long context window** (272K by default), useful for large-repo review, long-log analysis, and cross-file refactors. Codex does **not** enable the 1M window by default; you must declare it explicitly in `config.toml`.

### How to configure: add two lines to config.toml [#how-to-configure-add-two-lines-to-configtoml]

Edit `~/.codex/config.toml` and add the following at the **top level** (before any `[section]`, e.g. right after `model = "gpt-5.4"`):

```toml
model_context_window = 1000000
model_auto_compact_token_limit = 900000
```

Save, reopen the terminal, and re-enter Codex to apply it.

**Field reference**

| Field                            | Purpose                                                                                                                                                                                                 |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model_context_window`           | Declares the model's usable context window in tokens; `1000000` is 1M. Unset, it uses the model default (272K)                                                                                          |
| `model_auto_compact_token_limit` | The token threshold that triggers auto-compaction of history; set it to about 90% of the window (`900000` for 1M). Values above 90% of the window are clamped by Codex, so a larger number is pointless |

### Verify it took effect [#verify-it-took-effect]

After re-entering Codex, type `/status` and check whether `context window` shows around 1M (some versions show about 950K — a reserved 5% safety margin from Codex). You can also use `/statusline` to add context usage to the status bar for live monitoring.

### If you use CC Switch [#if-you-use-cc-switch]

If you manage the Codex config with [CC Switch](/docs/tools/cc-switch), add the same two lines in its Codex config editor and apply — the effect is identical:

<img alt="Setting model_context_window = 1000000 and model_auto_compact_token_limit = 900000 for the Codex config in CC Switch to enable the 1M-token long context" src="__img0" />

<Callout type="warn" title="Usage notes">
  * **Must be at the top level**: these two fields do not take effect inside a `[profiles.xxx]` section (a known Codex limitation); also put them in the user-level `~/.codex/config.toml`, since a project-level `.codex/config.toml` may be ignored
  * **Model support**: `gpt-5.4` and `gpt-5.5` support 1M over the API channel; models like `gpt-5.3-codex` are capped at 272K, and no config value can exceed the model's own limit
  * **Higher cost**: a longer context uses more tokens per request; the portion above 272K is billed at the higher long-context tier, so do not leave it on for anything but very long tasks
  * **Version differences**: some newer Codex versions read the window size from the model catalog first; if `/status` still shows the old value, upgrade to the latest (`npm i -g @openai/codex@latest`) and retry
</Callout>
