Introduction
Clack is a library for building beautiful, interactive command-line prompts in Node.js. Created by Nate Moore (co-creator of Astro), it provides a set of composable prompt components with a polished terminal UI out of the box. Clack focuses on developer experience: prompts look professional, the API is minimal, and multi-step flows feel cohesive. Tools like the Astro CLI, SvelteKit, and Drizzle ORM use Clack for their interactive setup wizards.
What Clack Does
- Provides styled prompt components: text, password, select, multiselect, confirm, and group
- Renders spinners, progress indicators, and log messages with consistent styling
- Chains prompts into multi-step wizards with intro/outro framing
- Handles cancellation gracefully with SIGINT detection and cleanup
- Offers a core layer for building custom prompt components with full rendering control
Architecture Overview
Clack is split into two packages: @clack/prompts (high-level components) and @clack/core (low-level primitives). The core package manages terminal state, cursor movement, input handling, and ANSI rendering. Prompt components are state machines that transition between idle, active, and submitted states. The rendering engine uses a double-buffered approach to minimize flicker, redrawing only changed lines on each keystroke.
Self-Hosting & Configuration
- Install via npm:
npm install @clack/prompts - Import prompt functions individually for tree-shaking
- No configuration files needed; styling is built into the components
- Works in Node.js 16+ and Bun
- Use @clack/core to build custom prompt components with full terminal control
Key Features
- Consistent visual design across all prompt types with Unicode box-drawing characters
- Group prompts into logical sections with
group()for multi-step wizards - Spinner component for long-running operations with start/stop/update methods
- Cancellation handling with isCancel() check after each prompt
- Minimal API surface: each prompt is a single async function call
Comparison with Similar Tools
- Inquirer.js — The established choice with many prompt types and plugins; Clack offers a more modern look and smaller API
- Enquirer — Feature-rich with custom prompt types; Clack prioritizes visual consistency and simplicity
- Prompts — Lightweight alternative; Clack adds polished styling and multi-step flow support
- Commander.js — Argument parser, not a prompt library; Commander handles flags while Clack handles interactive input
- Ink — React-based terminal UI framework; Clack is simpler for standard prompt flows without React overhead
FAQ
Q: Can I customize the look of Clack prompts? A: The high-level @clack/prompts package has a fixed visual style. For custom rendering, use @clack/core to build prompt components with your own ANSI styling.
Q: Does Clack work with TypeScript? A: Yes. Clack is written in TypeScript and all prompt functions have full type definitions, including generic types for select options.
Q: How does Clack handle user cancellation (Ctrl+C)?
A: Each prompt returns a special cancel symbol when the user presses Ctrl+C. Use the isCancel() helper to detect this and exit gracefully.
Q: Which projects use Clack? A: Astro CLI, SvelteKit, Drizzle ORM, and several other developer tools use Clack for their interactive setup and configuration wizards.