Applying a completed Codex task diff locally moves the generated code changes into the current Git checkout without copying patch text by hand. It is the fastest way to bring a reviewed task result onto the machine where the repository already exists.

Current local codex apply --help output describes codex apply TASK_ID as applying the latest diff produced by a Codex agent as git apply to the local working tree. Current OpenAI Codex CLI docs also describe using codex cloud from the terminal to browse cloud tasks, inspect diffs, and apply the resulting changes locally. If a task has multiple attempts, codex cloud diff --attempt N and codex cloud apply --attempt N target a specific attempt.

The patch only applies cleanly when the local checkout matches the repository and branch the task was generated against. Uncommitted edits, a different base branch, or a partially applied patch can cause git apply failures, so inspect the current working tree first and review the diff before applying it.

Steps to apply a Codex task diff locally:

  1. Change to the repository checkout that matches the completed task and inspect the current Git state.
    $ cd ~/src/example-app
    $ git status
    On branch main
    Your branch is up to date with 'origin/main'.
    
    nothing to commit, working tree clean

    Use the same repository and a compatible branch or commit range. If local edits are already present, review or stash them before applying the task diff.

  2. Confirm that the current shell can reach Codex with the expected login.
    $ codex login status
    Logged in using ChatGPT

    codex apply fetches the task from Codex before running git apply locally, so cached authentication must already work in this terminal.

  3. Review the task diff before applying it.
    $ codex cloud diff task_i_abc123
    diff --git a/src/math.js b/src/math.js
    index 8f3c4a1..1c0cb8d 100644
    --- a/src/math.js
    +++ b/src/math.js
    @@ -1,4 +1,8 @@
     export function average(values) {
    +  if (values.length === 0) {
    +    return 0;
    +  }
       return values.reduce((sum, value) => sum + value, 0) / values.length;
     }

    Replace task_i_abc123 with the real raw task ID. If the ID is not already known, codex cloud list can show recent tasks in the current account. Use codex cloud diff --attempt N TASK_ID when the task has multiple attempts and the default first attempt is not the version to inspect.

  4. Apply the latest diff from the task to the current working tree.
    $ codex apply task_i_abc123
    Successfully applied diff

    Current local Codex help and CLI source show that codex apply fetches the task's current diff and applies it with git apply in the current directory. Use codex cloud apply --attempt N TASK_ID when a cloud task exposes multiple attempts and a non-default attempt should be applied instead.

    If the checkout does not match the task's expected base, git apply can fail or skip paths, so return to a matching branch before retrying.

  5. Inspect the applied patch before testing or committing it.
    $ git diff --stat
     src/math.js | 4 ++++
     1 file changed, 4 insertions(+)

    Follow this with the normal test command for the repository, or review the full patch with git diff when the task changed several files.