# `Codex.Tools.ApplyPatchTool`
[🔗](https://github.com/nshkrdotcom/codex_sdk/blob/v0.18.1/lib/codex/tools/apply_patch_tool.ex#L1)

Hosted tool for applying Codex apply_patch edits to files.

## Options
  * `:base_path` - Base directory for file paths (defaults to CWD)
  * `:approval` - Approval callback for reviewing changes before applying
  * `:dry_run` - If true, only validate without applying changes

## Approval Callback

The approval callback can be:
  * A function with arity 1-3: `fn changes -> :ok | {:deny, reason} end`
  * A module implementing `review_patch/2`

## Examples

    # Basic usage (*** Begin Patch format)
    args = %{"input" => patch_content}
    {:ok, result} = ApplyPatchTool.invoke(args, %{base_path: "/project"})

    # With approval
    context = %{
      metadata: %{
        approval: fn changes, _ctx -> :ok end
      }
    }
    {:ok, result} = ApplyPatchTool.invoke(args, context)

    # Dry run to validate
    {:ok, result} = ApplyPatchTool.invoke(args, %{dry_run: true})

# `apply_hunks`

```elixir
@spec apply_hunks(String.t(), list()) :: {:ok, String.t()}
```

Applies hunks to file content.

Returns `{:ok, new_content}` or `{:error, reason}`.

# `parse_patch`

```elixir
@spec parse_patch(String.t()) :: {:ok, list()} | {:error, {:parse_error, String.t()}}
```

Parses an apply_patch or unified diff patch string into a list of file changes.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
