# How to Use Codex: Turning a Task Into a Handoff the Agent Can Finish Alone

A brief that answers every question before the agent asks, a sandbox that can actually install and run your tests, and a review that reads the task log before the diff — the three hinges that decide whether a delegated Codex task comes back finished or unverified.

> coding-agents · codex · ai-assisted development · About 7 min · Nov 29

## Key points

1. Codex is one agent in three places (an open-source command-line tool, an editor extension, and cloud tasks that run against a GitHub repo), and the cloud task is the setting where coding becomes a handoff rather than a supervised session.
2. A handoff brief has to answer four questions in advance: what is wrong now, what should be true instead, how it will be verified, and what is out of bounds; anything left unanswered becomes the agent's guess and survives to review.
3. The no-questions test is the check on a brief: reread it and ask what the agent would have to guess.
4. A cloud task runs in a fresh container built from your commit, so what the agent can verify is bounded by what the environment can install and run; setup script, lockfile, and network access decide whether "the tests pass" is a real claim or a guess wearing the same clothes.
5. Calibrate with a task that changes nothing: "run the test suite and report the output" tells you cheaply whether this repository can ever return verified work.
6. Read the task log, then the diff, then the summary, because the summary is only the agent's account of the log; the strongest cheap evidence is the new test failing before the fix and passing after.
7. A test the agent wrote after the fix proves the code and the test agree, not that the bug existed, so recreate the broken case yourself once.
8. Standing rules such as the run command, the test command, and off-limits folders belong in AGENTS.md at the repo root, a file shared with other agents, not pasted into every brief.
9. The same reasoning holds for the command-line version, where the sandbox is your machine and approvals replace environment configuration; install lines and flag names change between releases, so check the current docs.
10. Do not hand off work whose finished state you cannot check, and keep only one or two tasks in flight, because every diff returns to the same one reviewer.

---

Most pages that explain how to use Codex open with an install command, because Codex is easy to describe as a thing you install. It is OpenAI's agentic coding assistant, and it arrives in three places that share one agent underneath: an open-source command-line tool you run in a terminal, an extension inside your editor, and cloud tasks that run on OpenAI's machines against a GitHub repository while you are somewhere else. The command-line half really is open source, which is why searches for an open source AI coding assistant keep landing here.

