brokeinprod
brokeinprod
Theme

Debugging

shadcn init Ate My globals.css: Recovery, and the Pattern That Avoids It

shadcn init can overwrite globals.css and Tailwind customizations without warning. Recovering the lost work, and the cherry-pick pattern that skips the CLI.

November 19, 2026

I had a tuned Tailwind setup: custom properties, typography plugin wiring, font variables. One installer command later, I had shadcn's defaults and none of mine.

Start here: The shadcn CLI's init command rewrites your global CSS file (and can touch your Tailwind config and layout defaults) to install its theme variables. If you had customizations there, they are gone. Recover them from git (git checkout -- app/globals.css if uncommitted work survived elsewhere, or git diff against the last commit) or from VS Code's Timeline / Local History if you had not committed. Prevention is two habits: commit immediately before running any installer, and for shadcn specifically, consider cherry-picking component source from the docs instead of running the CLI at all. The components are designed to be copy-paste-owned.

The setup

A content site build with a deliberately tuned globals.css: Tailwind directives, custom properties for the accent system, prose and typography wiring, and font variable hookups from next/font. The plan was to pull in a couple of shadcn/ui primitives for accessible interactive components. shadcn's whole pitch is that you own the component source in your repo, which fit the build's "no dependency I can't read" posture.

So: run the installer, add a component or two, keep moving.

The symptom

After init, the site's look degraded in ways that did not trace to any file I had edited that session. Styles that had worked for weeks were gone.

Opening globals.css explained it. The file was not mine anymore. The installer had written its own version, shadcn's CSS variable theme blocks, and my customizations were absent. It did not stop at the stylesheet. The preset (Nova, in this case) had also swapped the font wiring in layout.tsx, Inter out and Geist in, and had set components.json to its own opinionated style. This is not a merge. It is a replace, across multiple files.

It is not a quirk of one machine, either. The behavior is documented in shadcn's own issue tracker. Users report that running init modifies the contents of globals.css and the Tailwind config, overwriting and removing existing configuration, and they ask for a merge instead of a rewrite. Others hit it repeatedly: start a project, tweak global.css, add shadcn, and global.css is overwritten. They recovered through VS Code's history feature and asked that init warn first.

The diagnosis

init is a scaffolder, not a patcher. Its job is to leave the project in a known-good state for shadcn components: theme variables in the global stylesheet, config aligned, aliases set. From the tool's perspective, whatever was in globals.css before is an unknown it cannot reason about, so it establishes its known-good state by writing over it.

The mistake on my side was a category error. I ran an initializer on a project that was already initialized. init is designed for minute one of a project. Weeks in, with a customized stylesheet, the same command is destructive by design.

The fix

Recovery, in order of preference:

 
 
# 1. If your customizations were committed (they should have been):
git diff app/globals.css          # see exactly what the installer changed
git checkout -- app/globals.css   # take your version back
 
# 2. Then re-apply what you actually wanted from shadcn's version by hand —
#    usually just the CSS variable theme block, merged below your own code.

If the work was uncommitted, the painful case, VS Code's Timeline view (right-click the file → Open Timeline) keeps local history snapshots even without git. That is the recovery path shadcn users themselves report using.

Prevention, two layers:

  1. Commit before any installer runs. Not "commit often" as a platitude. Specifically: any command that advertises writing to your project (init, create-*, codemods) gets a clean working tree first, so the diff it produces is inspectable and reversible.

  2. Cherry-pick instead of installing. shadcn components are published as source you are meant to own. You can copy a component's code from the docs into components/ui/ yourself, add its few dependencies manually, and merge the handful of CSS variables it needs into your existing stylesheet. No CLI, no surprise writes. For a project adding two or three primitives, this is less total work than auditing what init did.

The portfolio-level epilogue is worth recording. After paying this tax once, the next site skipped shadcn entirely. the mobile drawer and the command palette were both built on HTML5 <dialog>, with zero component library. Not because shadcn is bad, but because for two or three primitives, owning forty lines of dialog code beats auditing an installer's writes.

shadcn's copy-paste-owned philosophy is the reason skipping its own installer works. The components were always meant to be readable, portable source. The installer is a convenience layered on top of that design, and it is the only part of the design that writes to files you did not ask it to touch.


Installers are for minute one. After that, treat any tool that writes to your project as a pull request from a stranger: clean tree before, full diff after.

FAQ

Does add (single component) do the same damage as init? add is far more contained. The CLI docs describe it as adding components and their dependencies to your project; init is the command that installs dependencies, adds the cn utility, configures CSS variables, and writes an @import into your global CSS. The heavy rewrites are init's territory. The clean-tree habit costs nothing either way.

Can I re-run init safely with a flag? There is a --force flag for overwriting configuration, which is the opposite of what you want here. As of the issue reports above, there is no merge mode. The safe path is manual merging.

What about the Tailwind v4 wrinkle? Newer shadcn versions targeting Tailwind v4 move theming into the CSS file: an @import that init adds, CSS variables in :root and .dark, and @theme inline. The overwrite risk is the same or higher, because more of the setup now lives in the one file init writes to. The same habits apply.

I don't use VS Code. What are the other recovery options? JetBrains IDEs have Local History (right-click → Local History → Show). For Vim and other editors without local history, git is the only net, which is the argument for layer 1.

Further reading

Keep reading

Newsletter

New posts in your inbox. No spam — unsubscribe anytime.

Occasional emails when we publish something worth your time. Unsubscribe anytime.

More about what you'll get on the newsletter page.

THEME
↑↓ navigate↵ openesc close