Skip to content

Run your first Codex task

A first Codex task is one small, real change whose success a test can prove: Codex reads the repository, edits files inside its sandbox, runs the project’s test command, and reports what it did. The Codex CLI is the reference surface. The desktop app, the IDE extension, and Codex cloud run the same agent with different isolation and review.

This page is for developers who have installed Codex, signed in, and now face an empty composer. The tempting first prompt is “refactor the auth module”, and it returns a 14-file diff you cannot judge. A better first task ends in a test that fails without the change and passes with it, so you can accept the result on evidence instead of reading every line.

What you’ll walk away with from your first Codex task

Section titled “What you’ll walk away with from your first Codex task”
  • A checklist for choosing a first task that a test can prove.
  • A first-task prompt with acceptance criteria, a plan checkpoint, and a report format, plus a variant for repositories without an HTTP layer.
  • The exact commands for Codex CLI 0.157.1 to run the task interactively, in a Git worktree, headless, and in Codex cloud.
  • A five-minute verification routine, including a check that the new test can actually fail.
  • Recovery steps for the ways a first task usually goes wrong.
  1. Codex runs and you are signed in. codex doctor reports no errors. If it does, work through installation and authentication first.

  2. The working tree is clean. Codex edits real files, and Git is your undo. Commit or stash anything in progress:

    Terminal window
    git status --short # should print nothing
  3. You know the project’s test command and it passes today. Run it once yourself. If the suite is already red, Codex cannot show you that it turned it green.

  4. Optional but worth it: an AGENTS.md. Run /init inside Codex to draft one, then correct the test command and folder layout by hand. Set up AGENTS.md for Codex explains what to put in it. Since codex-cli 0.150.0, a project you have not marked as trusted does not supply its AGENTS.md, so answer the trust prompt when Codex first opens the repository.

The best first task has one observable behaviour, touches one to three files, and has an existing test runner to prove it. That keeps the diff small enough to check in minutes and gives you an objective signal.

Good first taskPoor first taskWhy
Fix a missing error path in one API route and add a test for it“Improve error handling everywhere”One behaviour, one test; the broad version has no finish line
Handle an edge case in a pure function (empty list, null, time zone)Migrate the project to a new frameworkA pure function is testable in isolation; a migration needs a plan first
Add input validation to one endpoint, with a 400 testRedesign the database schemaValidation is reversible; a schema change needs a migration and review
Add a missing test for an untested branch“Make the tests faster”“Faster” has no acceptance criterion

The walkthrough below uses the first row. It exercises everything a first task should: reading the codebase, finding a concrete defect, editing code, writing a test, and running commands in the sandbox.

Write the prompt: outcome, constraints, and proof

Section titled “Write the prompt: outcome, constraints, and proof”

A first-task prompt states the outcome, fences the scope, and says what evidence ends the task. The plan checkpoint in the prompt below costs one extra turn and catches a wrong direction while it is still a paragraph of text.

If the project has no HTTP layer, point the same structure at a pure function. The shape stays the same: locate, propose, wait, test first, fix, report.

The CLI shows every file read, command, and approval as it happens, which makes it the clearest place to watch a first task.

  1. From the repository root, start Codex in a new managed Git worktree so the change cannot touch your main checkout:

    Terminal window
    codex --worktree

    Plain codex also works and edits your current checkout. With --worktree, the change lives in that worktree, not in the directory you started from, so run the verification checks further down from inside it: git worktree list in your main checkout prints its path. Either way, once you trust the repository and unless your config says otherwise, Codex runs with the on-request approval policy and the workspace-write sandbox: it can edit and run commands inside the workspace, and it asks before writing elsewhere or using the network.

  2. Leave the model alone for now. GPT-6 Astra is Codex’s bundled default since codex-cli 0.153.4 (2026-09-04), and its default reasoning effort in Codex is low. If the plan in step 4 comes back shallow, raise the effort to medium or high with /model before you consider another model. The models hub covers when a different model is worth it.

  3. Paste the first-task prompt and press Enter.

  4. Read the plan. Check that the file and line exist, that the triggering input is plausible, and that the proposed test exercises that input. If any of the three is vague, ask for it before you reply go.

  5. Answer approval prompts deliberately. A request to reach the network or write outside the repository during a small fix usually means the approach is wrong, so decline and redirect. Recover from Codex errors explains each approval choice.

  6. When Codex reports back, inspect the result without leaving the session:

    • /diff shows the Git diff, including untracked files.
    • /review runs a separate review pass over your current changes and lists the issues it finds.

To script the same task, for example to repeat it across several services, use codex exec. It runs without the interactive UI and writes the final report to a file:

Terminal window
codex exec --sandbox workspace-write -o first-task-report.md "$(cat first-task-prompt.txt)"

first-task-prompt.txt holds the prompt without the “wait for go” step, because nobody answers in a headless run, and a plan checkpoint left in by mistake stalls the run. The headless variant replaces that paragraph with an instruction to state the evidence and carry on:

