Terminal

Show command-line output and logs.
~/project$ pnpm test
312ms0
✓ src/utils.test.ts (5 tests) 23ms ✓ src/api.test.ts (12 tests) 156ms ✓ src/components.test.ts (8 tests) 89ms Test Files 3 passed (3) Tests 25 passed (25) Start at 10:23:45 Duration 312ms
<Terminal  command="pnpm test"  stdout={`✓ src/utils.test.ts (5 tests) 23ms✓ src/api.test.ts (12 tests) 156ms✓ src/components.test.ts (8 tests) 89msTest Files  3 passed (3)     Tests  25 passed (25)  Start at  10:23:45  Duration  312ms`}  exitCode={0}  durationMs={312}  cwd="~/project"/>

Raw terminal output was not designed for conversation. Shell results lose their ANSI colors, exit codes, and stderr separation the moment they land in a chat message. Terminal renders command output the way you would see it in a real shell, colored, structured, and auto-collapsed when it gets long, so it does not take over the conversation.

Role: Information. For displaying data without user input. See Design Guidelines for how component roles work.

Getting Started

Run this once from your project root.

npx shadcn@latest add @tool-ui/terminal

Render Terminal in your UI with tool-compatible props.

import { Terminal } from "@/components/tool-ui/terminal";export function MyComponent() {  return (    <Terminal      id="my-terminal-example"      command="ls -la"      stdout={`total 16drwxr-xr-x  3 user user 4096 Dec  3 10:23 .drwxr-xr-x 12 user user 4096 Dec  3 10:20 ..-rw-r--r--  1 user user  220 Dec  3 10:23 package.json`}      exitCode={0}      durationMs={45}      cwd="~/project"    />  );}

Registration tells assistant-ui which component to render when a tool returns command output. Without it, tool results appear as raw JSON.

// Backend toolimport { tool, jsonSchema } from "ai";const showTerminal = tool({  description: "Show a command result",  inputSchema: jsonSchema<{}>({    type: "object",    properties: {},    additionalProperties: false,  }),  async execute() {    return {      id: "terminal-1",      command: "pnpm test",      cwd: "~/project",      exitCode: 0,      durationMs: 1288,      stdout: "\u001b[32m✓\u001b[0m 42 tests passed",    };  },});// Frontend with assistant-uiimport { type Toolkit } from "@assistant-ui/react";import { Terminal } from "@/components/tool-ui/terminal";import { safeParseSerializableTerminal } from "@/components/tool-ui/terminal/schema";import { createResultToolRenderer } from "@/components/tool-ui/shared";export const toolkit: Toolkit = {  showTerminal: {    type: "backend",    render: createResultToolRenderer({      safeParse: safeParseSerializableTerminal,      render: (parsedResult) => (        <>            <Terminal {...parsedResult} />        </>      ),    }),  },};

Key Features

ANSI color support

Renders colored output exactly as it appears in your shell

Exit code display

Green for success (0), red for any non-zero code

Duration tracking

Badge showing how long the command took

Stdout/Stderr separation

Stderr rendered separately with distinct styling

Props

Core Props

Prop

Type

Metadata

Prop

Type

Display Options

Prop

Type

Standard Props

Prop

Type

Use ToolUI.LocalActions to compose external actions next to Terminal.

ANSI Color Support

Terminal automatically renders ANSI escape codes for colored output:

import { Terminal } from "@/components/tool-ui/terminal";const coloredOutput = "\x1b[32m✔\x1b[0m Success\n\x1b[31m✗\x1b[0m Error";<Terminal  id="my-terminal"  command="npm test"  stdout={coloredOutput}  exitCode={0}/>;

Common ANSI codes:

  • \x1b[32m - Green text
  • \x1b[31m - Red text
  • \x1b[33m - Yellow text
  • \x1b[36m - Cyan text
  • \x1b[1m - Bold text
  • \x1b[0m - Reset formatting

Exit Code Meanings

  • 0 - Success (green)
  • 1 - General error (red)
  • 2 - Misuse of shell builtins (red)
  • 126 - Command not executable (red)
  • 127 - Command not found (red)
  • 130 - Interrupted with Ctrl+C (red)
  • Any non-zero - Error (red)

Accessibility

  • ANSI colors maintain WCAG contrast ratios against both light and dark backgrounds
  • Screen readers announce the command, exit status, and output content
  • Collapsible sections are keyboard-accessible with proper ARIA attributes
  • Code Block: both show monospaced content, but CodeBlock is for source code while Terminal is for command execution results
  • Progress Tracker: for when you need real-time status updates during a long-running operation