The [Claude Code walkthrough](https://eulore.ai/articles/how-to-use-claude-code-d63031a3) put a terminal agent to work while you watched, and that habit of watching is worth keeping. Codex's more interesting setting points the other way: you write the task down, you leave, and you come back to a change that is either good or needs another round. Making that work is a different skill from supervising a session, and it has three hinges. The brief has to be complete enough that the agent never needs to ask you anything. The sandbox has to be able to install and run whatever proves the work is done. And you have to be able to read what comes back, because the agent's summary of its own work is not the work.

## The case: one bug, one brief

The example below is invented, but it is the ordinary shape of a first handoff. You have a small timesheet app, the kind of thing exported from an app builder or written in a few chat sessions, that turns logged hours into a CSV for invoicing. A user reports that the export breaks for any client whose name contains a comma: the invoice rows shift one column to the left, and they have been renaming clients to work around it. There is a test suite, `npm test` runs it, and a few tests already cover the export function.

The instinct is to type "fix the CSV bug" and hit send. That brief hides four decisions the agent will then make for you: which escaping rule to apply, which file to touch, whether to add a test, and how the finished work should be checked. Each of those silently becomes the agent's guess.

A handoff brief answers them in advance. Four lines, in this shape:

```text
Fix the CSV export in src/export.ts. Today exportCsv builds each row with
row.join(',') and no quoting, so a client name with a comma splits into two
columns in the invoicing spreadsheet.

Expected: fields wrapped in double quotes when they contain a comma, a double
quote, or a line break, and any double quote inside a field doubled. That is
what Excel and Google Sheets expect.

Verify with: npm test. Add a test named "quotes client names containing
commas" that exports a row with the client "Smith, Jones & Co" and checks the
resulting string. Existing export tests must still pass.

Do not: rename the export file, change the download button, reorder columns,
or touch anything under src/billing/.
```

Read each line as an answer to a question the agent would otherwise answer itself: what is wrong right now, what should be true instead, how will we both know, and what is out of bounds. The last line is the one people skip, and it is the one that keeps a two-line fix from arriving as a refactor of three files.

Before sending, run the no-questions test: reread the brief and ask, for each sentence, what the agent would have to guess. Anything it must guess is a decision you have handed over. In an interactive session the agent asks and you answer in ten seconds. In a handoff there is no pause to ask, so the guess survives all the way to your review, where it costs a whole round trip.

## The sandbox decides what "it works" can mean

A cloud task does not run on your laptop. Codex takes the repository at the commit you point it at, starts a fresh container, installs your dependencies, edits files inside that container, and runs commands there. So when the task comes back saying the tests pass, the only thing that sentence can mean is that the tests ran, in that container, against that code. Whether they could run at all is decided by how the environment is set up before the agent starts: a setup script that installs dependencies, plus any environment variables the app needs.

This is the hinge that surprises people, and the failure is quiet rather than loud. If the project has no committed lockfile, `npm ci` has nothing to install from. If the setup script is empty, the test runner may not be present. If the agent's own run has no network access, which is the default in the cloud sandbox and a sensible default, then nothing it does can fetch a package or call a live API. In all three cases Codex still finishes the task and still describes a correct fix. It just replaces "the tests pass" with "the change looks right", a much weaker claim wearing similar clothes.

Two habits fix this before it bites. First, make the setup script do the boring, explicit thing:

```bash
npm ci
```

and commit the lockfile so that line has something to read. If your repository came out of a builder without one, run `npm install` locally first and commit the resulting `package-lock.json` as its own change, so the lockfile is not part of the fix under review.

Second, calibrate the environment with a throwaway task that changes nothing: "run the full test suite and report the exact output, do not modify files." If the answer is a test summary, your environment can verify real work. If it is "the command was not found", you just learned that every future task in this repository will hand you unverified code, and you learned it for the price of one trivial round trip instead of a week of false confidence.

## Reading the change it hands back

What returns from a task is three things: a log of the commands the agent ran, a diff, and a written summary. Read them in that order, because the order of certainty runs the same way. The summary is the agent's account of the log, so if the two disagree, the log wins.

In the log, look for one pattern above everything else: the new test failing first, then the fix, then the suite passing. That red-to-green sequence is the strongest cheap evidence you can get, because it shows the test was actually sensitive to the bug. If the only run in the log is a green one at the end, and the agent wrote the test, you have something weaker than it looks. A test written after a fix proves that the code and the test agree, not that the bug was ever there. So plan to spend your own two minutes recreating the broken case before you call the task done.

Then read the diff, mainly for size and reach. Two files, `src/export.ts` and the test file, matches the brief. A diff that also reformats the download button, or bumps a dependency "while it was there", is scope drift, and the fix is one follow-up task that says exactly that: revert the unrelated edits, keep the quoting change.

The part the sandbox cannot do for you is the last check, because the container has no spreadsheet. You can borrow the container's eyes, though: add a line to the brief asking the final message to include the first three lines of the exported CSV as text. Then you can look at `"Smith, Jones & Co",8,720` yourself and judge the thing your user actually cares about, without a working development environment of your own.

The CSV escaping rule and the `npm ci` line belong to this example. What transfers is the shape: four-part brief, named check, calibrated environment, log before diff before summary, and a small human check at the end that a machine cannot make for you.

Two things you repeat in every brief should move into a file instead. Codex reads `AGENTS.md` at the repository root at the start of a task, so the run command, the test command, and standing rules like "never touch `src/billing/`" belong there once. That file name is shared across several agents now, not just Codex, so you write it once and other tools read it too, the same role the Claude Code walkthrough gave `CLAUDE.md`.

If you hand off from the command-line version instead of the cloud, nothing in the reasoning changes, only the mechanism: the sandbox is your own machine, it is limited to the folder you started it in by default, network access is off unless you grant it, and approval prompts stand in for environment configuration. Installation lines and flag names in Codex change between releases, so confirm the current ones in the docs rather than trusting a snippet from a blog post, including this one.

One more restraint is worth naming, because the handoff model invites the opposite. Queueing five tasks at once feels like five times the work, but each one returns a diff that has to be read by the same one person, and two tasks touching the same file arrive as a conflict you now own. One or two in flight is the honest limit. And if you cannot yet say how the finished work would be checked, with no test, command, or output you could look at, do not hand it off. Work beside the agent instead, in a session where you can watch it discover the problem, and write the brief once you know what "done" looks like.

## Mind map

```mermaid
flowchart LR
  A["How to use Codex"] --> B["One agent, three places: CLI, editor extension, cloud tasks"]
  B --> C["Cloud task = handoff: describe, leave, come back"]
  C --> D["Brief: wrong now / should be / how to verify / out of bounds"]
  D --> E{"What would the agent have to guess?"}
  E -->|"anything"| D
  E -->|"nothing"| F["Sandbox: setup script installs deps, tests run"]
  F --> G{"Calibration task: does the suite run at all?"}
  G -->|"no"| H["Fix environment before trusting any result"]
  G -->|"yes"| I["Read log, then diff, then summary"]
  I --> J{"New test failed before the fix, passed after?"}
  J -->|"yes"| K["Strong evidence, plus your own look at the output"]
  J -->|"no"| L["Weaker: recreate the broken case yourself"]
  K --> M["Standing rules move to AGENTS.md"]
```

## Glossary

- Handoff brief：a task description written for an assistant that will not ask questions, so it must state the current state, the target, the way to verify it, and the boundaries in one go.
- No-questions test：rereading a brief line by line and asking what the assistant would have to guess; every guess is a decision you have handed over.
- Sandbox environment：the disposable container a cloud task runs in, starting from the commit you pick and installing dependencies through a setup script; what it can install and run sets how strong the assistant's evidence can be.
- Calibration task：a first task that changes no files and only asks for the test output, used to confirm the environment can verify anything at all.
- Red to green：a log where the new test fails first, then the fix lands, then everything passes; it shows the test was sensitive to the bug in a way an all-green final run does not.
- AGENTS.md：a file at the repository root that the assistant reads when a task starts, holding the run command, the test command, and rules like which folders not to touch.

## Sources

1. [OpenAI Codex CLI — the open-source local agent; check install lines and sandbox or approval flags here, since they change between releases](https://github.com/openai/codex)
2. [AGENTS.md — the convention for the instruction file Codex and several other agents read at the repository root](https://agents.md)
3. [Codex cloud tasks entry point (sign-in required) — where the task log and returned diff appear](https://chatgpt.com/codex)

---

Original article: https://eulore.ai/articles/how-to-use-codex-06f377d6

> **Eulore** · Start small. Go deep.
>
> Eulore is an AI learning tool built around connected articles, each a 5–10 minute read. Ask questions as you go and help shape what comes next. That’s how this article was created.
>
> Start your own series → https://eulore.ai
