Edit a repository with Codex CLI and review the diff
Start Codex CLI in a terminal, check the session status and permissions, give it a narrow edit task, then verify the result with /review and your own diff view.
Before you start · 1. Enter the project directory and launch · 2. Check the session status
At a glance
Codex CLI can inspect code, edit files and run tools already installed on your machine from the terminal. An edit can still be wrong, so this workflow splits one task into scoping, permission checks, the edit, diff review and a keep-or-discard decision, leaving checkable evidence at each step. The example uses a fictional small project with no real account or code.
Workflow
Is the scope clear?
The task names target files, the behavior to change and what must not be touched. If the scope is vague, narrow it before starting.
Are permissions suitable?
After launch, use /status to see the session configuration and /permissions to choose what Codex may do, then give the task.
Does the diff match?
After the edit, ask Codex to re-check with /review and compare the version-control diff file by file against the original task.
Before you start
- The codex command already runs in your terminal (see the official Install Codex page for installation; this guide does not repeat it).
- Use a local Git repository. Record existing changes, then establish a baseline that isolates this task: commit existing work or start in a clean separate working directory. A backup helps recovery but does not clear existing diffs. Revert only changes made by this task.
- Knowledge of the project's own checks, such as its existing test or build command, because Codex runs tools already installed on your machine.
1. Enter the project directory and launch
In the terminal, change to the root of the repository you want to modify, then type codex. The startup screen shows the current directory; confirm it is the target repository rather than a parent or unrelated folder. If it is wrong, exit the session and start again from the right place.
2. Check the session status
Type /status to view the current session configuration. Check that the working directory and model settings match your expectation; this guide names no model, so follow what your interface shows. If something is unwanted, adjust it with /model as the interface suggests, or end the session.
3. Choose permissions
Type /permissions and select what Codex may do. For a first task of this kind, pick a conservative option; the available options are whatever your screen lists. If the permission configuration you chose asks for approval before a command or file write, read each request, then decide whether to approve it rather than opening everything at once.
4. Describe the task in one complete sentence
At the prompt, include four things: which files to read, which behavior to change, what must not change, and what to report afterwards. For example: "Read src/title.js and tests/title.test.js, make formatTitle trim leading and trailing spaces and add one matching test; do not change other files; when done, list the files you changed and the checks you ran." Give one small task at a time.
5. Ask for a review, then read the diff yourself
When Codex finishes, type /review so it re-checks the change and points out issues. Then, in a second terminal window, read the version-control diff file by file: only permitted files should appear, and every change should map to a phrase in the task. Run the project's own check and go by its actual output rather than Codex's verbal summary.
6. Keep or discard, then stop
Commit only when the diff matches the task and the checks pass. If unrelated files, extra refactoring or failing checks appear, ask Codex for another round on the specific problem or undo the change with version control. End the session when done; to continue later, relaunch and recheck the directory and permissions. Compare against the baseline and revert only the task diff, preserving pre-existing work.
Original example
Fictional project demo-notes. Input: launch codex in the repository root, confirm with /status that the directory is demo-notes, choose a conservative option in /permissions, then enter "Read src/title.js and tests/title.test.js, make formatTitle trim leading and trailing spaces and add one test; do not change other files; when done, list the files you changed and the checks you ran." Expected, checkable result: the diff shows only those two files; the change in src/title.js concerns whitespace handling only; the test file gains one case using a title with surrounding spaces; Codex's report matches the diff; the project's own test command passes in your terminal. If the diff also touches package configuration or reformats an entire file, treat it as out of scope, undo it and tighten the prompt. This is an illustrative workflow, not an observed output.
Completion checks
- The directory on the startup screen matches the target repository.
- The file list in the diff is exactly the set of files the task allowed.
- Every change maps to a phrase in the task description.
- The project's own check was actually run and passed in your terminal, not merely reported by Codex.
- Each issue raised by /review was either fixed or consciously set aside with a recorded reason.
Limits
- Do not start in a directory holding important uncommitted work; the diff will mix together and be hard to undo.
- Do not open all permissions at once; approve deleting files, installing dependencies or network access one by one, and only after you understand them.
- /review is a helper check; it does not replace reading the diff and cannot guarantee nothing was missed.
- This guide names no model and does not judge whether any model suits your task.
Verification scope
Only the official Codex CLI documentation was read; the example task and prompt are original. Login, installation, product API execution, file upload and generated output were not tested, so slash-command behavior and menu options depend on your current version.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.