| name | shadcn-init |
| description | Setup shadcn/ui in React projects (Next.js, Vite, Astro). Use when initializing shadcn/ui, setting up Tailwind CSS v4, configuring path aliases, or when user mentions "setup shadcn", "install shadcn", "shadcn init", or starting a new shadcn project. NOT for adding components or customization. |
shadcn/ui Initialization
This skill guides you through setting up shadcn/ui for the first time in React projects.
What shadcn/ui Is
shadcn/ui is a collection of unstyled, accessible React components built on Radix UI and styled with Tailwind CSS. Components are copied directly into your project, giving you full ownership and control.
When to Use This Skill
Use this skill when:
- Setting up shadcn/ui for the first time
- User mentions "setup shadcn", "install shadcn", or "shadcn init"
- Configuring Tailwind CSS v4 for shadcn/ui
- Setting up path aliases for component imports
- Troubleshooting initialization errors
Do NOT use this skill for:
- Adding individual components (use shadcn-components skill)
- Customizing themes or styles (use shadcn-customize skill)
- Advanced patterns (use shadcn-patterns skill)
Quick Start
- Detect the framework (Next.js, Vite, or Astro)
- Follow framework-specific setup (see sections below)
- Run validation script to verify installation
- Installation complete - ready to add components
Framework Detection
Check for framework indicators:
- Next.js:
next.config.jsornext.config.tspresent - Vite:
vite.config.tsorvite.config.jspresent - Astro:
astro.config.mjspresent
Framework-Specific Setup
Next.js Setup
Next.js auto-detects configuration, so setup is minimal:
Install Tailwind CSS (if not already installed):
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -pConfigure Tailwind in
tailwind.config.js:export default { content: [ "./app/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}", ], }Add Tailwind directives to
app/globals.cssor your CSS file:@import "tailwindcss";Verify imports in your app entry:
- For App Router: Ensure
globals.cssis imported inapp/layout.tsx - For Pages Router: Ensure CSS is imported in
pages/_app.tsx
- For App Router: Ensure
Run initialization:
npx shadcn@latest init- Choose defaults when prompted (or use
-dflag to skip)
- Choose defaults when prompted (or use
Verify installation succeeded - Check these files exist:
components/ui/button.tsx(or similar component)lib/utils.tscomponents.json
Vite Setup
Vite requires more explicit configuration:
Step 1: Install Dependencies
npm install -D tailwindcss @tailwindcss/vite
Step 2: Configure Tailwind in Vite
Update vite.config.ts:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: {
'@': '/src',
},
},
})
Key points:
tailwindcss()plugin processes Tailwind importsresolve.aliasmaps@to/srcdirectory- Plugin order: react first, then tailwindcss
Step 3: Configure TypeScript Path Aliases
Update root tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
If you have tsconfig.app.json (app-specific config), also add paths there:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
Why both configs? shadcn init validates the root config, but TypeScript uses both configs in project reference setups.
Step 4: Prepare Global CSS File
This step is CRITICAL. Add ONLY the Tailwind import to your global CSS (typically src/index.css or src/globals.css):
@import "tailwindcss";
⚠️ IMPORTANT:
- Add ONLY this line
- Do NOT add CSS variables yet
- Do NOT add @layer blocks
- Do NOT add any other customizations
The shadcn init command will automatically add all theme configuration after it validates Tailwind v4.
Verify this file is imported in your app entry point (src/main.tsx or src/main.ts):
import './index.css'
Step 5: Run Initialization
npx shadcn@latest init -d
The -d flag uses defaults (recommended):
- Style:
new-york - Base color:
neutral - CSS variables:
true
Or run interactively without -d to choose options.
Astro Setup
Astro requires React integration:
Step 1: Ensure React Integration
npx astro add react
This installs @astrojs/react and configures the integration.
Step 2: Install Tailwind CSS
npx astro add tailwind
This installs Tailwind and creates necessary configuration.
Step 3: Configure Path Aliases
Update tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
Step 4: Initialize shadcn/ui
npx shadcn@latest init
When prompted:
- Choose
srcas component directory - Choose defaults for other options
Step 5: Use Components in Astro
Components are used with the client: directive for interactivity:
---
import { Button } from '@/components/ui/button'
---
<Button client:load>Click me</Button>
Important: Use client:load or client:visible directives on interactive components.
Running shadcn Init
After pre-configuration is complete, run initialization:
# Non-interactive (uses defaults)
npx shadcn@latest init -d
# Interactive (choose options)
npx shadcn@latest init
What shadcn init creates:
components.json- Configuration file for component paths and settingssrc/lib/utils.ts- Utility file containing thecn()function for class merging- Updates your CSS file - Adds theme configuration using CSS variables
- Installs dependencies - Adds
clsx,tailwind-merge, andclass-variance-authority
During initialization, shadcn validates:
- Framework detection (Next.js, Vite, Astro, etc.)
- Path aliases in
tsconfig.json - Tailwind CSS v4 installation and
@import "tailwindcss"in CSS
If validation fails, check error message and review pre-configuration steps above.
Verification
After running shadcn init, verify installation using the validation script:
bash .claude/skills/shadcn-init/scripts/validate-installation.sh
This script checks:
components.jsonexistssrc/lib/utils.tsexists withcn()function- Required dependencies installed (clsx, tailwind-merge, class-variance-authority)
- Tailwind CSS v4+ installed
- CSS file has Tailwind import and theme variables
- Path aliases configured in tsconfig
If validation fails, see the Troubleshooting section below.
Troubleshooting
"No import alias found"
Cause: Path aliases not configured in tsconfig.json
Fix:
- Add to
tsconfig.jsonandtsconfig.app.json(if exists):
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
- For Vite: Also add
resolve.aliastovite.config.ts - Delete
components.jsonif it exists - Re-run
npx shadcn@latest init -d
"Unable to find Tailwind CSS"
Cause: Tailwind not installed or missing CSS import
Fix:
- Install:
npm install -D tailwindcss @tailwindcss/vite - Add to global CSS (top of file):
@import "tailwindcss"; - Verify CSS file is imported in app entry point
- Re-run
npx shadcn@latest init -d
Framework Not Detected
Cause: Framework detection failed
Fix:
- Verify framework:
npm list react react-dom - Delete
components.jsonif exists - Run
npx shadcn@latest init(interactive mode) - Manually select your framework
Validation Script Fails
Cause: Missing configuration or dependencies
Fix:
- Read error messages from validation script
- Review framework-specific setup steps above
- For Vite: Check BOTH
tsconfig.jsonANDtsconfig.app.json - Delete
components.jsonand retry
What shadcn init Creates
The npx shadcn@latest init command:
- Creates
components.json(configuration file) - Creates
src/lib/utils.ts(containscn()utility for class merging) - Updates your CSS file with theme variables
- Installs dependencies:
clsx,tailwind-merge,class-variance-authority
Advanced References
For detailed framework-specific guides:
Next Steps
Once installation is verified:
- Add your first component:
npx shadcn@latest add button - Use shadcn-components skill for adding more components
- Use shadcn-customize skill for theme customization
Installation is complete when validation script passes all checks.