Skip to content
AgentsFile write toolMenu

File write tool

A new file: the path in the header, then a file card with its name, size and first lines.

A created file card with size and first lines.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/tool-file-write.json

Usage

tsx
import { ToolFileWrite } from "@/components/ui/chatcn/tool-file-write"

<ToolFileWrite state="output-available" path={path} content={content} />
tsx
import { ToolFileWritePart, toolFileWriteRenderers } from "@/components/ui/chatcn/tool-file-write"

// One part straight from AI SDK or the chatcn contract
<ToolFileWritePart part={part} onApprove={approve} onDeny={deny} />

// Or map tool names to renderers for a whole message
renderToolPart(part, { ...toolFileWriteRenderers })

Props

PropTypeNotes
pathstring
contentstringThe written file
overwritebooleanSays Wrote instead of Created
previewLinesnumberDefault 12
stateToolDisplayStateThe ToolCall lifecycle: streaming, running, approval, output, error, denied, cancelled
approval, decisionApproval request and the user's answer, as on ToolCall
onApprove, onDeny, onRetrySame callbacks as ToolCall
errorTextReactNodeShown on output-error
durationMs, startedAtnumberOptional. Measured automatically when omitted
variant"card" | "inline"Inline sits on a trace rail
open, defaultOpen, onOpenChangeControlled or uncontrolled details

Keyboard

KeyAction
Enter, SpaceExpand or collapse the details
TabMove through the header, links, copy buttons and approval actions

Motion

  • Inherits ToolCall: the status glyph swaps with a 150 ms blur crossfade and details open over 200 ms.
  • Nothing inside the body animates. Under reduced motion everything snaps.