Artificial Intelligence Practice Test

β–Ά

Codex CLI is OpenAI's open-source coding agent for the terminal. You open it inside a project, describe a task in plain English, and it reads your files, proposes edits, runs commands and tests, and reports back. It can work carefully with you approving each step, or run on its own inside a sandbox while you do something else. This guide has 10 sections, 15 copy-paste blocks of prompts or commands, an 8-question Q&A, and takes about 26 minutes to read.

Codex CLI is OpenAI's open-source coding agent for the terminal. You open it inside a project, describe a task in plain English, and it reads your files, proposes edits, runs commands and tests, and reports back. It can work carefully with you approving each step, or run on its own inside a sandbox while you do something else. This guide has 10 sections, 15 copy-paste blocks of prompts or commands, an 8-question Q&A, and takes about 26 minutes to read.

This codex cli tutorial takes you from a clean machine to a merged pull request. You will install the CLI, sign in, pick a sandbox and approval mode, write an AGENTS.md file, complete a first real task, hand a PR review to Codex, and connect it to GitHub and your IDE. There is also a short comparison with Claude Code and a section on the errors people hit most.

Everything here reflects Codex as it works in late 2026. OpenAI ships updates often, so when a flag or menu on your screen looks different, run codex --help and trust that over any article, including this one. If you want structured practice instead of a single read, the AI Mastery course has a full Codex module with quizzes at the end of each lesson.

This Tutorial at a Glance

⬇️
2 install paths
npm or Homebrew
πŸ”‘
2 sign-in options
ChatGPT account or API key
πŸ›‘οΈ
3 sandbox levels
read-only, workspace-write, full access
πŸ“„
1 instructions file
AGENTS.md
πŸš€
7 steps
First task walkthrough
πŸ› οΈ
6 common errors
With fixes

OpenAI uses the name Codex for two products that share a model and an instructions format but run in different places. Knowing which one you are using saves confusion later, because the commands, the permissions and the way results come back are not the same.

Codex CLI runs on your own machine. It is an open-source terminal program. It works on the files in your current directory, uses your local tools (Node, Python, git, your test runner), and shows you a diff before anything lands. Nothing leaves your machine except the prompt, the relevant file contents and command output sent to the model.Codex cloud lives inside ChatGPT. You connect a GitHub repository, and Codex clones it into a sandboxed container on OpenAI's side. You give it a task from the ChatGPT interface, it works in the background, and it hands back a diff or opens a pull request. You can queue several tasks at once and walk away.

The two share AGENTS.md. Instructions you write once for the CLI also guide the cloud agent, so the file is worth doing properly. Most developers use the CLI for interactive work and quick fixes, and the cloud agent for batch tasks that can run unattended. If you have used Claude Code, the split is similar to Claude Code in the terminal versus Claude Code on the web; our Claude Code tutorial for beginners walks through that side.

Which Codex Should You Use?

πŸ“‹ Codex CLI (local)

Best when you want to watch and steer. You are in the repo already, the change is small to medium, you need local services such as a database or a dev server, or the code cannot leave your machine. You approve edits and commands one by one, or switch to a sandboxed auto mode for routine work. Runs on macOS, Linux and Windows through WSL.

πŸ“‹ Codex cloud (ChatGPT)

Best for tasks you can fully describe up front and check later. Refactors across many files, writing tests, dependency upgrades, or several independent bug fixes in parallel. It needs a GitHub connection and a container setup that can install your dependencies. Results arrive as diffs or pull requests you review in the browser.

πŸ“‹ Use both

A common pattern: explore and plan with the CLI, where you can ask questions and inspect files quickly, then hand the well-defined execution to the cloud agent while you keep working locally. Keep one AGENTS.md in the repo so both agents follow the same rules for testing, style and commit messages.

You need a terminal, Node.js (a current LTS release) and git. On Windows, use WSL. Install the CLI globally with npm:

npm install -g @openai/codex

On macOS, Homebrew works too:

brew install codex

Check that the command is on your path.

codex --version

Now sign in. Run the command with no arguments.

codex

The first launch asks how you want to authenticate.

Choose Sign in with ChatGPT to use the Codex access bundled with a paid ChatGPT plan; it opens a browser window, you approve, and the token is stored under ~/.codex/. Choose the API key option if you bill through an OpenAI Platform account instead, and export OPENAI_API_KEY in your shell before launching. Check the current pricing page for what each plan includes, since limits change.

