File Diff

Shows what an agent changed in a file: added, removed and context lines with old and new numbers and syntax colors, rows that stream in while the edit lands, running plus and minus counts, a copy button and an optional collapse once complete.

Preview

File Diff preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/file-diff
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

file
ReactNode
—
lines
FileDiffLine[]
—
status?
"complete" | "streaming"
streaming
open?
boolean
—
defaultOpen?
boolean
true
onOpenChange?
((open: boolean) => void)
—
collapseOnComplete?
boolean
true
maxHeight?
number
220
language?
"text" | "bash" | "diff" | "json" | "tsx" | "typescript"
typescript
copyText?
string
—
onCopy?
(() => void | Promise<void>)
—
className?
string
—

Composition

Show the patch inside the result of the tool call that edited the file.

ToolResult
└── ToolResultOutput
    └── FileDiff

Note: Code Block shares the same syntax colors for each line. Tool Result wraps the patch in the run that made it. Agent Activity lists the edit in order with the rest of the run.

How it works

A diff tells someone what an edit did, or is about to do, to a file. Keep original and updated line numbers side by side, and let the size of the change and whether it has landed be readable in one glance.

Updated