Codex CLI introduction
This tutorial introduces the Codex CLI as an AI harness for bounded work in a local repository. It connects repository instructions, tool permissions, inspectable changes and verification.
Sources and product details checked 25 August 2026
Use a disposable practice repository without confidential files.Complete the Preparation path before beginning.
Step 1
Identify the harness and its working surface
The Codex CLI is a terminal-based AI harness that works with project files, repository instructions, tools and execution feedback.
- Locate the workspace that defines the authorised file boundary.
- Identify the active model and the tools exposed by the harness.
- Require evidence through diffs, commands and reported checks.
- Keep human acceptance as an explicit state after technical validation.
Check: you can distinguish the model, Codex, the workspace and the evidence used for review.
Step 2
Prepare one bounded repository
- Use a disposable repository that contains no confidential files or credentials.
- Run
git status --shortoutside Codex and record the starting state. - Locate the repository instructions and the commands that check its current artefacts.
- Confirm the current account or workspace access required by the chosen Codex surface.
Check: the repository boundary, starting Git state and available checks are known before Codex starts.
Product prerequisites checked 25 August 2026 against the official CLI documentation.
Step 3
Install the Codex CLI through the maintained route
- Follow the current installation route in the official Codex CLI documentation.
- Open a new terminal when the installation changes the executable search path.
- Run
codex --versionand record the version used for the exercise. - Start the CLI with
codex --sandbox read-onlyfrom the practice repository.
Check: Codex reports its version and opens inside the intended repository with the read-only sandbox selected.
Installation command and CLI flags checked 25 August 2026. Open the official CLI guide.
Step 4
Confirm the workspace and active model route
- Confirm the current repository and branch before supplying the task.
- Identify the active model or provider shown by the CLI.
- State the files that may be inspected and the evidence expected in return.
- Treat
codex --oss --local-provider ollamaandcodex --oss --local-provider lmstudioas optional local-provider routes. This introduction uses the standard provider route.
Check: the repository, branch, model route and task boundary can each be named from the visible session state.
--oss and --local-provider checked 25 August 2026 in the official Codex CLI reference.
Step 5
Read the complete instruction hierarchy
Codex first loads one global file from CODEX_HOME: AGENTS.override.md takes precedence over AGENTS.md. It then searches each directory from the project root to the working directory, again preferring AGENTS.override.md. Instructions are combined root-down, so deeper guidance applies later.
- Identify the global
AGENTS.override.mdorAGENTS.mdinCODEX_HOME. - Locate the applicable instruction file in every directory from the project root to the current directory.
- Read the effective chain in order and assign each rule to its scope.
- Use
/initonly when the repository needs a reviewed starting instruction file.
Check: you can name the global and project instruction files that apply to the current directory and explain their precedence.
Official AGENTS.md guide, checked 25 August 2026.
Step 6
Inspect tools and permission boundaries before action
The sandbox sets the technical boundary for commands. The approval policy determines when Codex must stop and request authorisation before crossing that boundary.
- Open
/permissionsand inspect the active sandbox and approval policy. - Keep the first exercise in the read-only sandbox and authorise file inspection only.
- Review every requested permission or sandbox expansion against the task and repository boundary.
- Require Codex to report commands, observed outputs and remaining uncertainty.
Check: the displayed permissions permit inspection and exclude workspace changes during the first exercise.
Sandboxing and agent approvals checked in the official OpenAI documentation on 25 August 2026.
Step 7
Locate the extension and parallel-work mechanisms
Skills and MCP
Skills provide maintained task procedures. Model Context Protocol connections expose external resources and tools whose scope must be inspected.
Subagents and worktrees
Subagents return evidence from bounded contexts. Worktrees isolate concurrent file changes before integration.
Check: each enabled mechanism has a defined function, source, scope and verification route.
Step 8
Run one reversible repository orientation
Ask Codex to inspect the repository, identify applicable instructions and explain its maintained checks. Keep the task inside the read-only sandbox.
- Request a compact repository summary with direct file references.
- Ask Codex to name the applicable global and project instruction files and existing check commands.
- Inspect the cited files and compare the answer with the repository state.
- Exit the session and run
git status --shortoutside Codex.
Check: the summary is supported by repository evidence and the final Git state matches the recorded baseline.
The working loop follows the source-checked objectives of Codex bootcamp 101.
