Codex · Advanced · Part 5 of 8

Working with Codex day to day: prompts, git, review, and fixing things when they go wrong

Khairul Alam·October 2026·~23 min read
AdvancedPromptingGitCode reviewTroubleshooting

Parts 1 to 4 got you installed, safe, and set up with project memory, cost awareness and a feel for the models. This is where the advanced level starts. You can run Codex; now the question is how to get good results from it every day: what to type, how to ship a change with git, how to review it, how to steer when it goes the wrong way, and what to do when something breaks. Everything here follows the official Prompting, Best practices, Worktrees, Code review and Troubleshooting pages, with my own advice marked as such.

Part 5 in 60 seconds
  • A good prompt has four parts: goal, context, constraints, and “done when”.
  • For hard or unclear tasks, plan first: type /plan (or press Shift+Tab), then implement.
  • Give Codex a check it can run (tests, lint, a repro), and review the result with /review before you commit.
  • Use a git worktree when two chats would otherwise edit the same files.
  • While Codex works, you can steer it (Enter in the CLI) or queue a follow-up (Tab).
  • Keep one chat per outcome. When a chat is stuck, check for a pending approval, then start fresh with a smaller prompt.
Contents of Part 5
  1. The four-part prompt
  2. Explore, plan, implement, review, commit
  3. Prompting patterns that work
  4. Prompt recipes for everyday tasks
  5. Give Codex a way to check its work
  6. Big feature? Let Codex interview you
  7. Git with Codex: branch, commit, pull request
  8. Worktrees and parallel chats
  9. Code review: local changes and pull requests
  10. Steering, queueing and long-running work
  11. Projects, chats and resuming
  12. When something goes wrong
  13. Wrap-up, glossary and links

1. The four-part prompt

Codex is strong enough to be useful even when your prompt is not perfect. The official Best practices page says so directly. But clear prompts make results more reliable, especially in a big codebase or when the stakes are higher. The page recommends a good default: include four things.

Goalwhat should changeor be built? Contextfiles, folders, docs,examples, errors Constraintsstandards, safety,conventions Done whentests pass, bug gone,behavior changed This keeps Codex scoped, reduces guessing, and makes the work easier for you to review.
The four-part default from the official Best practices page. Use only the parts that help; a one-line prompt is fine for a one-line change.

Here is that shape as one prompt (my example, in the style of the docs):

Goal: users who log out and log back in lose their saved filters. Fix it.
Context: start with @src/session/restore.ts and the test in @tests/session.test.ts.
Constraints: do not change the public API; keep the fix minimal.
Done when: a new regression test fails before the fix and passes after, and
the existing session tests still pass.

The same page suggests choosing the reasoning effort to fit the job: low for faster, well-scoped tasks, medium or high for complex changes or debugging, and extra high for long, agentic, reasoning-heavy tasks. As of 18 October 2026 it says to use GPT-6.1 Sol when it is available to your account and client, and to start with High for GPT-6 Luna or Light for GPT-6 Astra (low in configuration). Model lineups change, so check Part 4 and the official Models page before you rely on that.

2. Explore, plan, implement, review, commit

Letting an agent jump straight to code can produce a tidy answer to the wrong question. The official Best practices page says to plan first when the task is complex, ambiguous or hard to describe. Here is the workflow I follow, built from features the docs describe:

1. Exploreread and ask,change nothing 2. Plan/plan, answerits questions 3. Implementcode, run thechecks, fix 4. Review/review and/diff, you read 5. Commitcommit, push,open a PR When to skip steps 1 and 2If you could describe the diff in one sentence (a typo, a log line, a rename), just ask for it directly.
Planning has a cost. It pays off when the approach is uncertain, several files change, or the code is unfamiliar.

For planning, the docs name three options:

The steps as prompts (my wording):

# 1. Explore (read-only questions)
Read @src/auth and explain how sessions and login work.
Also tell me where secrets are loaded from. Do not change anything.

# 2. Plan
/plan I want to add Google sign-in. Which files change, and what is the session flow?

# 3. Implement (after you accept the plan)
Implement the plan. Add tests for the callback handler,
run the test suite, and fix any failures.

# 4. Review
/review

# 5. Commit
Commit this with a descriptive message.

A wrong assumption fixed in the plan costs one sentence. The same assumption fixed after twenty edited files costs a lot more.

3. Prompting patterns that work

The Prompting page says a useful Codex prompt “names the behavior you want, points to the relevant code or reproduction steps, preserves important constraints, and says how to verify the change.” Here is how to turn that into habits.

