Skip to content
AgentsCode search toolMenu

Code search tool

A grep or glob: the pattern and match count in the header, matches grouped by file with file:line and the match highlighted.

Matches grouped by file with the match highlighted.

Installation

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

Usage

tsx
import { ToolSearchCode } from "@/components/ui/chatcn/tool-search-code"

<ToolSearchCode state="output-available" query="getProjects(" matches={matches} />
tsx
import { ToolSearchCodePart, toolSearchCodeRenderers } from "@/components/ui/chatcn/tool-search-code"

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

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

The part renderer also reads ripgrep style text (path:line:text) and glob results that are only paths.

Props

PropTypeNotes
querystringPattern or glob
regexbooleanHighlight with a regular expression
matches{ path, line?, text? }[]Paths only for globs
initialFilesnumberFiles before Show all. Default 6
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.