# Chain of Thought

A collapsible list of the model's intermediate reasoning steps.

- Category: AI & Agents
- Page: https://wunderui.com/components/chain-of-thought
- Tier: Core and Pro

## Install

Chain of Thought ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { ChainOfThought, ChainOfThoughtStatus } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { ChainOfThought } from "@wunderui/react"

export function Reasoning({ running }: { running: boolean }) {
  return (
    <ChainOfThought
      status={running ? "running" : "completed"}
      steps={[
        "Opened Q3-report.pdf.",
        "Read the revenue dashboard.",
        "Wrote the summary.",
      ]}
    />
  )
}
```

Expected result: You see a bordered row with a sparkles icon and Thought for a few seconds. It starts closed, so press it to show three steps, and while running the text reads Thinking.

## When to use

### Use Chain of Thought for

- The steps an agent took, folded under its answer in a chat
- A live run whose steps arrive one by one and can be folded away
- A short process summary a person may want to check

### Use something else

- [Chat Tool](https://wunderui.com/components/chat-tool) for one tool call with its status and result
- [Agent Plan](https://wunderui.com/components/agent-plan) for the steps an agent plans to take, before it takes them
- [Collapsible](https://wunderui.com/components/collapsible) for any other show-more panel that is not a list of steps

## Keyboard

The toggle is a native button, so the browser handles focus and activation. The steps are text and take no focus.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the toggle and away from it. Focus shows as an indigo border with a 2 px ring. |
| `Enter` or `Space` | Opens or closes the steps. `aria-expanded` follows. |

A closed panel is inert, so nothing inside it can be reached or read out. There is no arrow-key navigation, and a status change does not move focus.

## Behavior

What the list does with its state, its content, assistive technology and motion.

- **Open state:** The open state is internal and the default is read once, when the component mounts. To start a new run open, give the component a new key.
- **Header and status:** Without a status the label and icon are fixed. With one (running, completed, failed or interrupted) both follow it and the box is busy only while running, and your own label replaces the text.
- **Steps:** Steps are an array of strings, rendered as text lines with a bullet. They are plain divs, so a screen reader announces no list, and entries are keyed by position, so append and do not reorder.
- **Growing list:** Adding a step while the panel is open makes it taller at once, without a transition. The panel stays mounted when closed, so steps that arrive while it is folded are there when it opens.
- **Live region:** The component has no live region, so a status change is not announced by itself. Add a status line that names the current step and the outcome, or keep the list in the chat log.
- **Toggle semantics:** The toggle is a button that reports whether it is expanded, named by its label. While closed, the panel is inert: nothing in it takes focus or is read out.
- **Motion:** The chevron turns and the running loader spins. The panel opens with the same smooth height transition the Collapsible uses.
- **Reduced motion:** With reduced motion the panel opens at once, the chevron turns at once and the loader stands still. The header text still says Thinking.

## Anatomy

- `ChainOfThought`: The bordered box that holds the toggle and the steps. It keeps its open state itself, is marked busy while running and turns red when failed.
- `Toggle`: A native button that fills the first row and reports whether the panel is expanded. Its name is the label, Thought for a few seconds by default, or the status text or your own label.
- `Icon`: A 14 px decorative icon before the label: Sparkles by default and when completed, a turning loader while running, a warning triangle when failed, a ban when interrupted.
- `Label`: The header text. Without a status it is Thought for a few seconds, and with one it reads Thinking, Thought for a few seconds, Thinking failed or Thinking stopped, unless you pass your own.
- `Chevron`: Points down when closed and turns 180 degrees when open.
- `Steps`: The panel under the toggle, with a top border and 16 px padding. It stays mounted, grows and shrinks smoothly, and is inert while closed.
- `Step`: One entry of the steps: a small bullet and a line of text. It is a plain div, not a list item, and it wraps when long.

## Best practices

### When to use

- Use ChainOfThought to fold the steps an agent took under its answer. For one tool call and its result use Chat Tool, and for steps an agent plans to take, use Agent Plan.

### Do

- Show what the agent did, in short past-tense lines such as Opened Q3-report.pdf, not invented reasoning. People read the list to check the work.
- Keep it closed, the default, so the answer comes first. Open it by default only where the steps are the content, for example while a run is live.
- Set the status so the header says where the run is, and announce it elsewhere too, with a status line or the chat log. The component announces nothing.
- Keep one thought per entry and write plain text. Entries render as text, so markup and links show as characters.
- Once the run is completed, pass a measured time as the label, like Thought for 12 seconds. The default text is a placeholder for when you have no time.

### Don't

- Don't use failed for a step that only returned an empty result. It is for a run that did not finish, and the cause and next step belong in a message outside the list.
- Don't hide a failure in the list. A failed step needs a visible message with the step and the cause, outside the folded panel.
- Don't put required information or the only action in a closed list. What people must read or do belongs outside it.

## API reference

### ChainOfThought

| Prop | Type | Default | Description |
|---|---|---|---|
| steps* | string[] |  | The steps, one short line of text each, in order. They render as text, so markup in a string shows as characters. Append to the end while a run is live; entries are keyed by position. |
| className | string |  | Extra classes for the outer box, for example `w-full` when it sits in a flex column that aligns its children to the start. |
| defaultOpen | boolean | false | Whether the list starts open. It is read once when the component mounts; a later change has no effect. Give the component a new `key` to start it open or closed again. |
| label | React.ReactNode |  | Replaces the header text of any status, for example `Thought for 12 seconds`. A node is allowed; keep it short, it is the name of the toggle. |
| status | "running" \| "failed" \| "completed" \| "interrupted" |  | Where the run is: `running`, `completed`, `failed` or `interrupted`. It changes the header text and icon, sets `aria-busy` while `running` and turns the box red when `failed`. Without it the header keeps the fixed `Thought for a few seconds`. |

## Examples

### Content: a few short steps, long steps that wrap, many steps

### Status: running, completed, failed, interrupted

### Placement: on its own, or folded above the answer

### Inherited size and a fixed width

## In context

### Live run: steps arrive one by one, a status line names the current one

Press Run again. The header says Thinking… while steps arrive, and because the component has no live region, the line above the list is what gets announced.

### Conversation: the steps folded above the answer, the actions under it

Tab reaches the toggle, then the four actions. Enter or Space on the toggle opens the steps, and the open state stays as the person left it.

### Outcome: a run that finished, was stopped or failed

The list keeps the steps that happened and its header says how the run ended. The reason and next step appear outside it, in a visible status line with a button to start again.

## For AI agents

`get_component("chain-of-thought")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
