Command-line interface for interactive component management. The shadcn CLI provides 12 commands for initializing projects, adding components, viewing registry contents, checking for updates, and more.
Initializes a new project with shadcn/ui configuration. Installs dependencies, adds the cn utility function, configures Tailwind CSS, and sets up CSS variables for the project.
shadcn init [options]Description: Sets up a new project with all necessary configuration for shadcn/ui components.
What it does:
components.json configuration filecn utility function for className mergingOptions:
-c, --cwd <dir> - Set working directoryExample:
npx shadcn initExit Codes:
0 - Success1 - General error (e.g., package manager not found, network error)2 - Configuration error (invalid existing components.json)4 - Validation error (invalid user input)Agent Usage: For non-interactive use, ensure components.json exists or use programmatic API to create configuration. The command will fail if run in a directory that already has a valid components.json unless you're updating it.
Edge Cases:
components.json already exists, the command may prompt to update or overwriteCreates a new project from scratch using a custom design system. Opens a website where you can build your custom design system and choose your framework.
shadcn create [options]Description: Launches the project creation wizard for building a new project with shadcn/ui from the ground up.
What it does:
Example:
npx shadcn createAgent Usage: This command requires browser interaction and is not suitable for programmatic use. Use init for programmatic setup. The command will attempt to open a browser; if this fails, it may display a URL to visit manually.
Exit Codes:
0 - Success (browser opened or URL displayed)1 - General error (browser launch failed, network error)Adds components to your project. The add command fetches components from registries and installs all required dependencies.
shadcn add [component...] [options]Description: Installs one or more components into your project with automatic dependency resolution.
What it does:
Arguments:
component - Component name(s) to add (optional for interactive mode). Can be:
button (uses default registry)@shadcn/buttonbutton card dialogOptions:
-c, --cwd <dir> - Working directory-a, --all - Install all available components (interactive selection)-y, --yes - Skip confirmation prompts (required for non-interactive use)-o, --overwrite - Overwrite existing files without prompting-p, --path <path> - Custom installation path (overrides components.json aliases)Examples:
# Interactive component selection
npx shadcn add
# Add single component
npx shadcn add button
# Add multiple components
npx shadcn add button card dialog
# Add from custom registry
npx shadcn add @acme/special-button
# Add with overwrite (non-interactive)
npx shadcn add button --yes --overwrite
# Add to custom path
npx shadcn add button --path src/components/custom
# Add all components (interactive)
npx shadcn add --allExit Codes:
0 - Success1 - General error (network, file system, etc.)2 - Configuration error (missing components.json)3 - Registry error (item not found, network error, authentication failure)4 - Validation error (invalid component name, circular dependency)Agent Usage: Always use --yes flag to skip prompts. Always specify component names explicitly for programmatic use. Use --overwrite if you want to update existing components. Check exit codes to handle errors appropriately.
Edge Cases:
--overwrite is not used, command will prompt (use --yes --overwrite to skip)Error Handling Example:
# Check if command succeeded
if npx shadcn add button --yes --overwrite; then
echo "Component added successfully"
else
exit_code=$?
case $exit_code in
2) echo "Error: components.json not found. Run: npx shadcn init" ;;
3) echo "Error: Registry error. Check component name and registry configuration" ;;
4) echo "Error: Validation error. Check component name format" ;;
*) echo "Error: Unknown error (exit code: $exit_code)" ;;
esac
fiChecks for updates against the registry. Compares your local components with their registry versions to detect changes and updates.
shadcn diff [component] [options]Description: Shows differences between local components and registry versions.
What it does:
Arguments:
component - Specific component to check (optional). If omitted, checks all installed components.Options:
-c, --cwd <dir> - Working directoryExamples:
# Check all components
npx shadcn diff
# Check specific component
npx shadcn diff button
# Check component from specific registry
npx shadcn diff @shadcn/buttonExit Codes:
0 - Success (no differences found or differences displayed)1 - General error (file read error, network error)2 - Configuration error (missing components.json)3 - Registry error (component not found in registry)Agent Usage: Use this to detect if local components have been modified and need updates or if customizations exist. The command outputs a diff format that can be parsed programmatically.
Edge Cases:
Views items from the registry. Displays component information including description, type, files, and code.
shadcn view [items...] [options]Description: Fetches and displays detailed information about registry items.
What it does:
Arguments:
items - Registry item(s) to view (e.g., @shadcn/button). Required. Can specify multiple items.Options:
-c, --cwd <dir> - Working directoryExamples:
# View single item
npx shadcn view @shadcn/button
# View multiple items
npx shadcn view @shadcn/button @shadcn/card
# View from custom registry
npx shadcn view @acme/special-button
# View without registry prefix (uses default)
npx shadcn view buttonExit Codes:
0 - Success1 - General error2 - Configuration error (missing components.json)3 - Registry error (item not found, network error)Agent Usage: Use programmatic getRegistryItems or view_items_in_registries MCP tool for structured data access. CLI output is formatted for human reading and may be difficult to parse programmatically.
Edge Cases:
Searches items from registries using fuzzy matching. Finds components based on name and description.
shadcn search <registries...> [options]
shadcn list <registries...> [options] # aliasDescription: Searches for components in specified registries.
What it does:
Arguments:
registries - Registry names or URLs to search (e.g., @shadcn, @acme). Required. Must start with @ for namespace-based registries.Options:
-c, --cwd <dir> - Working directory-q, --query <query> - Search query string (optional - omit to list all items)-l, --limit <number> - Maximum number of items to display (default: 100, max: 1000)-o, --offset <number> - Number of items to skip for pagination (default: 0, min: 0)Examples:
# List all components from @shadcn registry
npx shadcn search @shadcn
# Search for specific component
npx shadcn search @shadcn --query button
# Search with query (alternative)
npx shadcn search @shadcn -q "input form"
# Search multiple registries
npx shadcn search @shadcn @acme
# With pagination
npx shadcn search @shadcn --limit 20 --offset 0
# Search with limit and offset for pagination
npx shadcn search @shadcn -q "card" --limit 10 --offset 10Exit Codes:
0 - Success (results found or empty results)1 - General error2 - Configuration error (missing components.json)3 - Registry error (registry not found, network error)4 - Validation error (invalid registry name format, invalid limit/offset)Agent Usage: Use programmatic searchRegistries function for structured results. CLI output is formatted for human reading. For programmatic use, prefer the API.
Edge Cases:
@, exit code 4 is returnedRuns migrations for upgrading components. Supports migrating between icon libraries and updating to newer Radix UI versions.
shadcn migrate <command> [options]Description: Performs automated code migrations for component upgrades.
Available Subcommands:
Migrates components between icon libraries.
shadcn migrate icons [from] [to] [options]What it does:
Arguments:
from - Source icon library name (optional for interactive mode)to - Target icon library name (optional for interactive mode)Options:
-c, --cwd <dir> - Working directory-y, --yes - Skip confirmation promptsExamples:
# Interactive migration
npx shadcn migrate icons
# Migrate from lucide to phosphor
npx shadcn migrate icons lucide phosphor
# Non-interactive migration
npx shadcn migrate icons lucide phosphor --yesExit Codes:
0 - Success1 - General error (file read/write error, transformation error)2 - Configuration error (missing components.json, invalid icon library)4 - Validation error (invalid library names)Agent Usage: Specify both from and to parameters for non-interactive use. Use --yes to skip prompts. This modifies files in place - ensure version control is available.
Edge Cases:
Migrates components to newer Radix UI versions.
shadcn migrate radix [options]What it does:
Options:
-c, --cwd <dir> - Working directory-y, --yes - Skip confirmation promptsExample:
npx shadcn migrate radix
# Non-interactive
npx shadcn migrate radix --yesExit Codes:
0 - Success1 - General error2 - Configuration errorAgent Usage: Run this when upgrading Radix UI versions. Check component compatibility first. Use --yes for non-interactive use.
Edge Cases:
Displays project information including configuration, paths, and dependencies.
shadcn info [options]Description: Shows comprehensive project information for debugging and verification.
What it does:
Options:
-c, --cwd <dir> - Working directoryExample:
npx shadcn infoExit Codes:
0 - Success2 - Configuration error (missing components.json)Agent Usage: Use programmatic getRegistriesConfig for structured configuration access. CLI output is formatted for human reading.
Edge Cases:
Builds components for a shadcn registry. Used for creating custom registries.
shadcn build [options]Description: Builds and packages components for registry distribution.
What it does:
Options:
Example:
npx shadcn buildAgent Usage: This is for registry creators, not typical component consumers. Requires specific project structure and configuration.
Exit Codes:
0 - Success1 - General error (build failure)2 - Configuration errorStarts the Model Context Protocol server for AI assistant integration.
shadcn mcp [options]Description: Launches an MCP server that AI assistants can connect to for component management.
What it does:
Available MCP Tools:
get_project_registries - Get configured registrieslist_items_in_registries - List all registry itemssearch_items_in_registries - Search for componentsview_items_in_registries - View component detailsget_item_examples_from_registries - Get usage examplesget_add_command_for_items - Get add commandget_audit_checklist - Get post-addition checklistOptions:
-c, --cwd <dir> - Set working directoryExample:
npx shadcn mcpExit Codes:
0 - Server started successfully (runs until terminated)1 - General error (server startup failure)2 - Configuration error (missing components.json)Agent Usage: This is the primary interface for AI assistants. The server communicates via stdio using MCP protocol. The server runs until terminated (Ctrl+C or process termination). Ensure components.json exists before starting.
Edge Cases:
Initializes MCP configuration for AI clients.
shadcn mcp init [options]Description: Configures the shadcn MCP server for use with AI assistants like Claude, Cursor, VS Code, and Codex.
What it does:
Options:
--client <client> - AI client to configure (claude, cursor, vscode, codex). Required for non-interactive use.-c, --cwd <dir> - Set working directorySupported Clients:
Example:
# Interactive mode - prompts for client
npx shadcn mcp init
# Specify client directly
npx shadcn mcp init --client claude
npx shadcn mcp init --client cursorExit Codes:
0 - Success1 - General error (configuration file write failure, dependency installation failure)4 - Validation error (invalid client name)Agent Usage: Specify --client flag for non-interactive setup. This configures the MCP client, not the server. The command creates configuration files in client-specific locations.
Edge Cases:
Builds registry items (internal registry command). Used for building official shadcn/ui registry.
shadcn registry:build [options]Description: Internal command for building the shadcn/ui registry.
Example:
npx shadcn registry:buildAgent Usage: This is an internal command for registry maintainers, not for general use. Requires specific project structure and access to registry source.
Exit Codes:
0 - Success1 - General errorStarts registry MCP server (internal registry command). Internal server for registry operations.
shadcn registry:mcp [options]Description: Internal MCP server for registry management.
Example:
npx shadcn registry:mcpAgent Usage: This is an internal command for registry maintainers, not for general use.
Exit Codes:
0 - Success (server runs until terminated)1 - General errorAll commands support these common options:
-h, --help - Display help for command-v, --version - Display version number-c, --cwd <dir> - Set working directoryCommands read configuration from components.json:
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "app/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide",
"menuColor": "default",
"menuAccent": "subtle",
"registries": {
"@shadcn": "https://ui.shadcn.com/r/{name}.json",
"@acme": {
"url": "https://registry.acme.com/{name}.json",
"headers": {
"Authorization": "Bearer ${ACME_TOKEN}"
}
}
}
}Configuration Discovery:
components.json in the current directory and parent directoriescosmiconfig for configuration discoveryFor programmatic use, commands return standard exit codes:
0 - Success1 - General error (file system, network, package manager, etc.)2 - Configuration error (missing components.json, invalid configuration)3 - Registry error (network error, item not found, authentication failure, parse error)4 - Validation error (invalid input, invalid component name, circular dependency)Exit Code Handling Example:
#!/bin/bash
# Example script for handling exit codes
npx shadcn add button --yes --overwrite
exit_code=$?
case $exit_code in
0)
echo "Success: Component added"
;;
1)
echo "Error: General error occurred"
exit 1
;;
2)
echo "Error: Configuration error. Run: npx shadcn init"
exit 1
;;
3)
echo "Error: Registry error. Check component name and network connection"
exit 1
;;
4)
echo "Error: Validation error. Check component name format"
exit 1
;;
*)
echo "Error: Unknown exit code: $exit_code"
exit 1
;;
esac--yes flag with add and migrate commands to skip promptscomponents.json exists before running commands that require it (use init first)--overwrite flag to update existing componentsadd command automatically installs npm dependencies. Ensure package manager (npm/yarn/pnpm) is available-c, --cwd option to specify working directory for commands# Error: components.json not found
# Solution: Run npx shadcn init first
npx shadcn init# Error: Component not found in registry
# Solution: Search for correct component name
npx shadcn search @shadcn --query button# Error: Failed to fetch from registry
# Solution: Check network connection, retry, or check registry URL
npx shadcn info # Verify registry configuration# Error: Unauthorized access to registry
# Solution: Check environment variables and registry headers in components.json
echo $ACME_TOKEN # Verify token is set# Error: Circular dependency detected
# Solution: Review component dependencies, may indicate registry configuration issue
npx shadcn view @shadcn/button # Check component dependencies