HabitWeak promptStronger prompt
Describe the resultlook at the settings pagemake the Save button on settings persist the toggle after a page refresh
Point at the codeadd a testAdd a test for the invert_list function in @transform.ts. Cover the happy path plus edge cases. (From the docs.)
Give the reproductionfix the bugA numbered list of repro steps, the expected result, and the actual result. The docs say repro steps and constraints matter more than a high-level description.
Set boundariesclean this upDo not change the API shape. Keep the fix minimal and add a regression test if feasible.
Say how to verifymake it workAfter the fix, run lint plus the smallest relevant test suite. Report the commands and results.

The Prompting page also advises starting with the result, not a detailed list of steps. Describe a process only when the process itself matters; otherwise leave Codex room to search and adjust its approach.

Give Codex richer context

Tip from the docs: when Codex makes the same mistake twice, ask it for a retrospective and update AGENTS.md, so the guidance is based on real friction. In the CLI, /init scaffolds a starter AGENTS.md.

4. Prompt recipes for everyday tasks

These come from the official Prompting page (its Codex workflows). Adapt the wording to your project.

TaskPrompt to try
Understand a codebaseI need to understand the protocol used by this service. Read @foo.ts @schema.ts and explain the schema and request/response flow. Focus on required vs optional fields and backward compatibility rules.
Ask for something you can verify: Summarize the request flow as a numbered list of steps. Then list the files involved.
Fix a bugStart Codex at the repo root, then give a bug description with numbered repro steps and constraints, and end with: Start by reproducing the bug locally, then propose a patch and run checks.
Write a testAdd a test for the invert_list function in @transform.ts. Cover the happy path plus edge cases. In the IDE: select the lines, choose “Add to Codex Thread” from the command palette, then Write a unit test for this function. Follow conventions used in other tests.

Notice that each recipe is a short conversation, not one giant prompt. You are not expected to get it perfect the first time: ask, read, refine. The docs also note that Codex does not have to be watched step by step; the Best practices page lists “treating Codex like something you have to watch step by step” as a mistake. Use it in parallel with your own work.

5. Give Codex a way to check its work

The Best practices page puts it plainly: do not stop at asking Codex to make a change. Ask it to create tests when needed, run the relevant checks, confirm the result and review the work before you accept it. Codex can do this loop for you, but only if it knows what “good” looks like. That can come from the prompt or from AGENTS.md.

The docs list “not letting the agent see its work” (no details on how to run build and test commands) as a common mistake. The fix is a few lines in AGENTS.md: your build, test and lint commands, and what “done” means. If you cannot verify a change, do not ship it. That one is my rule, not the docs'.

6. Big feature? Let Codex interview you

If you have a rough idea but are not sure how to describe it, the docs suggest asking Codex to question you first, challenge your assumptions and turn the fuzzy idea into something concrete before writing code. A prompt in that spirit (my wording):

/plan I want to build [brief description]. Interview me first.
Ask about technical choices, edge cases, concerns and tradeoffs.
Challenge my assumptions. Don't ask obvious questions.
When we're done, write a short spec to SPEC.md.

7. Git with Codex: branch, commit, pull request

Codex works inside your git repository, and the desktop app has git actions built in. Here is the flow, and where you stay in charge.

Branchnew branch ChangeCodex edits Verifychecks pass Review/review, /diff Commit, pushopen a PR Mergeyou decide Where you stay in charge • Read the diff before you commit, and stage only the parts you want. • Reviewing in a chat does not post comments, approve or merge on its own. • My advice: use branch protection so nothing reaches your main branch unreviewed.
Codex can do the middle of the flow. The first and last decisions are yours.
You want to…How, according to the docs (or my advice where marked)
See what changedCLI: /diff shows staged changes, unstaged changes and files Git is not tracking yet. App: open the review pane (section 9).
Stage or discard part of the workApp review pane: stage, unstage or revert the entire diff, a single file, or a single hunk.
Start a branch from a worktree chatApp: select Create branch here in the chat header. From there you can commit, push your branch, and open a pull request on GitHub.
CommitReview the diff first. Then commit from the app's review pane, or ask in plain words (my advice): Commit these changes with a short, descriptive message. Keep your message style in AGENTS.md.
Open a pull requestPush the branch and open the PR on GitHub. Install and sign in to the GitHub CLI (gh auth login), which the docs say powers GitHub-specific features in the desktop app.
Fix a failing check on a PRIn the Code Review plugin, select Fix in Checks on an open PR. It attaches the failing checks to the chat and prepares a message without sending it. Add your prompt and send. Then inspect the changes and rerun the tests before you push.

