Skip to main content
This guide is for extension authors building interactive terminal UI (TUI) components inside Atomic. By the end of this page, you can show custom dialogs and overlays with ctx.ui.custom(), style components with the active theme, and reuse Atomic’s built-in patterns for selectors, loaders, widgets, status indicators, footers, and custom editors. For low-level rendering primitives (TuiMainScreen, TuiAltScreen, Component, Focusable, matchesKey, and layout primitives), see @bastani/atomic-tui. For full extension contracts (ToolBlock, ExtensionCustomComponent, advanced ctx.ui.custom() options, theme invalidation, debug logging, and host-native dialogs), see TUI API reference.

Before you begin

Before you build custom TUI components, confirm that you have:
  • An Atomic extension entry point (see Author extensions).
  • An interactive terminal session (ctx.mode === "tui"). Guard terminal-only calls such as ctx.ui.custom() with ctx.mode === "tui" so your extension degrades cleanly in headless Remote Procedure Call (RPC) or print mode (see Handle extension UI over RPC).

Show a custom component with ctx.ui.custom()

Pass a synchronous or async component factory (ExtensionCustomComponent | Promise<ExtensionCustomComponent>) to ctx.ui.custom(). The factory receives (tui, theme, keybindings, done), and ctx.ui.custom() resolves with the value you pass to done(). Components can also implement dispose?(): void for cleanup when dismissed. The following extension hook opens a custom component on session start and shows the chosen value in a notification:
The following table lists the common options accepted by ctx.ui.custom(factory, options?): For advanced options (purpose, handlesInternalUiAction, deferInlineCustomUiFocus, reserveTranscriptRows, OVERLAY_ACTIVE_ROW_MARKER, and HostCustomUiState), see Custom component options.
Don’t rely on host process globals from render() or handleInput(), and pass only JSON-safe values to done(). Return true for consumed viewport keys or overlay mouse events and false to let the transcript handle them. Non-overlay components leave mouse scrolling and selection with the transcript.

Show floating overlays

Overlays render components on top of existing content without clearing the screen. To mount a component as an overlay, pass { overlay: true } to ctx.ui.custom():
To control size, position, responsive visibility, and focus, pass overlayOptions (either a static object or a () => OverlayOptions function) and onHandle:

Overlay focus and lifecycle

A focused visible overlay keeps input ownership across temporary non-overlay UI: if it opens another inline ctx.ui.custom() component, that component receives input while active, and the overlay reclaims input when it closes. Call handle.unfocus() to release input to the fallback target, or handle.unfocus({ target }) to focus a specific component (or null for none). Atomic disposes of overlay components when they close, so always create fresh instances instead of reusing closed references:
See overlay-qa-tests.ts for examples covering anchors, margins, stacking, responsive visibility, and animation.

Use built-in primitives

Import layout and content primitives from @bastani/atomic-tui (provided by Atomic without an extra install):
The following table summarizes the most common layout primitives: See @bastani/atomic-tui built-in components for full constructor signatures, options, and additional primitives (Input, Editor, Loader, CancellableLoader, TruncatedText, WindowedContainer, VStack, HStack, ScrollView).

Build a custom component

Implement render(width), invalidate(), and optional handleInput(data) to build a custom interactive component. Always keep every rendered line within width columns using truncateToWidth() or wrapTextWithAnsi():
Mount the component inside a slash command handler and call tui.requestRender() whenever handleInput() updates state:
Confirm that running /pick in an interactive session opens the selector, moves focus with the arrow keys, and notifies you of the chosen branch on Enter.

Style components with the active theme

Always use the theme passed to your callback (ctx.ui.custom, ctx.ui.setWidget, renderCall, or renderResult) instead of importing a theme singleton directly:
The following table lists the foreground tokens accepted by theme.fg(color, text): Background tokens accepted by theme.bg(color, text) are selectedBg, userMessageBg, customMessageBg, toolPendingBg, toolSuccessBg, toolErrorBg, scrollbarThumb, and searchMatchBg. For Markdown components, call getMarkdownTheme() from @bastani/atomic:
If your component stores pre-baked themed strings in child components, rebuild them in invalidate() so live theme switches take effect. See Invalidation and theme changes.

Reuse common UI patterns

Prefer these built-in Atomic components over writing interactive controls from scratch.

Selection dialog (Selector)

Use Selector from @bastani/atomic for searchable, keyboard- and mouse-accessible pickers (the same component behind /model, /login, /thinking, /trust, and ctx.ui.select and confirm):
Navigation supports Up / Down (wrapping), PageUp / PageDown, Home / End (when search is off), Enter, Right (when search is empty), Esc (clears search, then cancels), Ctrl+C, mouse click, and wheel scrolling. Without a search box, ? opens key help and j / k navigate. The following table lists the key SelectorOptions and item fields: For live updates, call selector.setItems(nextItems) and tui.requestRender(); selection stays on the same id when still enabled and matching. Call selector.setNotice({ text, tone }) for a one-line status under the list, and call selector.retrySelection() if an async onSelect or onConfirm callback fails and should re-enable input. For headless testing (SelectorState, selectorHintEntries) and UserMessageSelectorComponent, see Selector helpers.

Bare list (SelectList)

