---
title: schema init
description: Fetches the current schema of a Storyblok space and writes it as TypeScript files using @storyblok/schema helpers.
url: https://www.storyblok.com/docs/tooling/cli/schema-init
---

# schema init

Fetches the current schema of a Storyblok space and writes it as TypeScript files using [`@storyblok/schema`](/docs/libraries/js/schema) helpers. This is a one-time bootstrap step for adopting an existing space in code.

The command generates one file per block, one file per datasource, an aggregate `folders.ts` for component groups, and a root `schema.ts` that wires everything into a single exported `schema` object. Blocks are mirrored into subdirectories that follow their component group hierarchy:

```text
.storyblok/
└── schema/
    ├── blocks/
    │   ├── <block-name>.ts
    │   └── <group-slug>/
    │       └── <block-name>.ts
    ├── datasources/
    │   └── <datasource-slug>.ts
    ├── folders.ts
    └── schema.ts
```

After bootstrapping, treat the local files as the source of truth and use [`schema push`](/docs/tooling/cli/schema-push) for further changes.

## Prerequisites

-   The [`@storyblok/schema`](/docs/libraries/js/schema) package must be installed in the target project: `npm install @storyblok/schema`.

## Usage

```bash
storyblok schema init [flags]
```

## Flags

| Flag | Type | Description |
| --- | --- | --- |
| `--space`, `-s` | integer | _Required._ The ID of the Storyblok space to read the schema from. |
| `--out-dir` | string | _Optional._ Output directory for generated files. Defaults to `.storyblok/schema`. |

## Examples

The following examples assume that a `space` has been defined in a configuration file.

```bash
# Bootstrap a local TypeScript schema from a space
storyblok schema init
# Bootstrap into a custom output directory
storyblok schema init --out-dir src/schema
```

## Pagination

-   [Previous: reports prune](/docs/tooling/cli/reports-prune)
-   [Next: schema push](/docs/tooling/cli/schema-push)
