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
The template to use:
next, vite, start, or next-monorepoThe base color:
neutral, gray, zinc, stone, or slateSkip confirmation prompt
Use default configuration
Force overwrite of existing configuration
The working directory (defaults to current directory)
Use the src directory when creating a new project
Use CSS variables for theming
Enable RTL support
Do not install the base shadcn style
create
Create a new project with shadcn/ui.Options
The template to use:
next, vite, or startUse a preset configuration (name or URL)
The working directory
Use the src directory
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
Skip confirmation prompt
Overwrite existing files
The working directory
Add all available components
The path to add the component to
Mute output
diff
Check for updates against the registry.Options
Skip confirmation prompt
The working directory
view
View items from the registry.Options
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)