Applying a Codex task diff brings generated changes from a completed task into a local Git working tree for review, testing, and integration. It is useful when a task was run in Codex Cloud (or another Codex execution environment) and the resulting patch needs to be applied to a local checkout.

The codex apply command fetches the latest diff associated with a task ID and applies it as an uncommitted patch using git apply-style behavior. The patch is applied against the currently checked out files, so the local branch and base revision should match the context the task diff was generated from.

Local, uncommitted changes can cause hunks to fail or apply in unexpected places, so a clean working tree (or a temporary stash) is preferred before running codex apply. After applying the patch, standard Git inspection commands confirm which files changed and whether the content matches expectations before moving on to commits or additional work.

Steps to apply a Codex task diff:

  1. Confirm the current directory is inside the target Git repository.
    $ git rev-parse --show-toplevel
    /home/user/projects/example-repo

    fatal: not a git repository indicates the wrong directory.

  2. Check the working tree for uncommitted changes.
    $ git status --porcelain

    No output indicates a clean working tree.

  3. Create a temporary branch before applying the diff.
    $ git switch -c codex-task-apply
    Switched to a new branch 'codex-task-apply'

    A dedicated branch keeps the applied patch isolated for review.

  4. Stash local changes if uncommitted changes are present.
    $ git stash push -u -m "pre-codex-apply"
    Saved working directory and index state On main: pre-codex-apply

    Reapply later with git stash pop after the task diff review.

  5. Apply a Codex task diff by task ID.
    $ codex apply 1f2e3d4c-5678-90ab-cdef-1234567890ab
    Applying patch...
    Applied patch to working tree

    A failed apply usually indicates the checkout does not match the task diff base revision.

  6. Review the working tree for expected changes.
    $ git status -sb
    ## main...origin/main
     M data/pages/codex/version-check.txt
     M data/pages/codex/exec-prompt-run.txt
  7. Review a summary of file-level changes introduced by the applied patch.
    $ git diff --stat
     data/pages/codex/exec-prompt-run.txt |  8 +++++---
     data/pages/codex/version-check.txt   | 14 ++++++++++----
     2 files changed, 15 insertions(+), 7 deletions(-)
  8. Inspect the detailed diff to confirm the patch content is correct.
    $ git diff
    diff --git a/data/pages/codex/version-check.txt b/data/pages/codex/version-check.txt
    index 2b0c9f1..8a1d2c3 100644
    --- a/data/pages/codex/version-check.txt
    +++ b/data/pages/codex/version-check.txt
    @@ -12,7 +12,11 @@
     ##### snipped #####
  9. Reapply stashed changes if a stash was created earlier.
    $ git stash pop
    On branch main
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   notes/todo.txt
    
    ##### snipped #####
    Dropped refs/stash@{0} (3e2d1c4f1a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d)

    Stash pop can produce merge conflicts when the task diff touched the same files.