Skip to main content

CLI

Use the CLI to add components to your project, manage dependencies, and more.

Installation

You don’t need to install the CLI globally. Use npx to run commands:
This will always use the latest version of the CLI.

Commands

init

Initialize your project and install dependencies.
You can also initialize with components:

Options

string
The template to use: next, vite, start, or next-monorepo
string
The base color: neutral, gray, zinc, stone, or slate
boolean
default:"true"
Skip confirmation prompt
boolean
default:"false"
Use default configuration
boolean
default:"false"
Force overwrite of existing configuration
string
The working directory (defaults to current directory)
boolean
Use the src directory when creating a new project
boolean
default:"true"
Use CSS variables for theming
boolean
default:"false"
Enable RTL support
boolean
Do not install the base shadcn style

create

Create a new project with shadcn/ui.
If no name is provided, you’ll be prompted to enter one. If no preset is specified, you’ll be taken to the create page to build your custom design system.

Options

string
The template to use: next, vite, or start
string
Use a preset configuration (name or URL)
string
The working directory
boolean
Use the src directory
boolean
default:"false"
Enable RTL support

add

Add components to your project.
You can add multiple components at once:
Or add all components:

Adding from URLs

You can also add components from URLs:

Adding from Custom Registries

If you’ve configured custom registries in components.json, you can use them:

Options

boolean
default:"false"
Skip confirmation prompt
boolean
default:"false"
Overwrite existing files
string
The working directory
boolean
default:"false"
Add all available components
string
The path to add the component to
boolean
default:"false"
Mute output

diff

Check for updates against the registry.
This will check all components in your project for updates. To check a specific component:
The command will show you the differences between your local components and the latest versions in the registry.

Options

boolean
default:"false"
Skip confirmation prompt
string
The working directory

view

View items from the registry.
This outputs the raw JSON for the component from the registry. Useful for debugging or inspecting component metadata. You can view multiple items:

Options

string
The working directory

Search for components in the registry.
This searches the registry for components matching your query.

migrate

Migrate from older versions of shadcn/ui.
This command helps you migrate your components when there are breaking changes or new conventions.

info

Display project information.
Shows information about your project setup, including:
  • Framework detected
  • Package manager
  • Tailwind CSS version
  • Configuration paths

Usage Examples

Environment Variables

The CLI supports environment variables for authentication with custom registries:
.env
Use them in your components.json:
components.json
The CLI automatically loads .env, .env.local, and other environment files using dotenvx.

What Happens When You Add a Component?

When you run shadcn add button, the CLI:
  1. Fetches the component from the registry
  2. Transforms the code to match your project configuration
    • Updates import paths based on your aliases
    • Applies Tailwind prefix if configured
    • Converts to JSX if TypeScript is disabled
    • Adds “use client” for React Server Components
  3. Installs dependencies required by the component
  4. Writes the files to your project
  5. Updates your CSS if needed (for new CSS variables)
All transformations are based on your components.json configuration. The CLI reads this file to understand your project structure.

Troubleshooting

Make sure you’re using npx to run the command:
Not:
If you get configuration errors, try:
  1. Check your components.json is valid JSON
  2. Verify path aliases match your tsconfig.json
  3. Run npx shadcn@latest init --force to reset configuration
If a component is not found:
  1. Check the component name is correct
  2. Run npx shadcn@latest search <name> to find available components
  3. Make sure you have an internet connection (registry is fetched remotely)
If you get import errors:
  1. Check your path aliases in tsconfig.json match components.json
  2. Restart your TypeScript server
  3. Make sure dependencies were installed (check package.json)

Version

To check the CLI version:
Always use @latest to ensure you’re running the most recent version of the CLI. The package is updated frequently with bug fixes and new features.