Use SelectList from @bastani/atomic-tui when you need a minimal list inside your own layout (such as custom autocomplete rows) framed with DynamicBorder:
See preset.ts and tools.ts for working examples.

Cancellable loader (BorderedLoader)

Use BorderedLoader for cancellable async operations where Esc aborts the request:
See qna.ts and handoff.ts for working examples.

Settings toggles (SettingsList)

Use SettingsList from @bastani/atomic-tui with getSettingsListTheme() from @bastani/atomic:
See tools.ts for a full example.

Status indicator

To display or clear persistent mode indicators in the footer, call ctx.ui.setStatus():
See status-line.ts, plan-mode/index.ts, and preset.ts.

Customize the working indicator

To customize the inline Working indicator shown from accepted prompt submission through response streaming, call ctx.ui.setWorkingIndicator():
By default, Atomic shows a one-cell ∀ pulse beside a turn status message in a standalone row (custom editors can embed it in their top border with embedWorkingStatus: true). NO_COLOR disables colors and text styles, and ATOMIC_REDUCED_MOTION=1 freezes the built-in pulse (custom frames and intervals render verbatim). Working appears during prompt startup and response streaming and disappears on completion, failure, or a no-turn result. Automatic retry, fallback, and compaction loaders use their own built-in indicators and take precedence; successful mid-turn compaction restores Working automatically. See working-indicator.ts for a complete example.

Editor widgets

To display persistent content above or below the input editor (such as todo lists or progress panels), call ctx.ui.setWidget():
To react when the host clears a widget during a UI reset, subscribe with ctx.ui.onWidgetRelease(key, listener) when available (replacing a widget with another factory doesn’t trigger release). For ordinary updates, mutate your component state and call requestRender() instead of re-registering setWidget().

Scrollable widgets

Pass scroll: { maxHeight: 6 } (or { maxHeight: 10, maxHeightFraction: 1 / 3 } to scale with live terminal rows) to give a widget its own fullscreen viewport with mouse-wheel scrolling and a one-column overflow scrollbar. Render the full content instead of a pre-clipped slice:
getScrollRequest and onScroll are optional, and installReactiveWidget accepts the same scroll options. Keep version unchanged during ordinary content updates so user wheel scrolling stays intact. Native wheel scrolling requires fullscreen mode and a mouse-capable terminal. See plan-mode/index.ts for a complete example. To replace the footer and read live Git branch and extension statuses from footerData, call ctx.ui.setFooter():
ctx.ui.getFooterDataProvider() exposes the same read-only provider to embedded extension UIs. For a viewer showing a different working directory (viewerCwd), pass viewerCwd to both footerData.onBranchChange(listener, viewerCwd) and footerData.getGitBranch(viewerCwd), and call the returned unsubscribe function on disposal (never call the parent provider’s dispose()). An unsubscribed getGitBranch(viewerCwd) lookup is transient and doesn’t retain a branch watcher. See custom-footer.ts for a complete example.

Custom editor (Vim mode)

Extend CustomEditor (not base Editor) to customize editing while keeping Atomic’s app keybindings (Esc to abort, Ctrl+D to exit, model switching, and autocomplete):
Pass undefined to ctx.ui.setEditorComponent(undefined) to restore the default editor. Custom editors exposing setAutocompleteMaxVisible() inherit the active autocompleteMaxVisible setting. The following table lists the CustomEditorOptions accepted by new CustomEditor(tui, theme, keybindings, options?):
setEditorComponent, setFooter, setHeader, onTerminalInput, and addAutocompleteProvider require synchronous terminal callbacks and run only in single-process TUI hosts (they warn and don’t run in default isolated interactive mode). See Extension UI.
See modal-editor.ts for a full example.

Attached composer

When an extension or custom SDK host embeds a secondary chat editor, use applyAttachedComposer(style, label, placeholder, lines) to style its rules with accent color, add a bold label to the top rule, and display a dim placeholder while empty:
applyAttachedComposer() replaces plain ─ rules and editor overflow rules (↑ N more / ↓ N more). For the bottom border, it scans upward from the end of lines to find and recolor the last rule line even when non-rule lines (such as a hint or autocomplete menu) follow it. It inserts placeholder only when the editor has a single empty prompt row (the bottom rule is at line index 2 and line 1 is bare ❯). Long labels truncate with …, and when the terminal is narrower than INPUT_LABEL_MIN_COLUMNS (40) columns, the rules render without the label. Pass undefined for label or placeholder to omit either. For buildInputLabel() and applyInputLabelToEditorTopRule(), see Input label helpers.

Key rules

  • Use theme from callbacks: Don’t import a theme singleton directly; use the theme passed to ctx.ui.custom(), setWidget(), renderCall(), or renderResult().
  • Type DynamicBorder callbacks explicitly: Write (s: string) => theme.fg("accent", s).
  • Call tui.requestRender() after state changes inside handleInput().
  • Prefer built-in components: Selector, SelectList, SettingsList, and BorderedLoader cover most interactive UI cases.

Troubleshooting

Use the following table to resolve common TUI component issues:

Examples and next steps

Browse complete working extensions in the repository:

TUI API reference

Look up ToolBlock, ExtensionCustomComponent, theme invalidation, debug logging, and host-native UI contracts.

@bastani/atomic-tui

Explore low-level rendering, mouse events, IME focus, and keyboard utilities.