21st-cli-use
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese21st CLI — find, install & generate from the terminal
21st CLI — 从终端查找、安装与生成内容
The CLI (, bin ) is the command-line surface for
the 21st.dev catalog. Search first, install what fits, and only hand-write UI
when nothing matches. To publish your own components/themes/templates, use
the skill; to publish a project's design as a theme, use
.
21stnpx @21st-dev/cli21st21st-registry21st-design-sync21stnpx @21st-dev/cli21st21st-registry21st-design-syncAuth (do this once)
身份验证(只需执行一次)
Two interchangeable credentials, both sent as the API key:
- Login session — opens the browser and saves a token to
npx @21st-dev/cli login. Best for interactive/dev machines.~/.config/21st/auth.json - API key — from https://21st.dev/mcp (or https://21st.dev/settings/api-keys). Pass via
21st_sk_…or the--api-key <key>/TWENTYFIRST_TOKENenv var. Best for CI.API_KEY_21ST
21st whoami21st usage21st logout两种可互换的凭据,均作为API密钥使用:
- 登录会话 — 会打开浏览器,并将令牌保存到
npx @21st-dev/cli login。最适合交互式/开发机器。~/.config/21st/auth.json - API密钥 — 来自**https://21st.dev/mcp**(或**https://21st.dev/settings/api-keys**)的`21st_sk_…`。通过`--api-key <key>TWENTYFIRST_TOKEN
或API_KEY_21ST`环境变量传递。最适合CI环境。/
21st whoami21st usage21st logoutMetering
计量规则
Metadata (search, previews, a theme's CSS) is free. Retrieving component
code (, install) and AI generation are metered per user: a small
free daily quota, then a paywall ( shows what's left). Community
access / membership lifts the quota.
21st get21st usage元数据(搜索、预览、主题CSS)是免费的。获取组件代码(、安装)和AI生成功能按用户计量:每日有少量免费配额,超出后需付费(可查看剩余配额)。社区访问/会员资格可提升配额。
21st get21st usageFind
查找内容
bash
undefinedbash
undefinedSearch everything (components + themes + templates)
搜索所有内容(组件 + 主题 + 模板)
21st search "pricing table" --limit 10
21st search button --type c # components only (c | theme | template)
21st search dark --type theme
21st search "pricing table" --limit 10
21st search button --type c # 仅搜索组件(c | theme | template)
21st search dark --type theme
Filters: --tag <slug> --color <bucket> --sort <s> --free|--paid
筛选条件:--tag <slug> --color <bucket> --sort <s> --free|--paid
--author <username> --mine --liked --json for machine output
--author <username> --mine --liked --json 用于机器可读输出
**Always search before hand-writing a component** — a close match is usually
faster to install and adapt than to build from scratch.
**手写组件前务必先搜索**——通常安装并适配一个相近的匹配项,比从零开始构建更快。Logos
图标
bash
21st logo discord # search brand + UI SVG logos (free, no login)
21st logo "next js" --limit 5 --jsonPrints each logo's name and SVG url(s) to curl straight into a project. Uses the
open svgl.app library; free and unmetered on every plan.
bash
21st logo discord # 搜索品牌和UI SVG图标(免费,无需登录)
21st logo "next js" --limit 5 --json打印每个图标的名称和SVG链接,可直接通过curl导入项目。使用开源svgl.app库;所有套餐均免费且无计量限制。
Pull code
拉取代码
bash
undefinedbash
undefinedPrint a component's code + demo (by the id from search)
打印组件代码 + 示例(使用搜索结果中的id)
21st get 143 [--json]
21st get 143 [--json]
Print a theme's CSS (by a theme id from search --type theme
)
search --type theme打印主题CSS(使用search --type theme
结果中的主题id)
search --type theme21st theme <id> [--json]
undefined21st theme <id> [--json]
undefinedInstall
安装
bash
undefinedbash
undefinedInstall a component into the current project (shadcn under the hood)
将组件安装到当前项目(底层基于shadcn)
21st add <user>/<slug> # e.g. 21st add shadcn/button
21st add @<team>/<slug> # from a team library
21st add <user>/<slug> # 示例:21st add shadcn/button
21st add @<team>/<slug> # 从团队库安装
--print to dump the shadcn command instead of running it
--print 参数用于输出shadcn命令而非直接执行
`21st add` resolves the registry item, writes it to `components/ui/<slug>.tsx`,
and installs npm deps with the project's package manager. Public/unlisted items
also work with stock shadcn:
`npx shadcn@latest add "https://21st.dev/r/<user>/<slug>"`.
`21st add`会解析注册表项,将其写入`components/ui/<slug>.tsx`,并通过项目的包管理器安装npm依赖。公开/未公开的项目也可配合原生shadcn使用:
`npx shadcn@latest add "https://21st.dev/r/<user>/<slug>"`。Generate
生成内容
When nothing in the catalog fits, sketch it with 21st AI and iterate on it
from the terminal — that whole loop ( → →
→ ) lives in the skill:
21st generategenerationiteratetake21st-aibash
21st generate "a glassy pricing section with a monthly/yearly toggle"Opens a preview; from there you edit any variant and pull its code. See the
skill for the full generate/iterate/grab-code flow and metering.
21st-ai当目录中没有合适的内容时,通过21st AI快速生成原型,并从终端进行迭代——整个流程( → → → )都在****技能中实现:
21st generategenerationiteratetake21st-aibash
21st generate "a glassy pricing section with a monthly/yearly toggle"打开预览界面;你可以在其中编辑任何变体并拉取其代码。有关完整的生成/迭代/获取代码流程及计量规则,请查看技能。
21st-aiBookmarks, teams & MCP config
书签、团队与MCP配置
bash
21st bookmarks [--type component|theme|template]
21st bookmark <id> --type <kind> [--remove] # heart / un-heart
21st lists # your bookmark lists
21st list <listId>
21st teams # your teams
21st team <teamId> # a team's libraries
21st team-components <teamId> [--library <id>]
21st init --client cursor|claude|codex|vscode|windsurf [--write] # write MCP config
21st install-skill # install the 21st skills globallybash
21st bookmarks [--type component|theme|template]
21st bookmark <id> --type <kind> [--remove] # 添加/取消收藏
21st lists # 查看你的书签列表
21st list <listId>
21st teams # 查看你的团队
21st team <teamId> # 查看团队的库
21st team-components <teamId> [--library <id>]
21st init --client cursor|claude|codex|vscode|windsurf [--write] # 写入MCP配置
21st install-skill # 全局安装21st技能