If you're building a coding agent UI, you need a diff review component sooner or later. The agent says "here's what I want to change", and somebody has to look at it before it touches the codebase. I built one as part of Detent and made it a free shadcn component. This post is how to drop it into your project and wire it to an agent.
Why not a <pre> with red and green lines?
That's where everyone starts, and it falls apart fast.
Line numbers drift the moment a hunk has more additions than deletions. You want to accept one hunk and reject another, so now every hunk needs its own state. The agent streams, and the whole panel jumps as lines come in. Then someone asks for a split view. None of that is the product you're actually building.
Install it
It's one command, and the code lands in your project like any other shadcn component, so you can change whatever you want:
npx shadcn@latest add https://detentui.com/r/diff
You get components/detent/components/diff/DiffReview.tsx and a few small helpers next to it. It picks up your shadcn theme. The only package it pulls in is motion.
Wire it to an agent
The component wants the change as hunks. A hunk is a chunk of the file, with each line marked ctx, add or del. o and n are the line numbers it starts at in the old and new file.
The other prop that matters is shown: how many lines are visible right now. That's the whole streaming story. Bump it as lines arrive and the component animates them in.
I don't want you to need an API key to try this, so here a timer plays the agent:
'use client'
import { useEffect, useState } from 'react'
import { DiffReview, type Hunk } from '@/components/detent/components/diff/DiffReview'
const hunks: Hunk[] = [
{
id: 'limits',
scope: 'LIMITS',
o: 12,
n: 12,
lines: [
['ctx', 'export const LIMITS = {'],
['del', ' windowDays: 30,'],
['add', ' windowDays: 45,'],
['ctx', '}'],
],
},
{
id: 'approval',
scope: 'needsApproval(order)',
o: 41,
n: 41,
lines: [
['ctx', 'function needsApproval(order: Order) {'],
['del', ' return order.total > 1000'],
['add', ' return order.total > LIMITS.approvalOver'],
['ctx', '}'],
],
},
]
const total = hunks.reduce((n, h) => n + h.lines.length, 0)
export default function AgentChange() {
const [shown, setShown] = useState(0)
useEffect(() => {
const t = setInterval(() => setShown((s) => (s < total ? s + 1 : s)), 120)
return () => clearInterval(t)
}, [])
return (
<DiffReview
title="Apply the Q3 refund rules"
file="src/billing/refunds.ts"
hunks={hunks}
shown={shown}
onApply={(verdicts) => console.log(verdicts)}
/>
)
}
With a real model, hunks comes out of a tool call (something like a proposeEdit tool in the AI SDK) and shown follows the stream. The component doesn't care where the lines come from.
What the reviewer sees
While the agent writes, lines drop into their hunk one at a time. The panel doesn't jump, which is harder to get right than it sounds.
When it's done, every hunk waits for a decision. You can click Accept or Reject, or stay on the keyboard: A accepts, R rejects, S flips between unified and split. Long lines read much better in split.
When you apply, onApply hands you one verdict per hunk:
{ limits: 'accepted', approval: 'rejected' }
Write the accepted hunks to disk. Send the rejected ones back to the agent, so its next attempt knows what not to do.
If you want your own controls, say a "Review next" button inside the chat, pass a ref. It exposes next(), prev(), accept(), reject(), toggleView() and apply().
Is it worth it?
Honestly, you can build this yourself. It just takes longer than it looks. The component is well over a thousand lines, mostly for the boring parts: keeping line numbers straight, the split view, and streaming that doesn't shake the page. If your product is the agent and not the diff viewer, the snippet above is all the code you need to own.
Diff review is free and part of Detent, a set of shadcn components I'm building for apps with AI agents in them. If you try it in your agent, I'd like to see it.

Top comments (0)