# Diff Review

> A review of an agent’s file edits before they land. Handles accept or reject per change, comments back to the agent and edits still streaming.

Canonical: https://hextaui.com/blocks/diff-review
Last updated: 2026-10-29

## Overview

Coding agents change several files at once, and people need to keep some of it and throw the rest away. Diff Review puts every edit in one scrolling list with a file tree beside it, so you can accept or reject a single change, a whole file or everything, from the mouse or the keyboard. DiffSummary is the “Edited 4 files +120 −34” card for the chat, with the same actions on each file.

Each decision touches exactly one change. A decided change folds down to a one-line stub with its result, Show and Undo, and a file folds away once every change in it is decided. Bulk actions say how many changes they cover, and every decision, including Accept all and Reject all, can be undone with U or ⌘Z. “Next” always means the next change you haven’t decided yet. The counts and the progress bar come from what is still pending, so the review ends with a clear “All reviewed”.

Hover a line and press + in the gutter, or focus a line and press Enter or C, to comment on it. Drag or Shift-click line numbers, or use Shift+↑↓, to comment on a range. The composer opens as a small popover under the line, and a sent comment stays on the line as a thread you can edit, delete with undo, or collapse, with a count in the gutter. Removed lines are reported on the old side and added or unchanged lines on the new side, so the line numbers always match the file.

Pass a unified diff, or the content before and after and let the block compute the diff. With full content you can show the unchanged lines between changes, 20 at a time upward or downward, or all at once when fewer than 20 are hidden. Removed lines carry a fine striped bar in the gutter and added lines a solid one, so the difference never depends on color. Lines are highlighted with Shiki like Code Block, and changed words inside a line are marked when the two lines are similar enough for that to help. The layout switches to split view when there is room, which is at least 900px by default. Files that are still streaming show live and can’t be decided yet. Files that changed on disk can be rejected but not accepted. Diffs over 400 changed lines wait behind Load diff, and their file-level actions keep working.

## Installation

### Step 1: Get HextaUI Pro