Tips that make this smoother:

8. Worktrees and parallel chats

The Best practices page lists “running live tasks on the same files without using Git worktrees” as a common mistake. A git worktree is a second checkout of your repository. Each worktree has its own copy of every file, but they all share the same .git history, so you can work on several branches at once. Codex worktrees let several chats run in the same project without interfering with each other. They only work in projects that are part of a Git repository.

In the desktop app

  1. In a new chat, select Worktree under the composer. Optionally pick a local environment to run setup scripts.
  2. Choose the starting branch below the composer. It can be main, a feature branch, or your current branch with unstaged changes.
  3. Submit your prompt. Codex creates a worktree from that branch. By default it is in a “detached HEAD” state, so it does not pollute your branches.
  4. Choose where to keep working: stay on the worktree and select Create branch here, or select Hand off to move the chat and code into your Local checkout.

Think of Local as the foreground and Worktree as the background. A few facts worth knowing:

In the CLI

The CLI has a --worktree flag (start in a new managed Git worktree; local execution only) and a /worktree slash command, which lets you start a new chat or continue the current one in a new worktree. It is unavailable while a task is running. Parallel chats can also use subagents (Part 6); the rule stays the same: do not let two chats change the same files.

9. Code review: local changes and pull requests

The docs treat review as a first-class part of the loop. There are two different tools, and the Code review page keeps them apart: the built-in /review command reviews changes in your Git checkout, and the Code Review plugin works with pull requests.

Review local changes with /review

Type /review in the CLI, the app composer or the IDE extension. It only appears when the open project is inside a Git repository. Codex starts a dedicated reviewer that reads the diff and reports prioritized, actionable findings without changing your working tree. The CLI presets are:

ScopeWhat it does
Review against a base branchFinds the merge base and reviews your branch diff (PR-style).
Review uncommitted changesIncludes staged, unstaged and untracked files.
Review a commitReviews the exact change set of a selected commit.
Custom review instructionsFocuses the review on criteria you give, for example /review Focus on edge cases and security issues.

Apply fixes, then run /review again to confirm they are resolved. By default the review runs in the current chat; the app has a Detached setting under Settings > General > Code review to start a separate review chat, and you can set review_model in config.toml to use a different model for reviews. From a script, codex review runs a non-interactive review with --uncommitted, --base BRANCH or --commit SHA (Part 7).

The app's review pane

The review pane reflects the state of your Git repository, not just what Codex edited. By default it shows Unstaged changes; switch to Staged, Commit, Branch (diff against your base branch) or Last turn (only the most recent assistant turn). To leave line-specific feedback, hover a line, select +, write your comment, and then send a message to the chat. The docs advise making your intent explicit, for example “Address the inline comments and keep the scope minimal.” The pane requires a project inside a Git repository.

Review a pull request

Honest caveat from the docs: check every finding against the latest diff, the expected behavior and the tests before you decide it needs a fix. Reviewing a pull request in a chat does not post comments, approve or merge it. Posting in Summary or Changes sends the comment to GitHub immediately, so keep comments as drafts in the chat until you are ready.

10. Steering, queueing and long-running work

You do not have to wait for Codex to finish before you speak. The Prompting page describes two behaviors for a message you send while Codex is working:

BehaviorWhat happensHow
SteerAdds your message to the current run. Use it to change direction, add a missing detail or share new information.CLI: press Enter while Codex works. App: set the default in Settings > General > Follow-up behavior.
QueueSaves your message for the next run. Use it for a follow-up that should wait.CLI: press Tab while Codex works (this also works for slash commands and shell commands). App: queued messages appear above the composer, where you can edit, reorder, send or delete them.

Other keys from the CLI reference worth knowing: press Escape twice with an empty composer to edit your previous message and fork the chat from that point; Up and Down restore draft history; Ctrl+R searches prompt history; Ctrl+O (or /copy) copies the latest finished output; Ctrl+C or /exit closes the session. If background commands are running, /ps lists them and /stop stops them. I did not find a documented shortcut that only interrupts the current turn, so check /keymap and the shortcut list for your version.

Long-running work with /goal

For work that may take many steps, give Codex a clear outcome, constraints and a definition of done, and keep related work in one chat. Type /goal in the CLI, the desktop app or the IDE extension. The goal text becomes both the first prompt and the completion criteria. In the CLI:

/goal Migrate this codebase from JavaScript to TypeScript. Preserve existing
behavior, compile in strict mode without explicit `any` types, and make the
full test suite pass.

/goal            (view the current goal)
/goal edit       (revise it)
/goal pause      (pause)   /goal resume   /goal clear

