Create interactive CLI prompts (Inquirer.js)
✓Works with OpenClaudeYou are a Node.js CLI developer building interactive command-line interfaces. The user wants to create interactive prompts using Inquirer.js to gather user input with validation, choices, and conditional flows.
What to check first
- Run
npm list inquirerto confirm Inquirer.js is installed (version 8+ recommended) - Verify Node.js version is 12+ with
node --version
Steps
- Install Inquirer.js with
npm install inquirer(ornpm install inquirer@latestfor v9+) - Import the Inquirer prompt function at the top of your CLI file using CommonJS or ES modules
- Define a prompt array with question objects, each containing
type,name,message, and optionallychoicesordefault - Use
inquirer.prompt()and chain with.then()orawaitto handle user responses - Add
validatecallbacks to enforce input rules (non-empty strings, number ranges, email format) - Use
whenconditionals to show/hide questions based on previous answers - Chain multiple
inquirer.prompt()calls or nest them in.then()blocks for sequential flows - Handle errors with
.catch()or try/catch blocks around async/await
Code
const inquirer = require('inquirer');
async function runInteractiveCLI() {
try {
// First prompt: basic questions
const answers = await inquirer.prompt([
{
type: 'input',
name: 'projectName',
message: 'Project name:',
default: 'my-app',
validate: (input) => input.length > 0 || 'Project name cannot be empty'
},
{
type: 'list',
name: 'framework',
message: 'Choose a framework:',
choices: ['React', 'Vue', 'Angular', 'Svelte']
},
{
type: 'confirm',
name: 'typescript',
message: 'Use TypeScript?',
default: false
},
{
type: 'checkbox',
name: 'features',
message: 'Select features:',
choices: ['ESLint', 'Prettier', 'Testing', 'CI/CD'],
validate: (choices) => choices.length > 0 || 'Select at least one feature'
},
{
type: 'password',
name: 'apiKey',
message: 'Enter API key:',
mask: '*'
},
{
type: 'number',
name: 'port',
message: 'Server port:',
default: 3000,
validate: (num) => (num > 1024 && num < 65535) || 'Port must be 1024-65535'
},
{
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related CLI Tools Skills
Other Claude Code skills in the same category — free to download.
CLI App Builder
Build CLI applications with Commander.js
CLI Progress Bar
Add progress bars and spinners to CLI
CLI Config Manager
Build CLI configuration management
CLI Help Generator
Generate help text and man pages
CLI Testing
Test CLI applications
CLI Packaging
Package CLI for npm/brew distribution
CLI Autocomplete
Add shell autocompletion to CLI tools
CLI Color Output
Add colored and formatted CLI output
Want a CLI Tools skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.