Step one
All four surfaces run the same Codex agent; they differ in where they run, which files they can reach and how you sign in. The CLI and the IDE extension read the same ~/.codex/config.toml and the same login cache, so signing in once covers both.
If your data lives only on your computer or a lab server, use the CLI or the IDE extension. Codex Cloud tasks can only reach repositories and services in the cloud environment; local files, browser sign-ins and VPN access are not transferred, and large raw datasets do not belong in a GitHub repository.
On a lab server, get the CLI working on the server first, then set up the IDE extension over Remote-SSH. The CLI verifies proxy, certificates and login on its own, which makes extension problems easier to locate.
The Free and Go plans can use GPT-6 Luna in the desktop app only (rolling out). From Plus ($20 per month) Codex is available on the web, in the CLI, in the IDE extension and on iOS, including GPT-6.1 Sol.
| Surface | How to install | Where it runs | Sign-in | Best for |
|---|---|---|---|---|
| Codex CLI | install.sh / PowerShell script, npm, Homebrew | Local terminal; also on servers you reach over SSH | ChatGPT account or API key | Lab servers, scripted batch runs, precise permission control |
| IDE extension | Search openai.chatgpt in the VS Code / Cursor / Windsurf marketplace; in JetBrains, choose Codex in AI Assistant's AI Chat | Local machine or a Remote-SSH server | ChatGPT account or API key | Editing alongside the code and reviewing diffs |
| ChatGPT desktop app | chatgpt.com/download (macOS, Windows); separate Linux instructions | Local; choose Local, Worktree or Cloud | ChatGPT account or API key | Several projects in parallel, previewing figures and files |
| Codex Cloud | In ChatGPT web, desktop or mobile, choose Work in > Cloud | OpenAI-managed cloud containers; you first create an environment and connect GitHub repositories | ChatGPT account only | Code hosted on GitHub, tasks that must continue after you shut down |
Install
The official documentation lists four install methods; each uses the same command to update. After installing, run codex --version and codex doctor to confirm the binary, configuration, login and network.
# macOS / Linux: official installer (same command installs and updates)
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# Windows: run in a new PowerShell window
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
# npm (Node 16+; in mainland China you can add --registry=https://registry.npmmirror.com)
npm install -g @openai/codex
# Homebrew
brew install --cask codex # update: brew upgrade --cask codex
# Verify
codex --version # version checked on this page: codex-cli 0.162.1
codex doctor --summary # checks install, config, auth, network and sandbox| Symptom | Cause | Fix |
|---|---|---|
| Running codex prints Missing optional dependency @openai/codex-darwin-arm64 (or linux-x64, etc.) | The npm package is only a launcher; the program ships in per-platform optional dependencies. When that download fails, npm logs reify failed optional dependency and still reports success | Reinstall; on an unstable network add --registry=https://registry.npmmirror.com, or use the official installer / Homebrew |
| npm install takes over ten minutes | Platform packages are large: the 0.162.1 darwin-arm64 package is 136.6 MB compressed and 323 MB unpacked | Use a mirror or the official installer |
| Sandboxed commands fail in WSL1 | Since 0.115 the Linux sandbox uses bubblewrap; WSL1 was supported through 0.114 | Upgrade with wsl --set-version <distro> 2 |
| Garbled terminal or no start on Windows 10 | Codex needs ConPTY; Windows 10 1809 or newer is required and Windows 11 is recommended | Update Windows or run inside WSL2 |
| codex update says it cannot self-update | codex update only works for installs that support self-update | Update with the method you installed with (npm reinstall, brew upgrade, rerun the installer) |
Sign in
Both methods work in the local CLI, IDE extension and desktop app. The choice depends on whether you want to use plan allowances or pay per token, and whether you need Codex Cloud.
Credentials are cached in ~/.codex/auth.json or the OS keychain, controlled by cli_auth_credentials_store (file / keyring / auto / ephemeral). The CLI and IDE extension share this cache; signing out in one signs out both.
Device code sign-in must first be enabled in your ChatGPT security settings (for workspace accounts, by the admin in workspace permissions). If sign-in fails, check codex-login.log in the log directory.
In mainland China, the practical requirements are a stable international connection and a ChatGPT account or an OpenAI API key. Use HTTP proxy variables: a Windows user reported that ChatGPT backend disconnects stopped after switching SOCKS5 proxy variables to HTTP proxy variables and setting NO_PROXY (GitHub #20844). A third-party gateway must support the Responses protocol; services that only offer Chat Completions cannot be connected to the current version. For a comparison of official plans, API relays and domestic models, see /compare/codex-claude-code-china.
codex login # browser sign-in with a ChatGPT account
codex login --device-auth # device code: servers and machines without a browser
printenv OPENAI_API_KEY | codex login --with-api-key # API key sign-in
codex login status # exits 0 when signed in; prints Not logged in and exits 1 otherwise
codex logout
# Headless server without device code: forward the callback port, then sign in
ssh -L 1455:localhost:1455 user@server
codex login # open the printed URL in your local browser
# Or copy your local login cache (treat auth.json like a password)
ssh user@server 'mkdir -p ~/.codex && cat > ~/.codex/auth.json' < ~/.codex/auth.json# Linux / macOS terminal: use HTTP proxy variables and keep local addresses direct
export HTTPS_PROXY=http://127.0.0.1:7890
export HTTP_PROXY=http://127.0.0.1:7890
export NO_PROXY=localhost,127.0.0.1,::1
# On macOS the ChatGPT desktop app launched from the Dock ignores shell variables; set them in launchd and restart the app
launchctl setenv HTTPS_PROXY http://127.0.0.1:7890
launchctl setenv HTTP_PROXY http://127.0.0.1:7890
# Corporate proxy or private root CA
export CODEX_CA_CERTIFICATE=/path/to/root-ca.pem # falls back to SSL_CERT_FILE when unset
# Change only the address of the built-in OpenAI provider (no new provider), in ~/.codex/config.toml
openai_base_url = "https://gateway.example.com/v1"| Item | ChatGPT account | API key |
|---|---|---|
| Billing | Uses your ChatGPT plan allowance; Plus and Pro can buy extra credits | Charged to your OpenAI Platform account at standard API rates |
| Models | Depends on the plan; from Plus, GPT-6.1 Sol and GPT-6 Luna | Whatever models the key can access in the API |
| Codex Cloud, GitHub code review, Slack | Available | Not available |
| Best for | Daily interactive use | CI, scheduled scripts, extra usage after the plan allowance runs out |
| In automation | Maintain auth.json on a trusted machine | Set CODEX_API_KEY only for the Codex command, not as a job-wide variable |
Configuration
Settings apply in this order, earlier entries overriding later ones: command-line flags and -c overrides → project .codex/config.toml files (from the project root down to the current directory, closest wins, trusted projects only) → ~/.codex/<name>.config.toml selected with --profile → ~/.codex/config.toml → system /etc/codex/config.toml → built-in defaults.
# ~/.codex/config.toml (validated with --strict-config on Codex CLI 0.162.1)
# Root keys must come before the first [table]; after a table they become fields of that table and are ignored
model = "gpt-6.1-sol" # switch to gpt-6-luna if your account lacks access
model_reasoning_effort = "medium" # low / medium / high / xhigh, depending on the model
approval_policy = "on-request" # only on-request and never are accepted
sandbox_mode = "workspace-write" # read-only / workspace-write / danger-full-access
web_search = "cached" # cached (default) / live / indexed / disabled
file_opener = "vscode" # makes file paths in output clickable
project_doc_max_bytes = 65536 # combined AGENTS.md limit, default 32768
[sandbox_workspace_write]
network_access = false # set to true when pip/conda need the network
writable_roots = [] # extra writable directories, e.g. ["/Users/me/scratch"]
[history]
persistence = "save-all" # "none" keeps no local session history
# MCP: local stdio server
[mcp_servers.papers]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/papers"]
startup_timeout_sec = 20 # default 10
tool_timeout_sec = 60 # default 60
# MCP: remote HTTP server, disabled for now
[mcp_servers.context7]
url = "https://mcp.context7.com/mcp"
bearer_token_env_var = "CONTEXT7_API_KEY"
enabled = false
# Custom model gateway (Responses protocol only)
[model_providers.mygateway]
name = "My OpenAI-compatible gateway"
base_url = "https://gateway.example.com/v1"
env_key = "MYGATEWAY_API_KEY" # the variable name, not the key itself
wire_api = "responses"
request_max_retries = 4
stream_idle_timeout_ms = 300000
# Trust a project so its .codex/config.toml is loaded
[projects."/Users/me/research/rnaseq-2026"]
trust_level = "trusted"# ~/.codex/gateway.config.toml -- codex -p gateway
model_provider = "mygateway"
model = "gpt-6.1-sol"
# ~/.codex/deep.config.toml -- codex -p deep
model_reasoning_effort = "high"
# One-off overrides; values are parsed as TOML, so strings need quotes
codex -c model_reasoning_effort='"high"' -s read-only
codex exec -p deep "Review the statistics in scripts/02_model.py"| Setting | Values and defaults | When to change it |
|---|---|---|
| model | A model ID your account can use, e.g. gpt-6.1-sol or gpt-6-luna; unset defaults to gpt-6.1-sol in 0.162.1 | Use gpt-6-luna if you lack access or want to save allowance. GPT-5.5 retires from Codex with ChatGPT sign-in on 2026-10-14, so configs that pin gpt-5.5 need a new model |
| model_reasoning_effort | low / medium / high / xhigh and so on, depending on the model | high for deriving statistical methods or hard debugging; low for bulk formatting. Higher levels take longer and use more allowance |
| approval_policy | on-request, never, or { granular = {...} } | on-request for interactive work; codex exec always uses never |
| sandbox_mode | read-only / workspace-write / danger-full-access | read-only to inspect code; workspace-write to run analyses and edit scripts |
| [sandbox_workspace_write] | network_access defaults to false; writable_roots adds writable directories | Enable network_access to install packages; add writable_roots when results must go outside the project |
| model_provider + [model_providers.<id>] | base_url, env_key (variable name), wire_api (responses only), http_headers, request_max_retries, stream_idle_timeout_ms, etc. | For a company gateway, Azure, Bedrock or local Ollama. To change only the address, use top-level openai_base_url |
| --profile and <name>.config.toml | Since 0.134.0 each profile is a separate file with top-level keys | Switching between "daily", "high reasoning" and "via gateway" |
| [mcp_servers.<id>] | stdio: command, args, env; HTTP: url, bearer_token_env_var; common: startup_timeout_sec (default 10), tool_timeout_sec (default 60), enabled, required, enabled_tools / disabled_tools | To connect literature libraries, databases or browsers. Every MCP server consumes context and allowance; set enabled = false when unused |
| project_doc_max_bytes | Default 32768 bytes | Raise it when AGENTS.md exceeds 32 KiB in total; splitting into subdirectories is better |
| [projects."<path>"] trust_level | trusted / untrusted | Load a project's .codex/config.toml, or require approval for every command in a project |
- After editing, run codex exec --strict-config "hi": fields this version does not recognize produce unknown configuration field with the line number; a valid config starts running normally (and then returns 401 if you are not signed in).
- The config item in codex doctor --all lists ignored fields, for example Codex is ignoring 2 unrecognized configuration settings.
- In an interactive session, /status shows the active model, approval policy, writable roots and remaining context; /debug-config shows which file each config layer comes from.
- A project .codex/config.toml cannot set model_provider, model_providers, openai_base_url, profile and similar keys; they are ignored with a startup warning.
- codex mcp add <name> -- <command> or codex mcp add <name> --url <url> writes to config.toml; codex mcp list shows configured servers and whether they are enabled.
Version changes
The Codex CLI changes quickly, and many settings from tutorials written in 2025 and early 2026 no longer work. Every error message below was triggered on this page with Codex CLI 0.162.1.
| Old setting | Behavior in 0.162.1 | Fix |
|---|---|---|
| approval_policy = "untrusted" | Fails to start: approval_policy = "untrusted" is no longer supported; remove this setting | Delete it and use on-request; to require approval for every command, set trust_level = "untrusted" under [projects."<path>"] |
| codex -a untrusted or -a on-failure | invalid value ... [possible values: on-request, never] | Use -a on-request |
| profile = "fast" plus [profiles.fast] | legacy `profile = "fast"` config is no longer supported; use `--profile fast` with `fast.config.toml` instead | Move the keys under [profiles.fast] into ~/.codex/fast.config.toml as top-level keys, then delete the table and the profile line |
| Only a [profiles.fast] table, then codex -p fast | --profile `fast` cannot be used while ... config.toml contains legacy ... config | Same as above |
| wire_api = "chat" | `wire_api = "chat"` is no longer supported. How to fix: set `wire_api = "responses"` | Use responses; if the upstream only supports Chat Completions, switch to a gateway that supports Responses |
| Changing base_url under [model_providers.openai] | model_providers contains reserved built-in provider IDs: `openai` | Remove the table and use top-level openai_base_url, or pick another custom ID |
| codex exec --full-auto | error: unexpected argument '--full-auto' found (the docs still say it prints a deprecation warning; 0.162.1 rejects it) | Use codex exec --sandbox workspace-write |
| model = gpt-6.1-sol (unquoted) | string values must be quoted | Put strings in double quotes |
| args = ["C:\Users\me\data"] | too few unicode value digits (\U is read as an escape) | Use a single-quoted literal 'C:\Users\me\data' or forward slashes C:/Users/me/data |
| model placed after a table such as [sandbox_workspace_write] | No error, the model setting has no effect; with --strict-config: unknown configuration field `sandbox_workspace_write.model` | Move all root keys above the first [table] |
| Typos such as model_reasoning_efort; type = "stdio" copied from Claude Code MCP configs | No error, the field is ignored; doctor shows `mcp_servers.x.type` is ignored | Delete or correct it; Codex infers the type from command or url |
AGENTS.md
AGENTS.md is a plain Markdown file that Codex reads at the start of every session and places in the first turn's context. Use it for rules that hold for the whole project: directory conventions, run commands, files that must not change and what counts as done.
This page used codex debug prompt-input to view what is actually injected into the model (Codex CLI 0.162.1, no login needed). Started at the project root, only the global file and the root AGENTS.md were loaded; AGENTS.md files in subdirectories such as analysis/ were not. Started in analysis/deseq/, all four files on the path were loaded; when analysis/ also contained AGENTS.override.md, only the override was used for that directory. After growing the root AGENTS.md to 40 KB, the root file was truncated under the default limit and the rules from analysis/ and deseq/ did not reach the context.
So rules specific to a subdirectory only apply when you start Codex in that subdirectory (codex -C analysis/deseq). Rules that must always apply belong in the root file, which should stay short.
/init writes a draft AGENTS.md in the current directory; trim it to the essential rules before committing. ETH Zürich's evaluation of AGENTS.md (arXiv 2602.11988, ICLR 2026) found that on SWE-bench and similar coding tasks, context files slightly reduced task success overall while raising inference cost by more than 20%; agents follow the instructions faithfully, so unnecessary requirements make tasks harder. The authors recommend human-written files with only minimal requirements. The official pricing documentation also lists "reduce the size of your AGENTS.md" as a way to make usage last longer.
To check which files were loaded, ask "list the instruction files you loaded" in a session, or start with codex -c log_dir=./.codex-log and read codex-tui.log.
# AGENTS.md (at the root of the project repository)
## Directory conventions
- data/raw/: raw data, read-only. Do not modify, move, overwrite or re-encode.
- data/processed/: generated from data/raw by scripts in scripts/; can be deleted and rebuilt.
- scripts/: numbered (01_qc.py, 02_model.R); each script reads only the previous step's output.
- results/<date>_<label>/: one directory per run, holding figures, tables and logs.
## Run requirements
- Environment: conda env rnaseq-2026 (environment.yml). Report missing packages first; do not upgrade existing ones.
- Fix random seeds to 20261010 and record them in the run log.
- Each run writes RUN.md in its results directory: commands, input files with md5, software and package versions, parameters, runtime, list of outputs.
- For statistical tests, state the test, the multiple-testing correction and the thresholds; do not change thresholds mid-run.
## Scope of changes
- Only modify scripts/ and results/. Before changing shared functions, list the scripts affected.
- When results differ from expectations, report the difference; do not change thresholds or drop samples to make results look better.
## Definition of done
- Scripts reproduce the same results from a clean data/processed.
- The reply lists changed files and what I need to check by hand.- 01
Global layer
If ~/.codex/AGENTS.override.md exists Codex reads only that file; otherwise it reads ~/.codex/AGENTS.md. Put cross-project personal habits here, such as reply language or preferred package manager.
- 02
Project layer
From the project root (by default the directory containing .git; change with project_root_markers) down to the directory where you start Codex, each directory is checked for AGENTS.override.md, AGENTS.md and names in project_doc_fallback_filenames, taking at most one file per directory.
- 03
Merge
Files are concatenated in the order global → root → current directory. Files closer to the current directory come later and take precedence on conflicts. Empty files are skipped.
- 04
Limit
Once the combined size exceeds project_doc_max_bytes (32 KiB by default), content is truncated and files deeper in the path are dropped entirely.
Commands
Compiled from codex --help and the official Developer commands documentation; only everyday commands are listed.
/model, /fast, /personality
Switch model and reasoning level, toggle the Fast tier, set the reply style.
/permissions
Switch between Auto (workspace writable) and Read Only mid-session, and view the active sandbox and writable roots.
/status, /debug-config
Show the active model, approval policy, writable roots and remaining context; show where each config layer comes from.
/compact, /new, /clear
Summarize history to free context; start a new chat in the same terminal; clear the screen and start fresh.
/diff, /review
Show the git diff including untracked files; ask Codex to review current changes.
/plan, /goal
Get an execution plan before any edits; set a persistent goal for a long task.
/init, /mention, /mcp
Generate a draft AGENTS.md; attach specific files; list available MCP tools.
/resume, /fork, /rename
Resume a saved chat, fork the current one, rename a session so you can find it later.
/ps, /stop
Show background terminals and their output; stop all background terminals. Long-running analysis scripts show up here.
Shortcuts
@ searches files and inserts the path; a line starting with ! runs a shell command; while Codex works, Enter injects new instructions and Tab queues them for the next turn; Esc twice on an empty composer edits the previous message and forks from there; Ctrl+R searches prompt history; Ctrl+O copies the latest output.
| Command | Purpose | Common options |
|---|---|---|
| codex [prompt] | Start an interactive session in the current directory | -m model, -s sandbox, -a approval, -C working directory, --add-dir extra writable directory, -i image, --search live web search, -p profile |
| codex exec (alias e) | Non-interactive run for scripts | -o write final reply, --json, --output-schema, --ephemeral, --skip-git-repo-check, --ignore-user-config |
| codex resume / codex fork | Resume or copy a previous session | --last, --all, session ID or name |
| codex review | Review uncommitted changes, a commit or a branch | Also /review inside a session |
| codex apply (alias a) | Apply a Codex Cloud task's diff locally with git apply | |
| codex mcp add / list / get / remove / login | Manage MCP servers | --url, --bearer-token-env-var, --env |
| codex login / logout | Sign in and out | --device-auth, --with-api-key, status |
| codex doctor | Check install, config, auth, network and sandbox | --summary, --all, --json |
| codex sandbox | Run any command inside Codex's sandbox to test permission settings | -P permission profile, -C directory |
| codex features list / enable / disable | Inspect and toggle feature flags | |
| codex completion | Generate bash / zsh / fish completions |
Non-interactive and sessions
codex exec runs one task and exits. Progress goes to stderr and only the final reply goes to stdout, so you can redirect or pipe it. Three defaults differ from interactive mode; confirm them before writing scripts.
Session records are stored under ~/.codex/sessions. codex resume --last only searches sessions from the current directory; add --all after changing directories. When the saved directory differs from the current one, Codex asks which to use; tui.resume_cwd fixes that choice. Sessions run with --ephemeral are not saved and cannot be resumed.
When you need a fixed result format (for example a QC verdict per sample), use --output-schema schema.json to constrain the final reply to a JSON structure and -o to write it to a file.
# Run one analysis in the project directory; final reply goes to a file (progress goes to stderr)
cd ~/research/rnaseq-2026
codex exec --sandbox workspace-write \
-o results/2026-10-10_qc/codex_summary.md \
"Following AGENTS.md, run scripts/01_qc.py, write outputs to results/2026-10-10_qc/ and create RUN.md"
# JSONL events (commands, file changes, token usage)
codex exec --json --sandbox workspace-write "..." > run_events.jsonl
# Continue the previous non-interactive session (--last searches the current directory only)
codex exec resume --last "Change the 01_qc filter to min_counts=10 and rerun"
# Interactive sessions
codex resume # picker
codex resume --last # most recent in this directory
codex resume --all # search all directories
codex fork --last # copy a session to try another approach| Default | Consequence | What to do |
|---|---|---|
| Read-only sandbox when no config file sets one | The analysis runs but cannot write result files | Add --sandbox workspace-write, or set sandbox_mode in config.toml |
| Approval policy is always never | Actions that need approval fail and the error goes back to the model instead of waiting for you | Put the needed permissions (writable directories, network) in the config beforehand |
| Must run in a git repository or trusted directory | Not inside a trusted directory and --skip-git-repo-check was not specified. | Run git init in the analysis directory, or add --skip-git-repo-check |
Approvals and sandbox
The sandbox decides what commands can technically do (which directories they can write, whether they can reach the network); the approval policy decides when Codex stops to ask. They are set independently. In the CLI and IDE extension the operating system enforces the sandbox: Seatbelt on macOS, bubblewrap / Landlock on Linux and WSL2, dedicated sandbox users on native Windows.
Some paths stay read-only under workspace-write: .git, .codex and .agents inside the workspace (so git commit needs approval) and home locations such as ~/.cache. Tested on this page with codex sandbox: writing inside the workspace succeeded, while writing to ~/.cache and git commit both returned Operation not permitted, and curl to an external host returned Could not resolve host. Python packages that write caches to ~/.cache fail for this reason; specify in AGENTS.md that cache directories such as MPLCONFIGDIR and HF_HOME point inside the project or to /tmp.
/undo has been removed from the CLI. A maintainer explained in GitHub #9203 that the old implementation caused many problems and would need a redesign. The community workaround is to ask Codex to reverse its last changes with the patch tool, but deleted untracked files cannot be recovered. Committing to git before each task is currently the most reliable way back.
For finer control than sandbox_mode, use permission profiles (beta): set read, write or deny per path under [permissions.<name>] and allow-list network domains. The next section shows how to make raw data read-only.
| Combination | What it can do | Practical consequence |
|---|---|---|
| read-only + on-request | Read files and run read-only commands; writes and network need your approval | For a first look at someone else's code or explanations only; every change needs a click |
| workspace-write + on-request (the default Auto) | Read, write and run commands in the working directory, /tmp and $TMPDIR; writes outside and network need approval | Recommended for daily work. Every file in the working directory, raw data included, can be changed or deleted |
| workspace-write + never | Same as above; out-of-bounds actions simply fail | Common for codex exec. After a failure the model may try another route around it |
| workspace-write + approvals_reviewer = "auto_review" | Out-of-bounds requests go to a reviewer agent first | Fewer interruptions; reviews use extra allowance, and /approve retries one denied action |
| danger-full-access or --yolo (--dangerously-bypass-approvals-and-sandbox) | No sandbox, no approvals; reads and writes the whole machine and the network | Officially meant only for already-isolated containers or VMs. Deleted untracked files cannot be recovered through Codex |
Research code
Research analysis differs from ordinary software work in three ways: raw data cannot be regenerated, results must trace back to exact commands and parameters, and tasks run long. The steps below address each.
# ~/.codex/config.toml: make data/raw read-only with a permission profile
# Use this block OR sandbox_mode / [sandbox_workspace_write]; if both are present the profile is ignored
default_permissions = "research"
[permissions.research]
extends = ":workspace" # inherit the default workspace profile (.git/.codex read-only, network off)
[permissions.research.filesystem.":workspace_roots"]
"data/raw" = "read" # relative to each workspace root
"**/*.env" = "deny"
# Tested on this page (Codex CLI 0.162.1, macOS arm64, codex sandbox -P research):
# echo ok > results/out.txt -> succeeds
# echo x >> data/raw/counts.csv -> Operation not permitted
# rm data/raw/counts.csv -> Operation not permitted
# Control: with the built-in :workspace profile, appending to data/raw/counts.csv succeeds- 01
Layer 1: make raw data read-only at the OS level
The simplest option is chmod -R a-w data/raw. A Codex-only option is a permission profile that extends :workspace and sets data/raw to read (code below). Use it instead of sandbox_mode: if any config layer contains sandbox_mode or you pass --sandbox, the profile has no effect.
- 02
Layer 2: directory conventions in AGENTS.md
State which directories are read-only, where generated files go and what counts as done. The agent follows these rules, but rules alone cannot block writes, so combine them with layer 1.
- 03
Layer 3: git and per-run directories
If raw data stays out of git, at least track scripts, configs and RUN.md. Write each run to a new results/<date>_<label>/ directory instead of overwriting old results.
- 04
Require a reproducibility record
Have AGENTS.md require a RUN.md per run: commands, input file md5s, software and package versions (conda env export or sessionInfo()), random seed, parameters, runtime and outputs. When reviewing, read RUN.md before the results.
- 05
Prepare the environment first
workspace-write has no network by default, so pip / conda installs fail. Build the environment yourself before the task, or enable network_access only for the turn that installs packages and turn it off afterwards.
- 06
When the context gets long
Check remaining context with /status. Codex compacts automatically at a threshold (adjust with model_auto_compact_token_limit), or run /compact manually. GitHub #36642 reports that since 0.145 auto-compaction occasionally discards the entire history; it still reproduces on 0.150 and the issue is open. In long tasks, have Codex write progress, confirmed parameters and open items to NOTES.md, and have it read that file first after a failed compaction or in a new session.
Troubleshooting
Read the URL or path in the error first: it shows where the request actually went or which file was refused. Then run codex doctor, which checks login, WebSocket, proxy variables and the sandbox separately.
| Error message | Cause | Fix |
|---|---|---|
| unexpected status 401 Unauthorized: Missing bearer or basic authentication in header | No usable credentials (empty auth.json, or the env_key variable is not exported in this shell) | Check with codex login status; with API keys, confirm the variable is exported |
| stream disconnected before completion: error sending request for url (http://127.0.0.1:<port>/v1/responses) | A leftover model_provider in config.toml points to a local proxy that is not running | Delete the model_provider line and its [model_providers.x] table; changing model alone is not enough |
| stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses) | The network or proxy cuts long-lived connections; more common with SOCKS5 proxy variables | Use HTTP proxy variables with NO_PROXY; when doctor shows websocket failing, Codex tries an HTTPS fallback |
| Every request in WSL fails with stream disconnected from 0.129.0 on | WSL networking regression reported in GitHub #24511; 0.128.0 works; issue open | Community fix: enable WSL mirrored networking, or run on native Windows |
| Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token) | The last sign-in step could not reach auth.openai.com | Check the proxy covers that domain; on servers use --device-auth |
| no native root CA certificates found | The server lacks system root certificates | Point CODEX_CA_CERTIFICATE or SSL_CERT_FILE to a PEM file, e.g. the one shipped with Python certifi |
| Not inside a trusted directory and --skip-git-repo-check was not specified. | codex exec must run in a git repository or trusted directory | git init or add --skip-git-repo-check |
| Operation not permitted (writing files or git commit) | The target is outside the writable roots or in a protected path such as .git or .codex | Add a writable directory with --add-dir, or approve the action in the session |
| Could not resolve host (pip, curl, git clone) | workspace-write disables the network by default | Set sandbox_workspace_write.network_access = true, or approve that network request |
| Codex is ignoring N unrecognized configuration settings | Misspelled, deprecated or misplaced fields | Fix the field path shown; use --strict-config to make it a hard error |
| Missing optional dependency @openai/codex-<platform> | The npm platform package failed to download | See the Install section |
| Windows sandbox commands fail with error 1385 | System policy denies the logon type the sandbox user needs | Ask IT to grant the logon right; temporarily set [windows] sandbox to unelevated |
| Skipped loading 1 skill(s) due to invalid SKILL.md files ... missing YAML frontmatter | A local skill file lacks the --- delimited name and description | Add the YAML header at the top of the file |
Chinese community experience
The following come from posts with original error output or the author's own test record, cross-checked against the official documentation or GitHub issues, with the conditions under which they apply.
Remove custom providers completely when switching back to official sign-in
A CSDN author (Codex 0.142.0, Windows) saw requests going to 127.0.0.1:57321. A local proxy tool installed earlier had left model_provider and [model_providers.CodexPlusPlus] in config.toml, and the proxy was no longer running. Changing model back to an official model still used the old provider; removing both blocks and running codex logout and codex login fixed it. A later token_exchange_failed during sign-in was solved by switching proxy nodes.
Lab servers without internet or root
A CSDN author's tested setup: add RemoteForward 17891 127.0.0.1:7890 for the server in the local ~/.ssh/config to map the local proxy onto the server; export HTTP(S)_PROXY=http://127.0.0.1:17891 on the server; if root certificates are missing, set SSL_CERT_FILE to certifi's cacert.pem; load the same variables for the VS Code extension through ~/.vscode-server/server-env-setup, then run Remote-SSH: Kill VS Code Server on Host and reconnect. The author recommends getting the CLI working before the extension.
The macOS desktop app ignores proxy variables from the terminal
Proxies exported in .zshrc only apply to codex started from a terminal. An app opened from the Dock needs launchctl setenv followed by a restart (CSDN post). In GitHub #20844 a Windows user likewise only became stable after setting both the system proxy and the environment variables to an HTTP proxy.
If config changes do nothing, read doctor's ignore warnings
The warning mcp_servers.node_repl.type is ignored recorded in a CSDN post matches the format this page saw with codex doctor --all on 0.162.1. MCP configs migrated from Claude Code often carry a type field that Codex does not use.
Disagreement: fixing WSL disconnects
A NodeSeek user fixed it with WSL mirrored networking (networkingMode=mirrored, dnsTunneling=true); the reporter of GitHub #24511, on an Enterprise account, only recovered by going back to 0.128.0. Both start by running codex doctor inside WSL on its own, because WSL and Windows use different proxy variables and configs.
Hand it to an agent
Example instruction: "This is my RNA-seq project repository; raw counts are in data/raw. Read AGENTS.md and scripts/ first, run 01_qc through 03_deseq without modifying data/raw, write RUN.md for each step, and finally list how the results differ from the previous run and what I need to check."
Steps the agent performs: in an isolated cloud computer built on Codex, it reads the repository and AGENTS.md; uses the preinstalled pandas, SciPy, statsmodels and scikit-learn environment and installs missing R or Python packages in the workspace; runs the numbered scripts while recording commands, versions and parameters; reviews the results adversarially; keeps running after you close your computer and pauses with its state preserved when idle.
Outputs: modified scripts, a results directory with RUN.md and logs for every run, and a record explaining changes and anomalies.
You still need to check: whether the statistical methods and thresholds fit your study design, whether sample groups and batch information are correct, and the biological interpretation of the results.
References
- Codex CLI documentation — Four install methods and update commands
- Codex IDE extension documentation — Entry points for VS Code, Cursor, Windsurf, JetBrains and Xcode
- Codex Cloud and Codex environments documentation — Local, Worktree and Cloud; cloud tasks do not get local files
- Authentication documentation — Two sign-in methods, device code, port 1455 forwarding, CODEX_CA_CERTIFICATE, credential storage
- Pricing documentation — Surfaces and models per plan; API keys exclude cloud features
- Models documentation — Current recommended models and GPT-5.5 retirement date
- Config basics / Advanced Configuration / Configuration Reference — Precedence, profile files, custom providers, MCP fields, keys project configs cannot set
- Custom instructions with AGENTS.md — Discovery order, override files, 32 KiB limit
- Agent approvals & security — Sandbox and approval combinations, protected paths, migrating from untrusted
- Permissions (beta) — Permission profile syntax; not combinable with sandbox_mode
- Non-interactive mode — codex exec defaults, output, git check, CODEX_API_KEY
- Developer commands (CLI reference and slash commands) — Subcommands, slash commands, shortcuts
- ChatGPT desktop app for Windows / Windows sandbox — WSL1 unsupported since 0.115, Windows version requirements, error 1385
- Gloaguen et al. Evaluating AGENTS.md (arXiv 2602.11988, ICLR 2026) — Effect of context files on success rate and cost
- GitHub openai/codex #9203: Please make /undo back — Maintainer explains why /undo was removed; community undo workaround
- GitHub openai/codex #36642: Auto-compaction silently discards history — Reports of history loss since 0.145 and a self-check command
- GitHub openai/codex #20844: SOCKS5 proxy instability — Experience report: stable after switching SOCKS5 to HTTP proxy
- GitHub openai/codex #24511: 0.129.0+ fails in WSL — WSL disconnect regression report
- CSDN: troubleshooting record for local Codex stream disconnected before completion — Experience post with the author's own test (0.142.0, Windows): leftover local proxy and token_exchange_failed
- CSDN: setting up Codex CLI and the VS Code Codex extension on a remote server — Experience post with the author's own test: SSH reverse proxy and certificates for servers without internet
- CSDN: configuring a proxy for the Codex app on Mac — Experience post: launchctl setenv for GUI apps
- CSDN: Codex 401 errors and config not taking effect — Experience post: original unrecognized-field warning; its claims about environment variable precedence contradict the official docs and were not used