> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/openai/codex/llms.txt
> Use this file to discover all available pages before exploring further.

# codex apply

> Apply the latest diff produced by Codex agent to your local working tree

The `apply` command takes the most recent diff generated by the Codex agent and applies it to your local working tree using `git apply`.

## Usage

```bash theme={null}
codex apply
codex a  # Short alias
```

## Description

When Codex generates code changes during an interactive session, it produces a diff that can be applied to your files. The `apply` command:

1. Finds the latest diff from your most recent Codex session
2. Applies it to your local working tree using `git apply`
3. Reports any conflicts or issues

This is useful when you want to:

* Apply changes after reviewing them in the TUI
* Quickly accept Codex's proposed changes
* Integrate Codex changes into your current work

## Examples

### Basic Usage

Apply the latest diff from your most recent session:

```bash theme={null}
codex apply
```

Using the short alias:

```bash theme={null}
codex a
```

## Exit Codes

* `0` - Diff applied successfully
* `1` - Error applying diff (conflicts, file not found, etc.)

## Related Commands

<CardGroup cols={2}>
  <Card title="codex" href="/cli/codex">
    Run interactive Codex session
  </Card>

  <Card title="codex exec" href="/cli/exec">
    Run non-interactive execution
  </Card>
</CardGroup>