Find one error-handling gap in this project's API routes: a place where an
exception can crash the request handler or return a misleading status code.
State the file and line, an input that triggers the problem, the fix you
propose, and the test you will add first, then proceed:
1. Write the test first and run it. It must fail for the reason you described.
2. Make the smallest fix that makes it pass. Touch at most 3 files.
3. Do not modify, skip, or delete any existing test.
4. Run the full test suite.
Finish with: files changed, each command you ran with its exit code, and the name
of the new test.

-o (--output-last-message) saves the final message, and --json streams every event as JSONL if you want to parse the run. If your config.toml already selects a permission profile with default_permissions, drop --sandbox: OpenAI states that the profile and legacy sandbox systems “do not compose”. Configure Codex covers both, and running Codex non-interactively covers codex exec in depth.

Run the same task in the desktop app, IDE, or Codex cloud

Section titled “Run the same task in the desktop app, IDE, or Codex cloud”

The agent is the same on every surface. What changes is where it runs, how you watch it, and where you review the diff.

On macOS or Windows, codex app launches the desktop app and opens its installer if the app is missing. From a running CLI session, /app continues that session in the app. The app has no Linux build.

Open the project, start a thread, and paste the same prompt. Use the app when you want several threads running side by side in separate worktrees and a review pane for each diff. The Codex desktop app guide covers threads, worktrees, and the review pane.

OpenAI’s README still calls it the Codex App; since 2026-07-09 it ships as the Codex mode of the ChatGPT desktop app, according to Neowin (secondary source).

Verify the result without reading every line

Section titled “Verify the result without reading every line”

Codex’s summary is a claim, not proof. These five checks take about five minutes and tell you where, if anywhere, your own reading is needed. You sign off; the checks decide what you look at. If you started with --worktree, run them from inside that worktree (git worktree list prints its path), or begin with /diff in the session.

  1. Check the scope. The diff should match the plan you approved:

    Terminal window
    git status --short
    git diff --stat

    A file you did not expect is the first thing to read.

  2. Check that no existing test was weakened. Adjust the path to your test folder:

    Terminal window
    git status --short -- tests/

    git status rather than git diff, because git diff ignores untracked files and a new test file would never show. Only the new test should appear, as ?? (a new file) or M (a test added to an existing file). An M or D on any other test file is the red flag. A deleted, skipped, or loosened assertion is how an agent turns a red suite green, and it never shows in a “tests pass” summary.

  3. Prove the new test can fail. Temporarily remove the fix, keep the test, and run it. It must fail:

    Terminal window
    git stash push -- src/routes/orders.ts # the fixed source file, not the test
    npm test -- orders # expect a failure
    git stash pop

    Replace the path and the test filter with your own. If the fix is in a file Codex created, use git stash push -u -- <path>, because a plain stash skips untracked files. A test that passes without the fix proves nothing, so send it back.

  4. Run the gates yourself. In your terminal, not in Codex’s summary: the full test suite, the type check, and the linter, for example npm test && npm run typecheck && npm run lint.

  5. Run a review pass. Use /review in the session, or from the shell:

    Terminal window
    codex review --uncommitted

    Fix or disprove each finding that matters. Review Codex’s changes before you commit covers triage and keeping only the good hunks.

If you would rather have Codex run check 3 and show you the output, ask for it explicitly:

Read the failing output yourself. It should fail on the assertion you expect, not on an import error or a typo.

After the first task, choose the surface by how long the task runs and how you want to review it, not by habit.

TaskSurfaceWhy
A small fix you want to watchCLI or IDE extensionEvery command and approval is visible as it happens
A multi-file change you may throw awayCLI with --worktree, or the desktop appA worktree keeps your main checkout clean; deleting it is the undo
Long-running work, or several attempts to compareCodex cloudRuns remotely; --attempts gives independent tries to choose from
The same task across many repositories, or in CIcodex execScriptable, with the final report written to a file
A second opinion on a pull request@codex review on GitHubReviews where the team already works; see GitHub integration
SymptomLikely causeRecovery
Codex reports a gap you cannot reproduceThe plan was accepted without evidenceAsk for the triggering input as a failing test before any fix; reject a gap it cannot demonstrate
The new test passes with the fix removedThe test does not exercise the defectSend the “real oracle” prompt above; do not merge until the test fails without the fix
Existing tests changed or disappearedCodex made the suite pass by weakening itgit restore -- tests/, then repeat rule 3 of the prompt; add “never modify existing tests without asking” to AGENTS.md
Codex runs the wrong test commandNo AGENTS.md, or it guessedPut the exact command in AGENTS.md; start a new session so it loads
A package install or download failsThe sandbox blocks the network by defaultThat is the sandbox working. Install the dependency yourself, or grant the narrowest access described in error recovery
The diff sprawls across many filesThe task was too broadDiscard it (git restore ., or delete the worktree) and re-run with a file limit or a smaller task
Codex repeats the same failing fixIt is looping on one hypothesisPress Esc to interrupt, then ask for three different hypotheses, each with a check that tells them apart

Where to go next after your first Codex task

Section titled “Where to go next after your first Codex task”