apps/www/content/docs/get-started/cli.mdx
The Chakra UI CLI can be used to generate typings for your custom theme tokens, like colors, semantic tokens, recipe variants, etc. You can also add community snippets and premium Pro blocks to your project.
In order to use the CLI, you need to install it as a dev dependency in your project:
:::code-group
npm i -D @chakra-ui/cli
pnpm add -D @chakra-ui/cli
bun add -d @chakra-ui/cli
:::
:::warning
To use the CLI tool, please ensure that the version of Node.js is >= 20.6.0.
:::
Use the Chakra CLI to run any of the commands listed below with your preferred package manager.
Usage: npx chakra [options] [command]
The official CLI for Chakra UI projects
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
typegen [options] <source> Generate theme and recipe typings
snippet Add snippets to your project for better DX
blocks Add Chakra UI Pro blocks to your project
eject [options] Take control over the default theme tokens and recipes
help [command] display help for command
chakra typegenGenerates theme and recipe typings for your custom theme. This helps to provide autocompletion and type safety in your project.
# Generate typings
chakra typegen src/theme.ts
# Watch for changes and rebuild
chakra typegen src/theme.ts --watch
# Generate strict types for props variant and size
chakra typegen src/theme.ts --strict
The typegen command works in both development and CI/CD. It is not
limited to local use—run it everywhere your project is built or installed so
generated types stay up to date.
Run typegen if all of these are true:
If you're using JavaScript only, or TypeScript without custom Chakra theme
types, typegen is optional.
Add typegen to the postinstall or prepare script of the frontend
application that uses Chakra UI. This keeps types generated:
npm install / pnpm install / bun install (local development)npm ci or similar{
"scripts": {
"postinstall": "chakra typegen src/theme.ts",
"prepare": "chakra typegen src/theme.ts"
}
}
:::tip
Use postinstall if you want types after every install. Use prepare if you
also want it to run when the package is packed (for publishing). Pick one to
avoid running typegen twice.
:::
Run typegen before type-checking and build steps in CI.
{
"scripts": {
"typegen": "chakra typegen src/theme.ts",
"typecheck": "npm run typegen && tsc --noEmit",
"build": "npm run typegen && your-build-command"
}
}
This prevents CI failures caused by stale or missing Chakra types.
In a monorepo (e.g. pnpm workspaces), run typegen in the package that
depends on Chakra UI—typically your frontend application—not at the monorepo
root.
@chakra-ui/cli as a dev dependency in the frontend package.postinstall or prepare script to that package's package.json.// packages/frontend/package.json
{
"scripts": {
"postinstall": "chakra typegen src/theme.ts"
},
"dependencies": {
"@chakra-ui/react": "..."
},
"devDependencies": {
"@chakra-ui/cli": "..."
}
}
When you run pnpm install at the root, that frontend package's postinstall
runs and generates types in the right place.
By default, no. The CLI writes generated files to Chakra's installed package
types directory (node_modules/@chakra-ui/react/types/styled-system/generated),
which should not be committed.
If you use a custom --outdir inside your repository, follow your team's
codegen policy. In most cases, regenerating in CI is better than committing
generated files.
chakra snippetGenerates useful component compositions that boost your development speed.
# Add all snippets
chakra snippet add --all
# Add a specific snippet
chakra snippet add button
# List all available snippets
chakra snippet list
# Specify a custom directory
chakra snippet add dialog --outdir ./components/custom
chakra blocksAdd premium blocks from Chakra UI Pro to your project. These are professionally designed, fully responsive components that you can customize for your needs.
# Interactive block selection
chakra blocks add
# Add all variants of a specific block
chakra blocks add hero
# Add a specific variant of a block
chakra blocks add hero --variant "simple"
# List available blocks
chakra blocks list
# List blocks in a specific category
chakra blocks list --category "marketing"
# Preview blocks without downloading
chakra blocks add --dry-run --category "marketing"
# Specify output directory
chakra blocks add --outdir ./components/blocks
To use Pro blocks, you need a Chakra UI Pro subscription and API key:
Get your API key from Chakra UI Pro
Set the environment variable:
export CHAKRA_UI_PRO_API_KEY="your-api-key"
Or create a .env file in your project root:
CHAKRA_UI_PRO_API_KEY=your-api-key
Add it to your shell profile (.bashrc, .zshrc, etc.) for persistence if
using environment variables
--variant <variant>: Add a specific variant instead of all variants--outdir <dir>: Specify output directory for blocks--force: Overwrite existing files--dry-run: Preview what will be downloaded without writing files--tsx: Force TypeScript JSX format (auto-detected by default)chakra ejectGenerates the file(s) that contain the default theme tokens and recipes so you can have full control over them.
# Copy the tokens and recipes to your project
chakra eject --outdir src/theme
No. The typegen command works in both development and CI/CD. Add it to
postinstall or prepare so it runs after installs—locally and in your CI
pipeline.
Yes. If you enable strictTokens, run typegen in local and CI workflows so
token types stay in sync with your theme.
After generating the typings, you need to "Restart TS Server" for the autocomplete to show up.
Alternatively, you can install the @chakra-ui/cli package locally as a dev
dependency and run the chakra typegen command to generate the typings.