Skip to main content
The Astro CLI is the primary way to interact with your Astro project from the command line.

Usage

Commands

astro dev

Runs Astro’s development server. This starts a local HTTP server that serves your project with Hot Module Replacement (HMR).
Flags:
number
default:"4321"
Specifies which port to run on. If the port is already in use, Astro will automatically try the next available port.
string | boolean
Sets which network IP addresses the dev server should listen on (i.e. non-localhost IPs). Use --host to expose the server on all addresses, or pass a specific IP.
string | boolean
Opens the app in a browser on server start. Pass a URL path (e.g. --open /about) to open to a specific page.
string
Comma-separated list of allowed hostnames for the dev server.

astro build

Builds your site for production. By default, this will generate static files and place them in a dist/ directory. If SSR is enabled, this will generate the necessary server files to serve your site.
Flags:
string
Specifies the output directory for the build. Overrides the outDir config option.

astro preview

Starts a local server to serve your built dist/ directory. This is useful for previewing your build locally, before deploying it.
Flags:
number
default:"4321"
Specifies which port to run on.
string | boolean
Sets which network IP addresses the preview server should listen on.
string | boolean
Opens the app in a browser on server start.

astro check

Runs diagnostics (such as type-checking .astro files) against your project and reports errors to the console. If any errors are found, the process will exit with a code of 1.
Flags:
Runs the type checker in watch mode, re-checking files when they change.

astro sync

Generates TypeScript types for all Astro modules. This sets up type stubs for content collections, environment variables, and other Astro features.

astro add

Adds an integration to your Astro project. This command will:
  1. Install the integration package
  2. Update your astro.config.mjs file
  3. Install any peer dependencies
Examples:
Common integrations:
  • react - React support
  • vue - Vue support
  • svelte - Svelte support
  • solid-js - Solid support
  • preact - Preact support
  • mdx - MDX support
  • tailwind - Tailwind CSS support
  • sitemap - Sitemap generation
  • partytown - Partytown integration
Common adapters:
  • netlify - Deploy to Netlify
  • vercel - Deploy to Vercel
  • cloudflare - Deploy to Cloudflare
  • node - Deploy to Node.js servers
  • deno - Deploy to Deno Deploy

astro docs

Opens the Astro documentation website directly from your terminal.

astro info

Reports useful information about your current Astro environment. Useful for providing information when opening an issue.
Outputs information like:
  • Astro version
  • Node version
  • Package manager
  • Operating system
  • Installed integrations
Flags:
Automatically copies the info output to your clipboard.

astro preferences

Manage user preferences for Astro. Preferences are specific to individual Astro users, unlike the astro.config.mjs file which changes behavior for everyone working on a project.
Commands:
Available preferences:
  • devToolbar - Enable or disable the dev toolbar
Flags:
Set preferences globally for all Astro projects on your machine.

astro telemetry

Sets telemetry configuration for the current CLI user. Telemetry is anonymous data that provides insights into which Astro features are most used.
Commands:

astro db

Commands for managing Astro DB. These commands require the @astrojs/db integration to be installed.
Commands:
See the Astro DB documentation for more details.

Global Flags

These flags are available for all commands:

--config

string
Specifies the path to the config file. Defaults to astro.config.mjs.

--root

string
Specifies the path to the project root. If not specified, the current working directory is assumed to be the root.

--site

string
Overrides the site configuration option.

--base

string
Overrides the base configuration option.

--verbose

Enables verbose logging, which is helpful when debugging an issue.

--silent

Enables silent logging, which will prevent all logging.

--version

Prints the Astro version number and exits.

--help

Prints help message and exits.

Environment Variables

The Astro CLI respects several environment variables:

NODE_ENV

Sets the environment mode. Defaults to development in astro dev, and production in astro build and astro preview.

ASTRO_TELEMETRY_DISABLED

When set to 1, disables telemetry collection.

Examples

Development Workflow

Production Build

Type Checking

Adding Integrations