How to Use the shadcn CLI in an Astro Project (Without Installing React)
Step-by-step setup for custom @haze shadcn registries in pure Astro projects, including overwrite flags and dependency resolution.
Most developers assume shadcn is strictly a React tool. That assumption made sense when the CLI only pulled from the core React registry and hard-coded tsx file paths. Today, the schema-driven shadcn CLI supports custom namespaced registries and explicit file target paths, which means it installs plain .astro components into a zero-React Astro codebase out of the box.
Haze UI tested this directly in a clean Astro starter with no React integration installed: adding @haze/hero-centered, @haze/pricing-three-tier, @haze/faq-accordion, and @haze/navbar-simple pulled down the .astro blocks, their underlying UI primitives, cn(), and required Lucide icons, and astro build passed immediately.
Here is the exact setup and the edge cases worth knowing before you run your first install.
Step 1: Set up Astro and Tailwind CSS v4
Start with an Astro project using @tailwindcss/vite rather than the deprecated @astrojs/tailwind v3 plugin. If you already have an Astro project running Tailwind v4, check astro.config.mjs to confirm @tailwindcss/vite is active.
pnpm create astro@latest my-haze-app
cd my-haze-app
pnpm astro add tailwind
Verify that your package.json uses Tailwind v4 (tailwindcss and @tailwindcss/vite). Because Haze UI relies on @theme inline, color-mix() in OKLCH, and CSS custom variants, Tailwind v4 is a hard requirement. See the full checklist in our Installation docs.
Step 2: Configure components.json with the @haze namespace
Create a components.json file at the root of your Astro repository and map @haze to the registry template URL. Note that you do not need @/components/ui React aliases to consume an explicit-target registry, though keeping clean TypeScript path settings helps your editor.
{
"$schema": "https://ui.shadcn.com/schema/components.json",
"registries": {
"@haze": "https://hazeui.com/r/{name}.json"
}
}
When you pass @haze/button or @haze/hero-centered to the CLI, shadcn substitutes {name} and fetches the JSON payload from /r/<name>.json. That payload declares explicit target paths matching Haze’s internal directory layout (src/components/haze/ui/..., src/components/haze/blocks/..., and src/lib/haze/utils.ts).
| Registry item | Installed path | Purpose |
|---|---|---|
@haze/theme |
src/styles/haze.css |
Semantic OKLCH dark/light tokens, radii, shadows, easings |
@haze/utils |
src/lib/haze/utils.ts |
cn() helper combining clsx and tailwind-merge |
@haze/<ui-slug> |
src/components/haze/ui/<slug>.astro |
Base interactive primitive (e.g. Button) |
@haze/<block-slug> |
src/components/haze/blocks/<slug>.astro |
Complete page section (e.g. Centered Hero) |
Because install paths mirror Haze UI’s source layout, relative imports like import Button from "../ui/button.astro" and import { cn } from "../../../lib/haze/utils" work unmodified inside your own codebase.
Step 3: Install and import the theme once
Install the stylesheet before adding components:
npx shadcn@latest add @haze/theme
Then import haze.css right after @import "tailwindcss"; in your main global stylesheet (commonly src/styles/global.css):
@import "tailwindcss";
@import "./haze.css";
Also install the self-hosted font packages (@fontsource-variable/sora and @fontsource-variable/inter) if the CLI didn’t already prompt you, and import them inside your root Astro layout frontmatter:
---
import "@fontsource-variable/sora";
import "@fontsource-variable/inter";
import "../styles/global.css";
---
Why is @haze/theme a separate one-time command instead of a dependency listed on every block? During testing we discovered a sharp CLI edge case: if you edit src/styles/haze.css to customize your --brand hue or --radius, and a later block declares @haze/theme as a dependency, shadcn add stops and prompts to overwrite haze.css—even if you pass --yes. In non-interactive environments (CI scripts or AI coding agents), the CLI exits before installing the remaining files. Keeping @haze/theme standalone prevents customized themes from ever blocking future installs.
Step 4: Add components and multi-block sections
Now install any UI component or page block by slug. For example, assembling a SaaS landing page takes one command:
npx shadcn@latest add @haze/navbar-simple @haze/hero-centered @haze/pricing-three-tier @haze/faq-accordion
The CLI inspects the dependency graph automatically:
@haze/hero-centeredpulls in@haze/badge,@haze/button,@haze/placeholder,@haze/utils, and@lucide/astro.- Files that already exist and match byte-for-byte (such as
button.astroshared across multiple blocks) are skipped silently. - Every block ships with sensible demo defaults on
Astro.props, so you can drop it intosrc/pages/index.astroright away and replace props incrementally.
---
import NavbarSimple from "../components/haze/blocks/navbar-simple.astro";
import HeroCentered from "../components/haze/blocks/hero-centered.astro";
import PricingThreeTier from "../components/haze/blocks/pricing-three-tier.astro";
import FaqAccordion from "../components/haze/blocks/faq-accordion.astro";
---
<NavbarSimple brand="Northstar" />
<main>
<HeroCentered title="Ship Astro products faster" />
<PricingThreeTier />
<FaqAccordion />
</main>
Check out Navbar Simple, Centered Hero, Three-tier Pricing, and FAQ Accordion to inspect every prop before installing.
Handling updates and --overwrite safely
Once a .astro file lands in src/components/haze/, you own it completely. That freedom introduces one maintenance rule: if you edit button.astro locally and later install a new block whose upstream button.astro differs, shadcn add pauses at an overwrite prompt.
To update cleanly without surprises:
- Commit your working tree with
git add -A && git commit -m "chore: checkpoint before haze update". - Run
npx shadcn@latest add @haze/button --overwrite(or pass--overwriteon the new block install). - Inspect
git diff src/components/haze/ui/button.astroand keep or re-apply your local adjustments.
When you want complete multi-block page compositions rather than individual primitives, visit Screens & Starter Kits for pre-grouped install commands covering marketing launches, developer products, and full app workspaces.
Troubleshooting common Astro + shadcn CLI issues
- “Unknown registry
@haze”: Check thatcomponents.jsonsits in the exact working directory where you invokenpx shadcn@latestand includes"@haze": "https://hazeui.com/r/{name}.json". - Styles render unstyled boxes or wrong colors: Confirm
@import "./haze.css";comes after@import "tailwindcss";in your global stylesheet, and that@tailwindcss/vitecompiles that stylesheet in your layout. - Missing icons at build time: Verify
@lucide/astrowas added todependenciesinpackage.jsonand runpnpm installif your package manager skipped peer/auto-installs.
Want to go further and host a registry for your own team’s components? Read our breakdown on building a private shadcn-compatible component registry next.
Frequently asked questions
Does npx shadcn@latest add require React in Astro?
No. When installing from a custom Astro registry like @haze, the shadcn CLI writes whatever file types the registry specifies (such as .astro and .ts files) to their explicit target paths and installs only the npm packages listed by that entry, such as @lucide/astro, clsx, and tailwind-merge.
Why shouldn't @haze/theme be added as a dependency of every component?
Once you customize src/styles/haze.css, re-installing the theme automatically triggers interactive overwrite prompts—even when --yes is passed—which halts scripted installs and AI coding agents. Installing @haze/theme once as a setup step keeps component additions clean.
How do I update Haze UI components after customizing other files?
Commit your current changes in Git, then pass --overwrite when running npx shadcn@latest add @haze/<name> --overwrite so you can review exact diffs cleanly before keeping or reverting edits.
Which Tailwind version do Haze UI registry entries expect?
Haze UI uses Tailwind CSS v4 configured through @tailwindcss/vite and @theme inline inside src/styles/haze.css. Legacy @astrojs/tailwind v3 configs are not used.
Components & blocks mentioned
Browse all entries- ButtonUI
Button or link styled as a button, in seven variants and three text sizes, plus a square icon size and press and loading states.
npx shadcn@latest add @haze/button Centered headline, linked announcement badge, two CTAs and a raised image placeholder. Text rises in on load, then the placeholder.
npx shadcn@latest add @haze/hero-centeredThree plan panels in one row with equal heights and aligned buttons. The middle plan has a stronger border and a badge.
npx shadcn@latest add @haze/pricing-three-tierHeading and support link on the left, an exclusive animated accordion of questions on the right, built on native details.
npx shadcn@latest add @haze/faq-accordionSticky translucent top bar with wordmark, links, optional sign-in and a CTA from lg. Below lg a floating panel menu fades and slides in.
npx shadcn@latest add @haze/navbar-simple
Continue reading
9 min read
10 min read
AI & Agents
Making Your Component Library Readable by AI Coding Agents: llms.txt, Markdown Twins, and shadcn MCP
10 min read