Run codex login later to switch accounts and codex logout to clear the stored credential. Configuration lives in ~/.codex/config.toml, where you can set a default model, a default approval policy and MCP servers. You do not need to touch it yet.

One habit to build now: always start Codex from the root of the project you are working on. It treats the current directory as its workspace, and the sandbox boundaries in the next section are drawn around that folder.

Codex CLI separates two questions: what can the agent touch (the sandbox) and when does it stop to ask you (the approval policy). Most beginners assume these are one setting. They are not, and picking the right pair is the single biggest safety decision you make.

The sandbox has three levels. read-only lets Codex read files and run commands that do not write, which is perfect for code review and questions. workspace-write allows edits and writes inside the current project directory and its temp folders, but blocks the rest of your disk and, by default, network access. danger-full-access removes the sandbox; only use it inside a container you can throw away.

The approval policy decides when Codex pauses. With untrusted, it asks before running anything except a short list of known-safe commands. With on-request, the model decides when it needs to ask, usually for anything outside the sandbox. With on-failure, it runs freely inside the sandbox and only asks if a sandboxed command fails and it wants to retry with more permission. With never, it never asks, so pair that only with a strict sandbox.

You can set both from the command line, and there are shortcuts. Start a cautious session like this:

codex --sandbox workspace-write --ask-for-approval untrusted

Or use the shortcut for supervised automation.

codex --full-auto
--full-auto means workspace-write plus on-failure. Codex edits and runs tests inside your project without asking, and only comes back when something needs a decision. Inside a session, type /approvals to change the policy without restarting, and /status to see the current sandbox, model and token usage.

Which Mode for Which Job

πŸ“‹ Learning and review

Use read-only with untrusted approval. Codex can explain the codebase, trace a bug, or review a diff, and it cannot change a file. This is the right mode for your first hour and for any repository you do not own. Ask it "walk me through how requests reach the database" and you get a tour with file references and no risk.

πŸ“‹ Daily feature work

Use workspace-write with on-request or untrusted. You see every edit as a diff and approve commands that matter. Once you trust the agent on a task, allow the rest of the session with one keystroke. This is the mode most developers live in.

πŸ“‹ Routine automation

Use --full-auto for tasks with a clear finish line and a test suite that proves it: "make the failing tests pass", "rename this module everywhere", "add JSDoc to every exported function". Commit first so you can git diff and revert. Never combine never approval with danger-full-access on a machine you care about.

AGENTS.md is a plain Markdown file that Codex reads at the start of every session. It is where you write the things a new teammate would need to know: how to run tests, which folders are off limits, what style the project uses, and what "done" means. Codex CLI and Codex cloud both read it, and other tools have adopted the same filename, so one file serves several agents.

Codex looks for the file in layers. A global file at ~/.codex/AGENTS.md applies to every project, a file at the repo root applies to that repo, and files in subfolders apply when Codex works inside them. More specific files win when instructions conflict. Keep the global file for personal preferences and the repo file for team rules.

The fastest way to start is inside a session.

/init

That drafts a starter file from your project. Edit it before trusting it.

A good file is short and specific. Commands beat descriptions. Here is a compact example for a TypeScript service:

# AGENTS.md

## Setup
- Install: `npm ci`
- Dev server: `npm run dev` (port 3000)
- Tests: `npm test` (must pass before you finish)
- Lint: `npm run lint --fix`

## Rules
- Never edit files under `migrations/` or `.env*`
- Use the existing `logger` module, not console.log
- Keep functions under 40 lines; extract helpers
- Write a failing test before fixing a bug

## Finishing
- Run tests and lint, then summarize changed files
- Do not commit; leave changes staged for review

Notice what is missing: no essays about architecture, no wishes.

Every line is something Codex can act on or check. Add a "do not" section for anything that has burned you before. If Codex keeps doing something you dislike, the fix is usually one more line in this file rather than a longer prompt. The pattern is identical to a CLAUDE.md file, which we cover in the Claude Code skills guide, and the course lesson on agent instruction files shows several real examples side by side.

AGENTS.md Lines That Pay Off Immediately

