Skip to content
AISeeker

Search

Search reports, topics, companies…

CH.05Tutorials
3 min read
Signal strength: 4/5Major
Verified · 6 Sources

A practical OpenAI Codex workflow: CLI, IDE extension and cloud tasks in one setup

Set up Codex once with config.toml and AGENTS.md, then move work between the terminal, your editor, scripted runs and cloud tasks.

Key figures

32 KiB
Default AGENTS.md budget
1–4
Cloud best-of-N attempts

OpenAI's Codex is now one agent with several front ends: a terminal UI, an extension for VS Code-style editors, a scriptable exec mode and cloud tasks that run in OpenAI-hosted containers. This tutorial wires them into a single workflow for a Git repository. You need a ChatGPT plan that includes Codex (Plus, Pro, Business, Edu or Enterprise) or an OpenAI API key. Commands and flags were checked against the Codex docs and the openai/codex README in late November 2026, and several changed this year, so treat older blog posts with caution.

Install, sign in and pick a model

bash
npm install -g @openai/codex      # or: brew install --cask codex
codex                             # first run: choose "Sign in with ChatGPT"
codex login status                # exits 0 when credentials are present

There is also a standalone installer (curl -fsSL https://chatgpt.com/codex/install.sh | sh). Inside a session, /model switches model and reasoning effort. The models page currently positions them like this:

Model IDSuggested use
gpt-6.2-solEveryday coding and editing
gpt-6.2-astraDemanding work such as cross-service debugging
gpt-6-lunaHigh-volume, focused tasks (extraction, small fixes)

Model IDs are exact strings. Pass them with --model / -m or set them in config.

Configure once: config.toml and AGENTS.md

Personal defaults live in ~/.codex/config.toml. A sensible starting point:

toml
model = "gpt-6.2-sol"
model_reasoning_effort = "medium"
sandbox_mode = "workspace-write"
approval_policy = "on-request"

workspace-write lets Codex edit files and run routine commands inside the project; on-request makes it ask before stepping outside that boundary. The other sandbox modes are read-only and danger-full-access. A repo can ship its own .codex/config.toml, but Codex loads it only after you mark the project as trusted. For one-off overrides use -c key=value, and for named setups use --profile <name>, which reads ~/.codex/<name>.config.toml.

Next, run /init in the repo to generate an AGENTS.md. Codex reads a global file from ~/.codex first, then walks from the Git root down to your working directory, taking at most one file per directory (AGENTS.override.md wins over AGENTS.md). Files closer to your directory come later and take precedence. Keep it tight: once the combined text reaches project_doc_max_bytes (32 KiB by default), Codex stops adding files.

The local loop: terminal and editor

Start codex in the repo and work conversationally. A few slash commands carry most of the load:

  • /permissions changes what Codex may do without asking.
  • /review reviews uncommitted changes, a commit or a base branch without touching your working tree.
  • /status shows the active model, sandbox and approval settings.

codex resume reopens an earlier session from the same repository. If you prefer staying in the editor, the Codex extension works in VS Code and compatible editors such as Cursor and Windsurf; JetBrains IDEs and Xcode have their own Codex integrations. The extension offers a "Work locally" mode and a cloud option for longer tasks.

Automate and delegate

Script it with codex exec

codex exec runs without the UI: progress streams to stderr and only the final message goes to stdout, which makes it easy to pipe. It starts in a read-only sandbox, so a triage job is safe by default:

bash
codex exec "Explain why the tests in tests/api fail. Do not change files."

To let it fix things, grant write access explicitly and capture the result:

bash
codex exec --sandbox workspace-write -o fix-summary.md \
  "Fix the ESLint errors in src/ and run npm test"

Add --json for a JSON Lines event stream, or --output-schema schema.json when another program needs the final answer in a fixed shape. codex exec resume --last continues the previous run. In CI, the docs recommend the openai/codex-action GitHub Action; if you call the CLI directly, scope CODEX_API_KEY to the single command rather than the whole job, because repository code running in that job could read it.

Hand long jobs to the cloud

Cloud tasks run in an environment you define on the web: repository, setup script, secrets and an internet-access policy (package-manager domains, specific allowed domains, or the full public internet). Once an environment exists, you can drive it from the terminal:

bash
codex cloud                                   # browse cloud tasks
codex cloud exec --env ENV_ID --attempts 3 "Add pagination to /api/orders"
codex apply TASK_ID                           # apply the task's diff locally

--attempts (1 to 4) asks for several independent solutions so you can keep the best one. Review the diff as you would a colleague's pull request before applying it.

Pitfalls

  • Stale flags. --full-auto is no longer supported; use --sandbox workspace-write. The untrusted approval policy has been retired, so old config files need updating.
  • Full access. Reserve danger-full-access (or approval_policy = "never" with it) for disposable containers or VMs.
  • Silent truncation. A bloated root AGENTS.md can push nested instructions past the 32 KiB budget. Split guidance into subdirectories instead.
  • Untrusted project config. If a repo's .codex/config.toml seems ignored, check whether the project is trusted.
  • Model typos. Use the exact model ID; gpt-6-2-sol is not gpt-6.2-sol.

Next steps

Get the local loop and AGENTS.md right first, then add one codex exec job (for example, nightly lint fixes on a branch). Move to cloud tasks once your environment's setup script reliably builds and tests the project from scratch.

Researched and drafted with AI assistance under editorial review. Report errors to support@aiseeker.dev.

Sources

This report synthesises the sources below. Primary sources are marked.

  1. [1]
    Inspect, edit, and run code from your terminal

    OpenAI (Codex docs)2026.11.28Primary

  2. [2]
    Command line options

    OpenAI (Codex docs)2026.11.28Primary

  3. [3]
    Choose a model

    OpenAI (Codex docs)2026.11.28Primary

  4. [4]
    Sandbox

    OpenAI (Codex docs)2026.11.28Primary

  5. [5]
    Non-interactive mode

    OpenAI (Codex docs)2026.11.28Primary

  6. [6]
    Custom instructions with AGENTS.md

    OpenAI (Codex docs)2026.11.28Primary

Back to Tutorials →