# 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.

- Category: Tutorials · Published: 2026-11-18 · Updated: 2026-11-22 · Reading time: 7 min read
- Canonical URL: https://hazeui.com/guides/shadcn-cli-for-astro-without-react
- Tags: shadcn-cli, astro, tailwind-v4, registry, tutorial

## Executive Summary

The shadcn CLI supports custom third-party registries defined inside components.json and works cleanly in pure Astro projects without React. By adding the @haze registry endpoint, developers can run npx shadcn@latest add @haze/button to write plain .astro files, TypeScript helpers, and Tailwind v4 design tokens directly into src/.

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.

```bash
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](/docs/installation).

## 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.

```json
{
  "$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](/ui/button)) |
| `@haze/<block-slug>` | `src/components/haze/blocks/<slug>.astro` | Complete page section (e.g. [Centered Hero](/blocks/hero-centered)) |

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:

```bash
npx shadcn@latest add @haze/theme
```

Then import `haze.css` right after `@import "tailwindcss";` in your main global stylesheet (commonly `src/styles/global.css`):

```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:

```astro
---
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:

```bash
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-centered` pulls in `@haze/badge`, `@haze/button`, `@haze/placeholder`, `@haze/utils`, and `@lucide/astro`.
- Files that already exist and match byte-for-byte (such as `button.astro` shared across multiple blocks) are skipped silently.
- Every block ships with sensible demo defaults on `Astro.props`, so you can drop it into `src/pages/index.astro` right away and replace props incrementally.

```astro
---
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](/blocks/navbar-simple), [Centered Hero](/blocks/hero-centered), [Three-tier Pricing](/blocks/pricing-three-tier), and [FAQ Accordion](/blocks/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:

1. Commit your working tree with `git add -A && git commit -m "chore: checkpoint before haze update"`.
2. Run `npx shadcn@latest add @haze/button --overwrite` (or pass `--overwrite` on the new block install).
3. Inspect `git diff src/components/haze/ui/button.astro` and keep or re-apply your local adjustments.

When you want complete multi-block page compositions rather than individual primitives, visit [Screens & Starter Kits](/screens) for pre-grouped install commands covering marketing launches, developer products, and full app workspaces.

## Troubleshooting common Astro + shadcn CLI issues

- **"Unknown registry `@haze`":** Check that `components.json` sits in the exact working directory where you invoke `npx shadcn@latest` and 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/vite` compiles that stylesheet in your layout.
- **Missing icons at build time:** Verify `@lucide/astro` was added to `dependencies` in `package.json` and run `pnpm install` if 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](/guides/private-shadcn-component-registry-architecture-guide) next.

## Mentioned Haze UI Entries

- [Button](https://hazeui.com/ui/button.md): Button or link styled as a button, in seven variants and three text sizes, plus a square icon size and press and loading states.
- [Hero: centered with announcement badge](https://hazeui.com/blocks/hero-centered.md): Centered headline, linked announcement badge, two CTAs and a raised image placeholder. Text rises in on load, then the placeholder.
- [Pricing: three tiers with featured plan](https://hazeui.com/blocks/pricing-three-tier.md): Three plan panels in one row with equal heights and aligned buttons. The middle plan has a stronger border and a badge.
- [FAQ: two-column exclusive accordion](https://hazeui.com/blocks/faq-accordion.md): Heading and support link on the left, an exclusive animated accordion of questions on the right, built on native details.
- [Navbar: simple with mobile menu](https://hazeui.com/blocks/navbar-simple.md): Sticky translucent top bar with wordmark, links, optional sign-in and a CTA from lg. Below lg a floating panel menu fades and slides in.

## Frequently Asked Questions

### 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.