The exact test command, and a rule that tests must pass before the agent reports done
The lint or format command, so every change arrives in project style
Folders and files the agent must never edit (migrations, secrets, generated code)
Which logging, HTTP and database helpers to use instead of raw calls
Whether the agent may commit, and the commit message format if so
How to run the app locally so the agent can verify behaviour, not just tests
A note on the language or framework version, so it does not use newer syntax than you ship
One sentence on how to summarize its work at the end

Time for a real task. Pick something small with a clear finish line. A good first task changes two or three files and has a test you can run. Below, the example is adding input validation to an API route, but any similar job works.

Step 1: Start clean. Commit or stash your work so git diff later shows only what Codex did. Open the terminal at the repo root and launch a supervised session.
git status
codex --sandbox workspace-write --ask-for-approval untrusted
Step 2: Give context, then the task. Be specific.

A prompt like this gets far better results than "add validation": "In src/routes/users.ts, the POST handler accepts any body. Add validation so email is required and well-formed and name is 2 to 80 characters. Return 400 with a JSON error listing the failing fields. Add tests in tests/users.test.ts following the existing pattern. Run the test suite when you are done."

Step 3: Watch the plan. Codex reads the relevant files, may ask a clarifying question, and shows its first edit as a diff. Read it. If it is heading the wrong way, say so now; correcting early is cheap.Step 4: Approve commands deliberately. When it asks to run npm test, approve it. When it asks to run something you do not recognise, ask it why first. You can allow a command for the rest of the session once you are comfortable.Step 5: Review the whole change. Type /diff to see everything it touched.
/diff

Then check the working tree yourself.

git diff --stat
Step 6: Iterate in the same session. If a test failed, say "the second test fails because the error shape is different, match the existing error format in src/errors.ts". Codex keeps the context, so follow-ups are short. Use /compact if the conversation gets long and responses slow down.Step 7: Commit yourself. Unless your AGENTS.md allows commits, do the commit by hand so your name and message are on it. Close the session with /quit or Ctrl+C. Next time you can pick up where you left off.
codex resume

That shows recent sessions and lets you reopen one.

For scripted or CI use there is a non-interactive mode that runs one task and exits, printing the result to standard output:

codex exec "update the README installation section to match package.json scripts"

Use exec only with a sandbox and a clear task.

Prompts That Work Well on a First Session

πŸ—ΊοΈ Explain before changing

"Explain how authentication works in this repo and list the files involved." Zero risk, and it tells you whether Codex understands your code before you let it edit.

πŸ§ͺ Test-first bug fix

"Write a failing test that reproduces issue #42, then fix it so the test passes without changing other tests." The test is your proof the fix is real.

🧹 Bounded refactor

"Extract the date formatting in these three components into one helper in src/utils. Keep behaviour identical and run the tests." Small scope, checkable result.

πŸ“ Docs from code

"Read src/cli.ts and write a usage section for the README covering every flag." Codex is strong at turning real code into accurate docs.

Code review is one of the best uses of Codex because it needs no write access and produces value on every run. Check out the branch you want reviewed, or fetch a colleague's pull request, and open a read-only session.

git fetch origin pull/128/head:pr-128
git checkout pr-128
codex --sandbox read-only

Inside the session, ask for the review with a clear frame.

Try: "Review the diff between this branch and main. Focus on correctness, error handling and anything that would break existing callers. For each issue give file, line, severity and a suggested fix. Do not comment on formatting." Codex will run git diff main...HEAD, read the changed files and the surrounding code, and give you a structured list. Newer builds also expose a built-in review command:

/review

It reviews your current changes against the base branch.

The output is a starting point, not a verdict. Ask follow-ups: "is the race condition you flagged reachable in the current request lifecycle?" Codex reads more of the codebase to answer, which is exactly what a careful human reviewer would do. When you agree with a finding, you can switch to workspace-write and ask it to apply the fix on the spot.

For a team workflow, put the review instructions into AGENTS.md under a "Review checklist" heading. Then every reviewer, human or agent, uses the same list. This also feeds the GitHub integration in the next section, where Codex reviews pull requests without anyone opening a terminal.

Codex as a Reviewer: Strengths and Limits

Pros

  • Runs in read-only mode, so a review can never damage the branch
  • Reads surrounding code, not only the diff, so it catches broken callers
  • Consistent: applies the same checklist to every pull request
  • Fast on large diffs where human attention fades after the first few files
  • Can turn an accepted finding into a fix in the same session
  • Works on any language your repo uses, with no plugin per language

