# Thinking trace

> An expandable record of what an agent did: steps, reasoning, search or tool calls.

Shows an agent at work and keeps the record afterwards. While it runs a light sweeps across the header and the seconds roll up beside it; rows arrive as your stream reports them and the list eases taller to make room. Each step’s spinner blurs into a check that draws itself. When it settles the header doesn’t swap, it morphs: "Thinking 6s" becomes "Thought for 6s", "Searching the web" becomes "Searched the web", and the trace folds into that one line. On error the sparkle turns into an alert and it stays open so the failed step is visible.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/thinking-trace.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/thinking-trace
- Registry item (source): https://hairlineui.com/r/thinking-trace.json

## Usage

```tsx
import { ThinkingTrace } from "@/components/thinking-trace";

<ThinkingTrace
  variant="tools"
  status="running"
  startedAt={startedAt}
  steps={[
    { label: "Read", detail: "plans.ts" },
    { label: "Edit", detail: "PricingTable.tsx", additions: 74, deletions: 41 },
    { label: "Run", detail: "npm test", status: "running" },
  ]}
/>
```

## With the AI SDK

```tsx
import { useChat } from "@ai-sdk/react";
import type { UIMessage } from "ai";
import { ThinkingTrace } from "@/components/thinking-trace";

type Part = UIMessage["parts"][number];
type Reasoning = Extract<Part, { type: "reasoning" }>;

// Render a reasoning part as a trace of sentences.
function ReasoningTrace({ part, failed }: { part: Reasoning; failed: boolean }) {
  return (
    <ThinkingTrace
      variant="reasoning"
      status={failed ? "error" : part.state === "streaming" ? "running" : "done"}
      steps={part.text.split(/(?<=[.!?])\s+/).filter(Boolean).map((label) => ({ label }))}
    />
  );
}

// Render the sources an answer used as a search trace.
function SourcesTrace({ message, streaming }: { message: UIMessage; streaming: boolean }) {
  const sources = message.parts.filter((p) => p.type === "source-url");
  return (
    <ThinkingTrace
      variant="search"
      status={streaming ? "running" : "done"}
      steps={sources.map((s) => ({ label: s.title ?? s.url, detail: new URL(s.url).hostname, href: s.url }))}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `steps` | `ThinkingStep[]` | – | Rows so far: label, plus optional detail, href, icon, status, additions and deletions. |
| `variant` | `"steps" \| "reasoning" \| "search" \| "tools"` | `"steps"` | How the rows are drawn. |
| `status` | `"running" \| "done" \| "error" \| "cancelled"` | `"done"` | The state of the whole trace. |
| `startedAt` | `number` | – | Start time in ms. Shows a live timer and times the done label. |
| `duration` | `number` | – | How long it took in ms, if your stream reports it. |
| `label / doneLabel` | `string` | – | Override the running and settled headers. |
| `query` | `string` | – | Search query shown above the sources. |
| `more` | `number` | – | Shows "+N more" under the rows. |
| `open / defaultOpen / onOpenChange` | `boolean / boolean / (open) => void` | – | Control the expanded state yourself, or leave it automatic. |
| `onStepClick` | `(step, index) => void` | – | Makes rows without an href clickable, e.g. to show a tool’s output. |

## States

- **running**: A 1.4s sweep of light crosses the header and its seconds roll up once a second; the trace is open, the live step spins and the list eases to each new height (420ms).
- **done**: The header morphs to a summary, "Thought for 6s" (the timer stays as the answer) or "Ran 3 tools" (the timer folds away), and the trace folds shut 900ms later. The last spinner blurs into a check that draws itself.
- **error**: The sparkle blurs into a red alert and the header morphs to "Couldn’t finish"; it stays open with the failed step’s mark turned to a red cross and "Failed" opening beside it.
- **cancelled**: "Stopped", for when the user stops the agent.
- **step: pending / running / done / error**: Each row can carry its own status, e.g. a queued step or one tool call that failed.

## What it handles

An agent’s work earns trust when it is visible, and gets in the way when it takes over the page. This shows the steps while they run, folds into one line when done, and keeps the record a click away.

- **Steps arrive as your stream reports them**: Rows are added as they come and the list eases taller to make room.
- **Four ways to draw the rows**: Plain steps, reasoning text, search results with sources, or tool calls with file changes.
- **It folds into a summary**: “Thinking 6s” becomes “Thought for 6s”, and the trace folds into that one line.
- **Failures stay visible**: On error it stays open, shows “Couldn’t finish” and marks the step that failed.
- **Rows can link or act**: Rows can carry a link, or call onStepClick, for example to show a tool’s output.
- **Open state you control**: Leave it automatic, or control it yourself. Folded rows are inert so links inside can’t be tabbed to.

## Replaces

a collapsible reasoning panel, a step list, a live timer, search result rows, tool call rows, an error state

## Where it fits

- **Reasoning models**: Show the steps a model took before it answered.
- **Agents with tools**: A record of searches, file reads and tool calls.
- **Research assistants**: The queries run and the sources found.
- **Trust and debugging**: Keep what the agent did one click away after it finishes.

## Notes

- The header is a button with aria-expanded. A status region beside it announces the label and then the summary ("Thought for 6s"), never the ticking timer.
- Collapsed rows are inert, so links inside a folded trace can’t be tabbed to.
- Installs Number roll and Text morph. With reduced motion the sweep, spinners, rolls and row entrances stop; the trace still opens and closes.
- Long labels and file paths truncate instead of wrapping.

License: MIT (https://hairlineui.com/license#components)