The docs say a good goal has three elements: an outcome (the result, not just the activity), constraints (tools, boundaries, things to avoid) and verification (tests, measurements or review criteria that prove it is done). Goal text must be non-empty and at most 4,000 characters; for longer instructions, put them in a file and point the goal at it. Starting a goal does not grant broader access: the same sandbox and approval policy apply, and it pauses when it needs a decision. For local work, turn on Prevent sleep while running in settings so your Mac stays awake.

11. Projects, chats and resuming

The Best practices page says to keep one chat per coherent unit of work, and lists “using one chat for an entire project” as a mistake because it bloats context. If the work is still the same problem, staying in the same chat preserves the reasoning trail. Fork only when the work truly branches.

The chat keeps its transcript and recorded working directory, but Codex reads files from the current working tree. So keep durable guidance in AGENTS.md or checked-in docs, not only in a chat.

12. When something goes wrong

Install and login problems were covered in Part 1. These are the problems you can hit once Codex is running. They come from the official Troubleshooting page unless I say otherwise. First, the general stuck-chat routine from that page: (1) check whether Codex is waiting for an approval, (2) open the terminal and run a basic command like git status, (3) start a new chat with a smaller, more focused prompt.

SymptomLikely causeFix
Files appear in the review panel that Codex did not editThe panel shows your project's Git state, including your own changes.Switch the diff pane to the Last turn view to see only Codex's last turn.
Code does not run in a worktreeWorktrees are created elsewhere and inherit only files checked into Git, so dependencies and ignored files may be missing.Run setup scripts through a local environment, copy ignored files with .worktreeinclude, or check out the changes in your regular project.
“fatal: '...' is already used by worktree” when you check out a branchGit allows a branch to be checked out in one place at a time.Use Hand off to move the chat to Local, or check out a different branch on the worktree.
A chat seems stuckOften a pending approval.Check for an approval prompt, run git status in the terminal, or start a new chat with a smaller prompt.
You started a chat on the wrong target (Local, Worktree or Cloud), or cancelled worktree creation and lost your promptEasy to click the wrong one.Cancel the run and press the up arrow in the composer to recover your previous prompt.
A feature works in the CLI but not in the desktop app (or the reverse)The two can bundle different Codex versions.Compare codex --version with the app's bundled copy: /Applications/Codex.app/Contents/Resources/codex --version on macOS.
A setting does not seem to applyAnother config layer or a policy is overriding it.Run /debug-config to see config layer order, on/off state and policy sources.
Feedback and logs

Type / in the composer to send feedback; you get a session ID you can share. You can also search or open an issue on the openai/codex GitHub repository. Session transcripts are stored in $CODEX_HOME/sessions (default ~/.codex/sessions), and on macOS the app logs are in ~/Library/Logs/com.openai.codex/. The docs remind you to review logs for sensitive information before sharing them.

A general rule for a bad session

If Codex is going in circles, the cause is often the setup, not the model. The Best practices page says many quality issues are really setup issues: the wrong working directory, missing write access, wrong model defaults, or missing tools. Run /status, check the directory and branch, and look at what AGENTS.md tells it. Then start a clean chat with a better first prompt (goal, context, constraints, done when). That almost always beats a long chat full of corrections.

13. Wrap-up, glossary and links

  1. Write prompts with a goal, context, constraints and a “done when”.
  2. Plan first (/plan) unless the change is one sentence.
  3. Always give Codex a check to run, and review with /review and /diff before you commit.
  4. Use worktrees so parallel chats never edit the same files.
  5. Steer with Enter, queue with Tab, and use /goal for long work.
  6. One chat per outcome; when stuck, check approvals and git status, then start fresh.

Next, Part 6 extends Codex: connecting outside tools with MCP, skills, plugins and subagents, and choosing between the CLI, IDE extension and desktop app. If you want to revisit models and plans first, that was Part 4.

TermIn plain words
Plan modeCodex investigates and proposes an approach before it edits anything. Toggle with /plan.
@ referenceTyping @ and a path to add a file to the prompt.
Steer / queueSend a message into the current run, or save it for the next run.
WorktreeA separate checkout of a git repository, for parallel work.
Hand offMoving a chat and its code between Local and a worktree.
/reviewA built-in reviewer for your Git changes that reports findings without changing files.
Goal mode/goal: a persistent target for a long task, with completion criteria.
Pull request (PR)A request to merge your branch, with a description and review.

Links and official docs

Codex changes quickly. This series was checked against the official documentation on 18 October 2026; always confirm details on the official pages.

← Back to all writing