Cons

  • Does not know product intent, so it may flag deliberate choices as bugs
  • Can miss issues that need runtime knowledge (real data, load, timing)
  • Verbose by default; you need to ask for severity and skip style nits
  • Large monorepos may need you to narrow the scope to specific folders
  • Findings still need a human to confirm before they go in a PR comment
  • Usage counts against your plan limits, so batch reviews thoughtfully

The GitHub integration is what turns Codex from a personal tool into a team workflow. Setup happens in ChatGPT: open the Codex section, connect your GitHub account, and choose the repositories Codex may access. Grant only the repos you need; you can add more later.

Once connected, three things become possible. First, you can start cloud tasks from ChatGPT against any connected repo, and Codex opens a pull request with its changes when finished. Second, you can mention Codex on a pull request in GitHub, for example by commenting @codex review this, and it posts a review in the PR thread. Third, you can enable automatic reviews so every new pull request gets a first pass before a human looks.

Because both the CLI and the cloud agent read the same AGENTS.md, the instructions you tuned locally carry over. If your file says "run npm test before finishing", the cloud container runs it too, provided the environment can install your dependencies. You configure that environment in the ChatGPT Codex settings: setup script, environment variables and whether network access is allowed during the task.

A practical rhythm many teams settle on: write the issue clearly, assign it to Codex cloud, get a draft PR, then pull that branch locally and finish it with the CLI where you can run the app. The cloud agent does the boring first eighty percent, and you keep the judgement calls.

Connecting Codex to GitHub, in Order

Open the Codex section in ChatGPT and connect your GitHub account
Grant access to one repository first, add more once the workflow is proven
Commit an AGENTS.md at the repo root with test, lint and no-touch rules
Configure the cloud environment: setup script, environment variables, network policy
Run one small cloud task and confirm the pull request looks the way you expect
Try a review by mentioning Codex on an open pull request
Turn on automatic reviews only after the team agrees on the review checklist
Decide who merges: Codex opens PRs, a human approves and merges

If you prefer a sidebar to a terminal, OpenAI ships a Codex extension for VS Code, which also works in VS Code forks such as Cursor and Windsurf. Install it from the extension marketplace, sign in with the same ChatGPT account, and it uses your existing ~/.codex configuration and AGENTS.md files.

The extension shows the conversation in a panel, presents edits as inline diffs you accept or reject, and lets you switch between local mode and cloud tasks from the same window. Selecting code and asking a question about it is quicker than typing file paths in the terminal, and you can open the built-in terminal alongside to keep the CLI habits you learned above.

For JetBrains users, check the official docs for current IDE support; the extension list grows over time and this article will not guess at it. Whatever the surface, the mental model is unchanged: sandbox, approval policy, instructions file, small tasks with a test.

People ask which terminal agent to learn. The honest answer is that Codex CLI and Claude Code are closer than either vendor's marketing suggests. Both run in your terminal, read your repo, ask permission before risky actions, read a Markdown instructions file, support MCP servers for external tools, and have an IDE extension and a cloud counterpart. The differences are in defaults and ecosystem.

Codex ties naturally to ChatGPT plans and to GitHub, and its sandbox model is explicit and easy to reason about. Claude Code leans on Anthropic's Claude models and has a deeper customization layer: plan mode, hooks, subagents, and Skills, which are reusable SKILL.md procedures the agent loads when relevant. Start with the ecosystem you already pay for; the concepts transfer in an afternoon. For the long form, read what Claude Code is and the Gemini CLI tutorial, since Google's open-source agent is the third option on the same shelf.

CriterionCodex CLIClaude Code
Vendor and modelsOpenAI, GPT-5 familyAnthropic, Claude Opus / Sonnet / Haiku 4.x
Instructions fileAGENTS.md (global, repo, subfolder)CLAUDE.md (global, repo, subfolder)
PermissionsSandbox level plus approval policyPermission modes incl. plan mode, allow lists
ExtensibilityMCP servers, config.tomlMCP servers, hooks, subagents, Skills, plugins
Cloud counterpartCodex cloud in ChatGPT, GitHub PRsClaude Code on the web
IDEVS Code family extensionVS Code and JetBrains extensions
Non-interactivecodex execclaude -p
PricingChatGPT plan or API usageClaude plan or API usage

Check both official pricing pages before deciding; plan limits shift often.

Common Errors and Fixes

