astro sync generates the TypeScript types for Astro’s virtual modules, such as astro:content and astro:env, and runs your content collection loaders, writing the results into the .astro/ folder. astro dev, astro build and astro check already run it for you, so you only need npx astro sync on its own when your editor or tsc needs fresh types without starting the dev server.
Key Takeaways
- It writes
.astro/types.d.ts, pluscontent.d.tsand other generated type files it references.- It runs every collection loader, so schema errors show up here too.
- Run it after cloning, after editing
src/content.config.tswithout the dev server, and beforetscin CI.npx astro sync --forceclears the content layer cache and reloads everything.
What astro sync generates
# terminal
npx astro sync
The command does three jobs:
- Content collections. It loads
src/content.config.ts, runs each collection’s loader (glob(),file()or a custom one), validates entries against the schema and stores them in the content layer’s data store. It then generatescontent.d.ts, which typesgetCollection(),getEntry()andreference()for your collections. - Environment variables. If you define an
env.schemainastro.config.mjs, it generates types forastro:env/clientandastro:env/server. - Fonts and integrations. Types for the fonts API and any types injected by integrations are written alongside.
Everything is referenced from .astro/types.d.ts, which starts with a reference to astro/client. When it finishes you’ll see a log line like [types] Generated 412ms.
Astro starters list .astro/types.d.ts in include, so your editor picks the types up automatically:
// tsconfig.json
{
"extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"]
}
When to run it
Right after cloning. The .astro/ folder is usually in .gitignore, so a fresh clone has no generated types and your editor shows red squiggles on every astro:content import. Run npx astro sync once, or just start npm run dev.
After changing a schema without the dev server. If you edit a collection schema in src/content.config.ts while the dev server isn’t running, the types are stale until the next sync.
Before tsc or other type tools in CI. astro check syncs first on its own, but plain tsc --noEmit, ESLint with type information, or a test runner don’t:
// package.json
{
"scripts": {
"typecheck": "astro sync && tsc --noEmit"
}
}
After adding an astro:env variable. New entries in env.schema need a sync before import { API_URL } from 'astro:env/server' type-checks.
Use –force for a clean reload
The content layer caches entries between runs so unchanged files aren’t parsed again. If types or entries look wrong after renaming files, switching branches or upgrading a loader, clear the cache:
# terminal
npx astro sync --force
--force clears the content layer cache before syncing. astro build --force does the same as part of a build.
Errors you might see
Because sync runs your loaders and schemas, it surfaces content errors without a full build. A frontmatter field that fails validation produces the same error you’d get from astro build, for example frontmatter does not match collection schema. A config still using the old src/content/config.ts layout fails with the legacy content config error.
Sync doesn’t build pages, bundle assets or check .astro templates. For template type errors use astro check.
Every Komal theme defines its collections in src/content.config.ts, covered in our Content Collections docs, so running npx astro sync after cloning a theme from the catalog gets your editor’s types in place before you start writing. Astro’s CLI reference for astro sync lists the flags.
FAQ
What does astro sync do?
It generates TypeScript types for astro:content, astro:env, fonts and integration-provided modules, and runs your content collection loaders so entries and types match your schema.
Do I need to run astro sync manually?
Usually not. astro dev, astro build and astro check run it automatically. Run it yourself after cloning, or before tsc and other tools that don’t sync.
Where does astro sync put the generated types?
In the .astro/ folder at your project root, referenced from .astro/types.d.ts. Keep that folder out of git; it’s regenerated on every run.
Why are my content collection types out of date?
The types were generated before your last schema change. Run npx astro sync, or npx astro sync --force if cached entries are stale too, then restart your editor’s TypeScript server.