# Command output

> A command the agent runs: the log streams in, folds away on success, and stays open on failure.

Coding agents run commands constantly, and raw logs drown the conversation. This block shows the command, "running" with seconds that roll, and Stop, while the log streams underneath and follows the newest line. On success the spinner blurs into a check that draws itself, "running" morphs to "done", the time gains its tenths, Stop folds away as the chevron opens in, and the log folds away a beat later, leaving one tidy line. On failure "exit 1" rolls in red, the log stays open, and the first failing line is marked and scrolled into view.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/command-output.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/command-output
- Registry item (source): https://hairlineui.com/r/command-output.json

## Usage

```tsx
import { CommandOutput } from "@/components/command-output";

<CommandOutput command="pnpm test" status="running" lines={lines} startedAt={startedAt} onStop={stop} />
```

## With the AI SDK

```tsx
// Server: a tool that streams its log by yielding as it goes
const runCommand = tool({
  description: "Run a shell command in the project sandbox",
  inputSchema: z.object({ command: z.string() }),
  async *execute({ command }, { abortSignal }) {
    const startedAt = Date.now();
    const lines: string[] = [];
    const proc = sandbox.spawn(command, { signal: abortSignal }); // your sandbox
    for await (const line of proc.lines()) {
      lines.push(line);
      yield { status: "running", lines, startedAt };
    }
    const exitCode = await proc.exitCode;
    yield { status: exitCode === 0 ? "success" : "error", lines, exitCode, startedAt, endedAt: Date.now() };
  },
});

// Client: each yield updates the part's output; the last one is final
if (part.type === "tool-runCommand" && part.input?.command) {
  const out = part.state === "output-available" ? part.output : undefined;
  return (
    <CommandOutput
      command={part.input.command}
      status={part.state === "output-error" ? "error" : out?.status ?? "running"}
      lines={out?.lines ?? []}
      exitCode={out?.exitCode}
      startedAt={out?.startedAt}
      endedAt={out?.endedAt}
      onStop={stop} // from useChat: aborts the request, and the abort signal stops the process
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `command` | `string` | – | Shown after a muted "$". |
| `status` | `"running" \| "success" \| "error" \| "cancelled"` | – | Where the process is. |
| `lines` | `(string \| { text; level? })[]` | – | The log so far. ANSI colour codes are stripped; error-looking lines are marked unless you set level. |
| `exitCode` | `number` | – | Shown in red on failure. |
| `startedAt / endedAt` | `number` | – | A live timer while running, then the duration (1.8s, 2m 4s). |
| `onStop` | `() => void` | – | Shows Stop while running. |
| `open / onOpenChange` | `boolean / (open) => void` | – | Control the log yourself; by default it is open while running or failed. |

## States

- **running**: "$ pnpm test", a spinner, "running" with seconds that roll once a second, and Stop. Lines fade in and the log follows them unless you scroll up.
- **success**: The spinner blurs into a check that draws itself (380ms), "running" morphs to "done" and "1s" settles to "1.8s"; Stop folds away as the chevron opens in (420ms); the log folds away after 0.9s.
- **error**: "exit" morphs in and the code rolls in after it, in red. The log stays open, failing lines are tinted, and the first one scrolls into view.
- **cancelled**: A stop mark and "stopped", with the log folded. Focus moves from Stop to the chevron.

## What it handles

Coding agents run commands constantly, and raw logs drown the conversation. This block shows what ran, how long it took and whether it worked, and it opens the log up only when something failed.

- **The command and a live timer**: It shows “$ pnpm test”, the seconds rolling while it runs, and a Stop button.
- **The log follows the newest line**: It keeps following only while you are at the bottom, so you can scroll up and read.
- **It tidies away on success**: The log folds away and leaves one line with the command and its duration, such as 1.8s.
- **It stays open on failure**: The exit code shows in red, and the first failing line is marked and scrolled into view.
- **Cleaned-up output**: ANSI colour codes are stripped, and lines that look like errors are marked unless you set the level.
- **Stopped means stopped**: A cancelled command reads “stopped” and its log folds away.

## Replaces

a log viewer, a running timer, ANSI colour stripping, follow-the-newest-line scrolling, a pass and fail summary

## Where it fits

- **Coding agents**: Show a test run, a build or an install the agent started, without flooding the chat.
- **Ops and DevOps agents**: Deploy scripts and migrations that run on someone’s behalf.
- **Cloud IDEs and sandboxes**: Commands that run in a sandbox next to the code.
- **Build and deploy screens**: A step in a pipeline that shows its log only when it needs to.

## Notes

- The log is a role="log" region you can focus and scroll with the keyboard; only status changes are announced, never the ticking timer.
- It keeps following new lines only while you are at the bottom of the log.
- Colour is never the only signal: failing lines are also announced by the "Failed with exit code" status.
- Installs Number roll and Text morph. With reduced motion, the fold, rolls and the scroll to the error are instant.

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