astro add is the Astro CLI command that installs an integration or adapter and wires it into your project in one step: npx astro add mdx installs @astrojs/mdx with its peer dependencies, imports it in astro.config.mjs and adds it to integrations. It asks before every change unless you pass --yes, and it accepts several names at once.
Key Takeaways
- Usage:
npx astro add <name> [more names], for examplenpx astro add react sitemap.- Short names resolve to official
@astrojs/*packages first; other npm packages work if they’re tagged as Astro integrations.- Adapters such as
node,netlify,vercelandcloudflareare set asadapter, not added tointegrations.--yes(or-y) accepts every prompt, which is what you want in scripts.
Basic usage
# terminal
npx astro add mdx
You can use your package manager’s runner too: pnpm astro add mdx, yarn astro add mdx or bunx astro add mdx. Astro detects which one you use and installs with it.
Add several at once and accept all prompts:
# terminal
npx astro add react mdx sitemap --yes
The result in your config:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import react from '@astrojs/react';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
integrations: [react(), mdx(), sitemap()],
});
Run npx astro add with no names to print the list of supported short names.
What it does, step by step
- Resolves the name.
mdxis checked against the official@astrojsscope first. A scoped name like@scope/pkggoes straight to npm. - Checks it’s an integration. The package’s
keywordsmust includeastro-integrationorastro-adapter, or the command stops with “doesn’t appear to be an integration or an adapter”. - Collects dependencies. Required peer dependencies are installed alongside it, so
astro add reactalso installsreactandreact-dom. - Edits your config. It shows a diff of
astro.config.mjsand asks to apply it. - Updates TypeScript settings when the integration needs them, for example JSX options for React, Preact or Solid.
Short names worth knowing
| Command | Installs |
|---|---|
astro add react / preact / vue / svelte / solid-js |
UI framework renderers (solid also works) |
astro add mdx / markdoc |
Content formats |
astro add sitemap / partytown |
Build helpers |
astro add tailwind |
Tailwind CSS 4 through @tailwindcss/vite |
astro add starlight |
The Starlight docs framework |
astro add node / netlify / vercel / cloudflare / deno |
Server adapters |
Two of these do more than edit the config. tailwind registers @tailwindcss/vite as a Vite plugin and scaffolds src/styles/global.css, which you then import in your layout. cloudflare scaffolds a wrangler.jsonc if you don’t have one and adds a generate-types script that runs wrangler types.
Third-party integrations
Any npm package tagged astro-integration works:
# terminal
npx astro add astro-icon
Astro tells you it isn’t an official package and asks before continuing. Pin a version with the usual npm syntax, such as npx astro add @astrojs/mdx@latest.
When astro add can’t edit your config
astro add parses astro.config.mjs and modifies the defineConfig() call. If your config is built dynamically (spread from another file, wrapped in a function, or exported without defineConfig), it stops with “Astro could not update your astro.config.js file safely” and tells you to add the integration manually. Add the import and the integrations entry yourself, then run npm run dev to confirm. If there’s no config file at all, astro add creates one.
Komal themes keep a plain defineConfig() export, so astro add edits them like a fresh starter; astro.config.mjs in our docs shows the layout. For the full command list, see every Astro CLI command, and the sitemap tip for a worked example. If you’d rather start with integrations already configured, browse Astro themes. Astro’s CLI reference and the integrations directory list everything available.
FAQ
What does npx astro add do?
It installs an Astro integration or adapter with its peer dependencies and edits astro.config.mjs to register it, asking for confirmation before each change.
How do I install an Astro integration without prompts?
Add --yes or -y: npx astro add mdx --yes. Every prompt is accepted automatically, which is useful in setup scripts and CI.
Can I add multiple integrations at once?
Yes. List them with spaces: npx astro add react tailwind sitemap. Astro installs them in one go and shows a single config diff.
How do I remove an integration added with astro add?
There’s no astro remove. Uninstall the package with your package manager, then delete its import and its entry in integrations (or adapter) from astro.config.mjs.