CLI
Use the CLI to add components to your project, manage dependencies, and more.Installation
You don’t need to install the CLI globally. Usenpx to run commands:
Commands
init
Initialize your project and install dependencies.Options
string
The template to use:
next, vite, start, or next-monorepostring
The base color:
neutral, gray, zinc, stone, or slateboolean
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.Options
string
The template to use:
next, vite, or startstring
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.Adding from URLs
You can also add components from URLs:Adding from Custom Registries
If you’ve configured custom registries incomponents.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.Options
boolean
default:"false"
Skip confirmation prompt
string
The working directory
view
View items from the registry.Options
string
The working directory
search
Search for components in the registry.migrate
Migrate from older versions of shadcn/ui.info
Display project information.- Framework detected
- Package manager
- Tailwind CSS version
- Configuration paths
Usage Examples
Environment Variables
The CLI supports environment variables for authentication with custom registries:.env
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 runshadcn add button, the CLI:
- Fetches the component from the registry
- 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
- Installs dependencies required by the component
- Writes the files to your project
- Updates your CSS if needed (for new CSS variables)
Troubleshooting
Command not found
Command not found
Make sure you’re using Not:
npx to run the command:Invalid configuration
Invalid configuration
If you get configuration errors, try:
- Check your
components.jsonis valid JSON - Verify path aliases match your tsconfig.json
- Run
npx shadcn@latest init --forceto reset configuration
Component not found
Component not found
If a component is not found:
- Check the component name is correct
- Run
npx shadcn@latest search <name>to find available components - Make sure you have an internet connection (registry is fetched remotely)
Import errors after adding component
Import errors after adding component
If you get import errors:
- Check your path aliases in tsconfig.json match components.json
- Restart your TypeScript server
- Make sure dependencies were installed (check package.json)