One payment unlocks every block, including future ones. [See pricing](https://hextaui.com/pricing).

### Step 2: Add the Pro registry to components.json

```json title="components.json"
{
  "registries": {
    "@hextaui-pro": {
      "url": "https://hextaui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
      }
    }
  }
}
```

### Step 3: Add your token

Create a token on your [account page](https://hextaui.com/account) and put it in `.env.local` as `HEXTAUI_PRO_TOKEN`.

### Step 4: Add the block

```bash
npx shadcn@latest add @hextaui-pro/diff-review
```

## Usage

### With the AI SDK

Turn edit tool calls into files, including input that is still streaming: a unified diff, a new file’s content, or Claude Code’s old_string and new_string. The summary goes in the chat and the review beside it, sharing one provider.

```tsx
"use client"

import { useChat } from "@ai-sdk/react"
import { getToolName, isToolUIPart, type UIMessage } from "ai"

import type { DiffFile } from "@/components/blocks/diff-review/diff"
import { DiffReview } from "@/components/blocks/diff-review/diff-review"
import { DiffSummary } from "@/components/blocks/diff-review/diff-summary"
import { DiffReviewProvider } from "@/components/blocks/diff-review/use-diff-review"

type Input = Record<string, string | undefined>

function editsOf(messages: UIMessage[]): DiffFile[] {
  return messages.flatMap((message) =>
    message.parts.flatMap((part): DiffFile[] => {
      if (!isToolUIPart(part)) return []
      const input = (part.input ?? {}) as Input
      const streaming = part.state === "input-streaming"
      switch (getToolName(part)) {
        case "editFile":
          return input.path ? [{ path: input.path, patch: input.diff ?? "", streaming }] : []
        case "writeFile":
          return input.path ? [{ path: input.path, after: input.content ?? "", streaming }] : []
        case "Edit":
          return input.file_path
            ? [{ path: input.file_path, before: input.old_string ?? "", after: input.new_string ?? "", streaming }]
            : []
        default:
          return []
      }
    })
  )
}

export function AgentWorkspace({ onApply }: { onApply: (files: DiffFile[]) => void }) {
  const { messages } = useChat()
  const files = editsOf(messages)

  return (
    <DiffReviewProvider
      files={files}
      onDecide={({ decision, changes }) => {
        if (decision === "accepted") onApply(files.filter((file) => changes.some((change) => change.path === file.path)))
      }}
    >
      <div className="grid h-svh lg:grid-cols-[28rem_1fr]">
        <aside className="overflow-y-auto p-4">
          <DiffSummary />
        </aside>
        <DiffReview />
      </div>
    </DiffReviewProvider>
  )
}
```

### Send line comments to the agent

onComment gets the file, the side, the line numbers and a diff excerpt, so you can send it as a follow-up message. Return the promise from sendMessage and each comment shows Sending… and then Sent to the agent.

````tsx
"use client"

import { useChat } from "@ai-sdk/react"

import type { DiffComment } from "@/components/blocks/diff-review/comments"
import type { DiffFile } from "@/components/blocks/diff-review/diff"
import { DiffReview } from "@/components/blocks/diff-review/diff-review"

function lines({ lines, side, startSide }: DiffComment) {
  const mark = (value: DiffComment["side"]) => (value === "old" ? "-" : "+")
  if (side !== startSide) return `${mark(startSide)}${lines.start} to ${mark(side)}${lines.end}`
  return lines.start === lines.end ? `${lines.start}` : `${lines.start}-${lines.end}`
}

export function ReviewWithFeedback({ files }: { files: DiffFile[] }) {
  const { sendMessage } = useChat()

  return (
    <div className="h-[36rem]">
      <DiffReview
        files={files}
        onComment={(comment) =>
          sendMessage({
            text: [
              `Feedback on ${comment.path}, ${comment.side === "old" ? "removed line" : "line"} ${lines(comment)}:`,
              "```diff",
              comment.excerpt,
              "```",
              comment.text,
            ].join("\n"),
          })
        }
      />
    </div>
  )
}
````

### Write what was accepted

applyDecisions rebuilds each file from the hunks you kept, using the original or the edited content. It also returns a patch of only the accepted hunks, and says when a file should be deleted or never created.

```tsx
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"

import { applyDecisions, type DiffDecisions, type DiffFile } from "@/components/blocks/diff-review/diff"
import { DiffReview } from "@/components/blocks/diff-review/diff-review"

export function ReviewThenWrite({
  files,
  writeFile,
  deleteFile,
}: {
  files: DiffFile[]
  writeFile: (path: string, content: string) => Promise<void>
  deleteFile: (path: string) => Promise<void>
}) {
  const [decisions, setDecisions] = React.useState<DiffDecisions>({})

  const finish = async () => {
    for (const file of files) {
      const result = applyDecisions(file, decisions)
      if (result.deleted) await deleteFile(file.path)
      else if (result.content !== undefined) await writeFile(result.path, result.content)
    }
  }

  return (
    <div className="flex h-[36rem] flex-col gap-3">
      <DiffReview files={files} decisions={decisions} onDecisionsChange={setDecisions} />
      <Button onClick={finish}>Write accepted changes</Button>
    </div>
  )
}
```

### A read-only diff

DiffView shows one file’s changes with the same highlighting, gutter bars and unchanged-line expansion, without review controls. It grows with its content, so put it inside a scrolling parent.

```tsx
import { DiffView } from "@/components/blocks/diff-review/diff-view"

export function VersionChanges({ previous, current }: { previous: string; current: string }) {
  return (
    <div className="flex h-96 flex-col overflow-hidden rounded-xl border">
      <div className="min-h-0 flex-1 overflow-y-auto">
        <DiffView before={previous} after={current} language="tsx" header path="app/page.tsx" />
      </div>
    </div>
  )
}
```

### From a git diff

parsePatch splits git diff or plain unified diff output into files, with renames, new, deleted and binary files.

```tsx
import { parsePatch } from "@/components/blocks/diff-review/diff"
import { DiffReview } from "@/components/blocks/diff-review/diff-review"

export function PullRequestReview({ gitDiff }: { gitDiff: string }) {
  return (
    <div className="h-[36rem] overflow-hidden rounded-xl border">
      <DiffReview files={parsePatch(gitDiff)} defaultView="split" />
    </div>
  )
}
```

## Anatomy

The parts you compose, from the outside in.

| Part | Description |
| --- | --- |
| `DiffReviewProvider` | Holds the files, the decisions and the undo history, so a summary in the chat and a review panel stay in sync. |
| `DiffReview` | The review surface: toolbar, file tree, the changes and the review bar with progress, navigation and bulk actions. |
| `DiffSummary` | A card for the chat: “Edited 4 files” with counts, each file with accept and reject, and bulk actions. |
| `DiffView` | A read-only diff of one file, for showing changes between versions. |
| `Comment threads` | Comments under a line or range, with author, time, delivery status, edit, delete and collapse. |
| `parsePatch, applyDecisions` | Read git diff output into files, and turn decisions back into file contents and an accepted-only patch. |
| `useDiffReview` | The shared state, for building your own controls inside the provider. |

## API reference

### DiffReviewProvider

DiffReview and DiffSummary take the same props when used on their own.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `files` | `DiffFile[]` | – | The changed files, in the order the agent edited them. |
| `decisions` | `Record<string, "accepted" \| "rejected">` | – | Controlled decisions by change id. Changes without an entry are pending. |
| `defaultDecisions` | `Record<string, "accepted" \| "rejected">` | – | Starting decisions when uncontrolled. |
| `onDecisionsChange` | `(decisions) => void` | – | Called with the next decisions after every action, including undo. |
| `onDecide` | `(event: DiffDecideEvent) => void` | – | Called once per action with the decision, its source (change, file, all or undo) and the changes it touched. Use it to write or revert files. |
| `comments` | `DiffComment[]` | – | Controlled comments. |
| `defaultComments` | `DiffComment[]` | – | Starting comments when uncontrolled. |
| `onCommentsChange` | `(comments: DiffComment[]) => void` | – | Called after a comment is added, edited, deleted or restored. |
| `onComment` | `(comment: DiffComment) => unknown` | – | Called when a comment is sent, and again with the same id when it is edited. Return a promise to show Sending… and Sent to the agent, or Couldn’t send with Retry if it rejects. |
| `author` | `{ name: string; image?: string }` | `{ name: "You" }` | Shown on new comments. |

### DiffFile

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `path` | `string` | – | The file’s path. When an agent edits the same path twice, both edits are listed. |
| `patch` | `string` | – | A unified diff of this file. Hunk headers without line numbers, CRLF and “No newline at end of file” are fine. |
| `before` | `string` | – | The original content. With after, the diff is computed for you and unchanged lines can be shown. |
| `after` | `string` | – | The edited content. On its own, it describes a new file. |
| `oldPath` | `string` | – | The previous path of a renamed file. |
| `status` | `"added" \| "deleted" \| "modified" \| "renamed"` | – | Worked out from the content when left out. |
| `language` | `string` | – | Shiki language id. Defaults to the file extension. |
| `binary` | `boolean` | – | Shows “Binary file not shown” and decides the file as a whole. |
| `streaming` | `boolean` | – | The agent is still writing this file. It updates live and can’t be decided yet. |
| `stale` | `boolean` | – | The file changed on disk after the edit. Accepting is turned off until you pass a fresh diff. |

### DiffReview

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `view` | `"auto" \| "unified" \| "split"` | – | Controlled layout. Auto is split when the diff area is at least 900px wide. Split falls back to unified below 600px. |
| `defaultView` | `"auto" \| "unified" \| "split"` | `"auto"` | Starting layout when uncontrolled. |
| `onViewChange` | `(view: "unified" \| "split") => void` | – | Called when someone picks a layout. |
| `advance` | `boolean` | `true` | After deciding with the keyboard, move to the next change that is still pending. |
| `largeDiffLines` | `number` | `400` | Files with more changed lines than this wait behind Load diff. |
| `className` | `string` | – | Give it a height, or place it in a flex column. The list scrolls inside. |

### DiffSummary

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onReview` | `(path?: string) => void` | – | Shows Review and makes each file open the review at that file. |
| `foldAfter` | `number` | `6` | Fold longer lists behind “Show 3 more files”. |

### DiffComment

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `path` | `string` | – | The file the comment is about. |
| `side` | `"old" \| "new"` | – | The side of the last line: old for a removed line, new for an added or unchanged one. |
| `startSide` | `"old" \| "new"` | – | The side of the first line. It differs from side when a range runs from removed into added lines. |
| `lines` | `{ start: number; end: number }` | – | Line numbers in the file on startSide and side. |
| `excerpt` | `string` | – | The selected lines in diff form, such as “-old” and “+new”, so the agent sees the code even after line numbers move. |
| `text` | `string` | – | What the reader wrote. |
| `id, createdAt, author` | `string, number, { name; image? }` | – | Filled in when the comment is created. |

### DiffView

Exported from diff-view.tsx. It has no scroll container of its own: it grows with its content and its change headers stick to the nearest scrolling parent, so place it in one, such as a min-h-0 flex-1 overflow-y-auto element.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `before` | `string` | – | The earlier content. |
| `after` | `string` | – | The later content. |
| `patch` | `string` | – | A unified diff, instead of before and after. |
| `language` | `string` | – | Shiki language id. Defaults to the extension of path. |
| `path` | `string` | `"file"` | Used for the language and the optional header. |
| `view` | `"unified" \| "split"` | `"unified"` | Split falls back to unified below 600px. |
| `wrap` | `boolean` | `false` | Wrap long lines. Split always wraps. |
| `header` | `boolean` | `false` | Show the path and +N / −N counts above the changes. |
| `className` | `string` | – | Classes for the root. |

### DiffDecideEvent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `decision` | `"accepted" \| "rejected" \| "pending"` | – | Pending when a decision was undone. |
| `source` | `"change" \| "file" \| "all" \| "undo"` | – | What the person did. |
| `changes` | `{ file: string; path: string; id: string }[]` | – | Only the changes whose decision actually changed. |

### applyDecisions(file, decisions, options?)

Returns { path, decision, content?, deleted, patch }. Pending changes count as rejected unless options.pending is "accepted".

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `content` | `string \| undefined` | – | The file after review, built from before or after. Undefined for binary files or when neither is known. |
| `deleted` | `boolean` | – | True when the file shouldn’t exist: an accepted deletion or a rejected new file. |
| `patch` | `string` | – | The accepted hunks only, renumbered so git apply works on the original file. |

## Keyboard

| Key | Action |
| --- | --- |
| `J` | Moves to the next change that is still pending. K moves back. |
| `N` | Moves to the next file. P moves to the previous one. |
| `Y` | Accepts the current change. ⌘↵ does the same. |
| `X` | Rejects the current change. ⌘⌫ does the same. |
| `⇧` `Y` | Accepts every pending change in the current file. ⇧X rejects them. |
| `⌘` `⇧` `↵` | Accepts every change that is ready. ⌘⇧⌫ rejects them. |
| `U` | Undoes the last decision, including bulk ones. ⌘Z does the same. |
| `↑` `↓` | Moves through the file tree. Enter jumps to the file, ← and → fold folders, and typing jumps to a file by name. |
| `Tab` | Moves into a change’s lines. Each change is one stop, and ↑ ↓ Home End move between its lines; in split view ← → switch sides. |
| `⇧` `↓` | Selects a range of lines. ⇧↑ extends it upward, and Esc clears it. |
| `Enter` | Opens the comment composer for the focused line or the selected range. C does the same. |
| `⌘` `↵` | Sends the comment from the composer. Esc closes it and keeps what you wrote for that line. |

## Accessibility

- The review is a region named “Review changes”. Each change is a group with a full name, such as “Change 2 of 9, app/page.tsx, lines 40–52, 3 lines added, 1 line removed, pending”.
- Decisions, bulk actions and undo are announced through a polite live region with what is left, for example “Accepted change 2 of 9 in app/page.tsx. 7 changes left.”
- Shortcuts only work while focus is inside the review. They are ignored in text fields, and letters in the file tree jump to files by name. After deciding with the keyboard, focus moves to the next pending change. After clicking, it moves to the Undo button in the same place.
- Added and removed lines are read as “Added:” and “Removed:”, so they don’t rely on color. Changed words are underlined in high contrast mode, and progress is also exposed as a progressbar.
- Folded changes are inert, so they are skipped by Tab and screen readers until you show them. With reduced motion, folding, counts and progress update without animation.
- Each change’s lines are one tab stop with roving focus, like a grid. The focused line shows a tint and a + in the gutter, and forced colors mode draws an outline instead.
- Opening the composer moves focus into it and the line stays highlighted. Esc returns focus to the line visibly. After sending or clicking away, focus goes back to the line without a focus indicator, so the next arrow key continues from there.
- Removed and added lines carry a striped or solid gutter bar as well as the − and + signs, and the bars stay visible in forced colors mode.
- Adding, editing, deleting and restoring comments are announced, and deleted comments can be restored for a few seconds.

## Built with

The free HextaUI components Diff Review is made from. Each one installs on its own.

- [Avatar](https://hextaui.com/docs/avatar) - User photos with an initials fallback, status badges and stacked groups that collapse into a count.
- [Button](https://hextaui.com/docs/button) - Buttons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- [Card](https://hextaui.com/docs/card) - A surface for grouping content, with three variants, edge-to-edge media, concentric radii and whole-card links.
- [Dropdown menu](https://hextaui.com/docs/dropdown-menu) - A menu of actions and options behind a button, with groups, submenus, checkbox and radio items, and shortcuts.
- [Empty](https://hextaui.com/docs/empty) - A placeholder for screens with nothing to show yet, with an icon, a message and the next action.
- [Input group](https://hextaui.com/docs/input-group) - An input with icons, text, buttons or a keyboard hint attached, sharing one border and focus ring.
- [Kbd](https://hextaui.com/docs/kbd) - Key caps for shortcuts that show the right symbols on every platform, read them out properly and press down with the real keys.
- [Number flow](https://hextaui.com/docs/number-flow) - Animated numbers where only the changed digits spin, with any Intl format and locale.
- [Popover](https://hextaui.com/docs/popover) - A floating panel anchored to a trigger that resizes smoothly with its content and follows the trigger’s direction.
- [Spinner](https://hextaui.com/docs/spinner) - A loading indicator with Apple-style ticks or a breathing ring that can wait before showing and stay long enough not to flicker.
- [Toggle group](https://hextaui.com/docs/toggle-group) - A row of toggles for one choice or many, with a fill that slides to the picked item, joined or spaced items and arrow-key focus.
- [Tooltip](https://hextaui.com/docs/tooltip) - A short hint on hover or keyboard focus that opens after a brief rest, switches instantly between neighbours and shows shortcuts.
- [Tree](https://hextaui.com/docs/tree) - Nested, expandable rows for files and hierarchies, with indent guides, connector lines, cascading checkboxes, typeahead and full keyboard support.

## Code

14 files, added to components/blocks/diff-review.
