The Builder CLI is a command-line tool that powers several key functions for developers including code generation, code sync, and more.
- Command-line scripts are accessible through the builder.io/dev-tools NPM package.
- Some of the commands in this document are for Publish Spaces, while others are for Fusion Spaces.
Prerequisite for Publish
If you have a Publish Space, you must have integrated your codebase with Builder to use the Builder CLI. For more details, see Publish Quickstart.
Space type: Publish Space
Requirements: a Builder snippet ID
The add command adds code generated from a Publish Space to your local codebase. When successfully run, the command creates new files within a given directory. Replace <SNIPPET_ID> with your code snippet's ID.
npx "@builder.io/dev-tools@latest" add <SNIPPET_ID>To access a snippet ID:
- Within a Fusion Project, click the Develop tab.
- Click Generate Code.
- Adjust the code by prompting the AI as desired. For more details, see Get Started with Fusion.
- Click Sync Code.
An add script appears which includes the snippet ID.
Space type: Fusion or Publish Space
The auth command re-triggers authentication from the command line. This is useful should you need to change your authenticated Space or you are having any issues with authentication.
npx "@builder.io/dev-tools@latest" authTo reset your credential and log out, include the --reset flag.
npx "@builder.io/dev-tools@latest" auth --resetSpace type: Fusion or Publish Space
The auth status shows information about your Space and user account.
npx "@builder.io/dev-tools@latest" auth statusSpace type: Fusion or Publish Space
Requirements: a Builder fiddle URL, your Public API Key
The code command triggers code generation within a local codebase. Replace <URL> with your design URL and SPACE_ID with your Space's Public API Key.
npx "@builder.io/dev-tools@latest" code --url <URL> --spaceId <SPACE_ID>The code command can take the following flags:
| flag | description |
|---|---|
| The working directory for the command. |
| View usage instructions and additional flags. |
| Provide instructions through the command line rather than an interactive dialog with the CLI. |
| Your Space's Public API Key |
| The design URL to generate code from. |
| Disable MCP server support. |
| Enable privacy mode for codegen (encrypts sensitive data). |
There are two types of configuration files that can be used with the code command to customize code output.
- File exclusion configuration, like
.builderignore. - Rule files, such files within
.builder/rules/or separate.builderrulesfiles.
Additionally, Builder CLI recognizes .cursorrules files used by the Cursor AI Code Editor. For more detail on creating rules for the the Fusion AI, see Project configuration files.
Space type: a Fusion Space
Requirements: a local repository
The index-repo command analyzes your entire repository to understand your component architecture and typically achieves high mapping accuracy, enabling effective code generation.
npx "@builder.io/dev-tools@latest" index-repoThe index-repo command can take the following flags:
| flag | description |
|---|---|
| Your Space's Public API Key |
| Provide a specific package or scope to focus the command, such as |
| Increase the scope of indexing outside of the current directory by providing a comma-separated list of absolute paths. This is not necessary if component definitions are in the workspace you are indexing. |
| Skip the display headers. This is useful for CI or automation. |
| When set to |
| When set to |
| When set to |
| Provide the working directory for the command. |
| Allow the re-indexing process to focus on a specific component or list of components. This is useful when testing or refining document creation.
|
To instead generate code using a web interface, visit Figma to Fusion. If you'd rather generate code through a command-line interface, Generate Code with Builder CLI.