🚫 command not found: codex

The npm global bin folder is not on your PATH. Run npm bin -g (or npm prefix -g) and add that bin directory to your shell profile, or reinstall with Homebrew on macOS.

πŸ” Login loop or expired token

Run codex logout, then codex login, and complete the browser step in the same machine's browser. On a remote server without a browser, use the API key path or copy the device login URL as the prompt instructs.

🧱 Permission denied writing files

You are in read-only sandbox, or the file is outside the workspace. Restart with --sandbox workspace-write from the repo root, or move the target into the project directory.

🌐 npm install or curl fails inside the sandbox

Network is blocked by default in workspace-write. Approve the specific command when asked, or run the install yourself before starting Codex. Enable network for a session only when you understand the risk.

πŸŒ€ Agent loops or forgets earlier instructions

The context is full. Type /compact to summarize the session, or start a fresh session and move the standing rules into AGENTS.md so they survive resets.

πŸͺŸ Windows quirks

Native Windows support is limited; install under WSL, keep the repo inside the Linux filesystem, and launch codex from the WSL shell rather than PowerShell for consistent sandbox behaviour.

Two more problems deserve a paragraph. The first is a rate limit or usage cap message mid-task. Codex stops and tells you; nothing is lost. Wait for the window to reset, or switch to an API key if your team bills that way. Check the current pricing page rather than guessing what your plan includes.

The second is git confusion: Codex edited files but the diff is empty, or the change sits on the wrong branch. Almost always the session started in a different directory than you thought. Run /status to see the working directory and sandbox, then git status in that folder. Starting every session from the repo root avoids this.

When you hit anything not covered here, the official docs at OpenAI's developer site are current and searchable, and the CLI's own codex --help is the source of truth for flags. Beyond that, the fastest way to get fluent is practice with feedback, which is exactly what the AI Mastery course Codex lessons are built for, and the guide to building your first AI agent explains the plan, act, observe loop that Codex runs under the hood.

Official references: OpenAI Codex documentation and the open-source Codex CLI repository.

Codex CLI Questions and Answers

Is Codex CLI free?

The CLI itself is open source and free to install. Using it requires either a ChatGPT plan that includes Codex access or an OpenAI API key billed by usage. Check the current pricing page for what each plan includes, since limits and tiers change.

What is the difference between Codex CLI and Codex in ChatGPT?

Codex CLI runs on your machine in your terminal and edits your local files with your approval. Codex cloud runs in a sandboxed container on OpenAI's side, works on a GitHub repository you connect, and returns a diff or pull request. Both read the same AGENTS.md file.

Do I need an AGENTS.md file?

No, Codex works without one, but the file is where you record test commands, off-limits folders and style rules. Without it you repeat those instructions in every prompt. Run /init inside a session to draft one and then edit it.

Which approval mode should a beginner use?

Start with the read-only sandbox and untrusted approval to explore safely, then move to workspace-write with on-request approval for real edits. Save --full-auto for tasks with a clear finish line and a test suite.

Can Codex CLI run commands and tests on its own?

Yes. Inside the sandbox it can run your test runner, linters and build scripts. Whether it asks first depends on the approval policy you choose. Network access is blocked by default in workspace-write mode, so installs may need explicit approval.

How does Codex review a pull request?

Locally, check out the branch, start Codex in read-only mode and ask for a review against main, or use the built-in /review command. In GitHub, once the integration is connected, mention Codex on the pull request or enable automatic reviews.

Does Codex CLI work on Windows?

Use WSL. Install Node and Codex inside your Linux distribution, keep the repository in the Linux filesystem, and launch codex from the WSL shell. Native Windows support is limited and may behave differently.

Codex CLI or Claude Code, which should I learn first?

They share the same core ideas: terminal agent, instructions file, permission model, MCP support. Pick the one attached to the subscription you already pay for. Skills learned in one transfer to the other in an afternoon.
Go deeper: the full AI Mastery course

This tutorial gets you from install to a reviewed pull request. The AI Mastery course goes further: 60 lessons across 12 modules, from beginner to advanced, covering Gemini, Claude Code, Codex, building AI agents, Seedance video generation and building websites with AI tools. Each module ends with a quiz, you get lifetime access, and you can preview 2 lessons free before you decide. Start with the free preview lessons of the AI Mastery course and continue from where this article stops.

β–Ά Start Quiz