Code Block

Displays code while an agent is still writing it: highlighting for TypeScript, TSX, JSON, bash, diff or plain text, line numbers, emphasis on chosen lines, a height cap that trails new output, optional wrapping and a copy button that confirms.

Preview

Code Block preview width

Install

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

$ bunx --bun shadcn add @karaui/code-block
@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

code
string
—
language?
"text" | "bash" | "diff" | "json" | "tsx" | "typescript"
typescript
filename?
ReactNode
—
status?
"complete" | "streaming"
complete
showLineNumbers?
boolean
true
highlightLines?
number[]
[]
maxHeight?
number
280
wrap?
boolean
false
copyable?
boolean
true
onCopy?
(() => void | Promise<void>)
—
className?
string
—

Composition

Put the generated code inside whichever response decides when streaming starts and stops.

StreamingResponse
└── CodeBlock

Note: File Diff marks which lines were added or removed. Tool Result frames returned code as the output of a run. Streaming Response hosts code alongside prose in a full answer.

How it works

Code from a model arrives line by line, unlike a snippet pasted into docs. It has to stay legible mid-stream, keep its highlighting intact and give people one obvious way to copy the finished file.

Updated