@21st-dev/cli

中文文档
1.18.0发布于 2026/10/07MITES Module零依赖近 30 天下载 3.5万

The 21st CLI: search, retrieve and install 21st.dev components from your terminal, and configure the 21st MCP for your editor.

原始使用文档
文档目录7 节
  1. Install
  2. Sign in
  3. Commands
  4. How it works
  5. 1.17.1
  6. Docs
  7. License

21st CLI

Search, retrieve, install and publish 21st.dev components, themes and templates from your terminal, generate UI with 21st AI, and wire the 21st MCP into your editor. The CLI and the 21st MCP share one endpoint and one login, so every command returns exactly what an MCP client (Cursor, Claude, etc.) sees.

One unified CLI. @21st-dev/cli (bin 21st) is now the single tool for everything 21st. It supersedes the older @21st-dev/registry (publish/install) and @21st-dev/magic (Magic MCP) packages — use 21st for all of it. Old @21st-dev/magic configs keep working: since 0.2.0 that package is a thin proxy to the same 21st MCP endpoint this CLI configures.

Install

npm i -g @21st-dev/cli
# or run without installing:
npx @21st-dev/cli search "pricing table"

Sign in

21st login      # opens your browser, saves a token locally (~/.config/21st)
21st whoami     # show the signed-in account
21st usage      # retrieval tier/quota + hosted AI access
21st usage --json # structured account capabilities, including aiGenerationEnabled

You can also authenticate with an API key from https://21st.dev/settings/api-keys via the TWENTYFIRST_TOKEN (or API_KEY_21ST) env var, or the --api-key <key> / --token <key> flag. A retired an_… key left in an env var is skipped so it can't shadow a working 21st login session.

Commands

CommandWhat it does
21st search <query> [--type component|theme|template] [--context auto|path] [--tag] [--color] [--sort] [--json]Search metadata; Design Context adds confidence and fit rationales.
21st logo <query> [--limit N] [--json]Search brand + UI SVG logos. Free, no login required.
21st get <id> [--json]Print one component's code + demo by its search id (metered).
21st theme <id> [--json]Print one theme's CSS by its search id — free.
21st add <user>/<slug> [--print]Install a component via the 21st shadcn registry.
21st bookmarks [--type ...] [--limit N] / 21st bookmark <id> --type <kind> [--remove]List / add / remove a bookmark ("heart") across any entity.
21st lists / 21st list <listId> / 21st list-new <name> / 21st list-add <listId> <id> --type <kind> [--remove]Manage named bookmark lists.
21st teams / 21st team <teamId> / 21st team-lists <teamId> / 21st team-components <teamId> [--library <id>]Browse your teams' shared libraries + lists.
21st components [--status all|draft|published|private] [--scope all|personal|team:<uuid>] [--json]List every accessible personal/Team component and owned draft, using stable refs.
21st open <component:<id>|draft:<uuid>> [--no-open]Resume a draft or create/resume a reviewed revision of an existing component; --no-open prints its URL.
21st publish <Component.tsx> [--component component:<id>] --description "…" [--to <library-slug>] [--preview <image>] [--no-open]Create a draft, open CLI Review with live demos and automatic media, then publish a new component or an explicit owned revision.
21st submit <slug> / withdraw / resubmit / remove-from-catalogManage catalog review separately from Published/Private access.
21st publish-theme <theme.css> --name "…" [--tags a,b]Publish a theme (CSS with :root + .dark).
21st publish-template <name> --site <url> --preview <img-url> [--price N]Submit a template listing for review.
21st publish-gradient <recipe.json> --name "…" --thumbnail <image>Publish a Gradient Builder recipe to the API key's scope.
21st publish-ascii <recipe.json> --name "…" --thumbnail <image> [--video <file>] [--mask <file>] [--private]Publish an ASCII recipe to the API key's scope.
21st edit component:<id> --type component [...] / 21st delete component:<id> --type component --yesEdit or unpublish the exact component returned by inventory, including manageable team components.
21st edit <id> --type <theme|template> [...] / 21st delete <id> --type <theme|template> --yesEdit or remove a theme/template using its existing API-key-scoped id semantics.
21st delete draft:<uuid> --type draft --yesPermanently delete an owned draft and its unpublished sandbox.
21st publish <file> --prepare [--wait-video] [--media-dir <dir>] / 21st publish <file> --draft draft:<uuid> --auto [--wait-video]Headless flow: prepare revision-bound media without publishing, then publish that exact draft entirely from the CLI.
21st profile get [--json] / 21st profile set --file <path.json> [--clear] / 21st profile upload <image>Read, replace, or clear your bento profile board and upload media for it (requires a 21st_sk_… API key).
21st inspiration-feedback <feedbackId> --outcome accepted|rejectedRecord a privacy-safe inspiration decision.
21st generate "<prompt>" [--context auto|path] [--variants N]Generate grounded alternatives with hosted 21st AI access and AI credits, then open their preview.
21st generation <projectId> / 21st iterate <projectId> "<change>" [--take N] / 21st take <projectId> [--take N] [--code] [--select]List a sketch generation's takes, refine one, and grab its code (generation/take are free).
21st init --design-context [--check|--refresh]Create or verify .21st/design.json and .21st/DESIGN.md.
21st review <path...> [--fix] [--json]Run deterministic local UI review and conservative fixes.
21st skills install|list|check|update|removeManage verified skills for Claude, Cursor, and Codex.
21st skills catalogInspect curated compatibility; broad discovery stays on skills.sh.
21st install-skillCompatibility alias for 21st skills install --global.
21st init --client <name> [--write]Print or write the 21st MCP config for an editor.
21st login / logout / whoami / usage [--json]Manage your local session and see retrieval quota plus hosted AI access.

For a new component slug, publish opens the dedicated CLI Review and waits for its final Publish action. The review shows the live selected demo and the total demo count. It starts a required cover first and attempts an optional best-effort video in the background; publishing remains locked until every demo has a valid cover, but does not wait for video. A video is accepted only when a required interaction produces a visible result, so interactive controls should expose stable semantic selectors such as an id, native role, or data-slot. A ready video is included, and generated media can always be replaced manually. The CLI also rejects non-portable theme expressions such as oklch(var(--primary)); use bg-primary or var(--color-primary). --preview stages an initial cover but does not bypass confirmation, and --no-open prints the review URL without launching it. The current CLI command seeds one self-contained component and one demo; the review itself supports multiple demos. In CI the command prints the structured draft result and exits with code 2 instead of waiting. Both a 21st login session and a real API key (21st_sk_… from https://21st.dev/settings/api-keys) are accepted for component publishing and component metadata management. Theme/template management keeps its existing API-key semantics.

21st components drains both independent server cursors before printing, so the default --status all --scope all output contains every accessible personal or Team component and every owned draft rather than a first-page sample. 21st open draft:<uuid> resumes that draft. 21st open component:<id> creates or resumes a server-owned CLI Review revision from the retained published component code and demos; the live component stays unchanged until the revision is published. The revision requires fresh covers, while optional video generation runs best-effort in the background. --no-open creates or resumes the workspace and prints its URL without launching a browser.

Only the original component author can check out a code revision. A Team manager can still edit or unpublish a teammate's component metadata by its stable component:<id> ref. If retained source, dependencies, style, support files, or the default demo cannot be reproduced safely, checkout fails closed; use 21st publish <file> --component component:<id> with a local source file instead. Proof-backed legacy CLI drafts are recovered into inventory for their authenticated scope; an older unsigned draft whose scope cannot be proven may need to be recreated. Inventory, component checkout, and component metadata edit/delete accept the saved 21st login session or an API key. Theme/template management keeps its API-key requirement.

--client accepts cursor, claude, codex, vscode, or devin (Devin Desktop, formerly Windsurf; windsurf is still accepted as an alias). With --write, the config is merged into your existing MCP config (it won't clobber other servers).

How it works

Search and all metadata/list commands are free; retrieving a component's code (21st get, or the MCP get_component tool) is the metered action — themes are free to retrieve too. Signed-in free accounts get a small daily component-code allowance, then an upgrade prompt; members get unlimited retrieval. Private/team components are gated by team membership instead, never metered.

Hosted 21st AI is a separate capability: Builder component access alone does not enable generate or iterate. Check 21st usage --json before generating; only aiGenerationEnabled: true confirms AI access, and this field does not report the remaining AI credit balance. With AI off, use 21st search and 21st get, then adapt the returned code with your own coding agent. Existing generations remain readable through 21st generation and 21st take.

The MCP hides generate and iterate_generation when AI access is off. Cached calls and direct CLI commands return ai_subscription_required with guidance to use search and component retrieval; do not retry generation until AI access is enabled. Refresh the MCP tool list or reconnect after enabling AI. generate --json and iterate --json preserve the denial reason and exit nonzero.

1.17.1

  • 21st usage --json now returns the MCP's structured account capabilities, including hosted AI access when the server reports it.
  • Clarified the separate requirements for component retrieval and hosted AI, including the workflow for using your own coding agent with AI off.

Docs

Full guides live at help.21st.dev/cli — publishing (every flag, exit code and failure mode), finding and installing, 21st AI, project-aware design, and the command reference.

License

MIT © 21st.dev

版本与发布记录

@21st-dev/cli 共发布 66 个版本,首次发布于 2025/03/25;过去 12 个月发布了 42 个版本。

版本发布日期距今
1.18.0latest2026/10/0730 天前
1.17.12026/09/101 个月前
1.17.02026/09/012 个月前
1.16.12026/08/272 个月前
1.16.02026/08/212 个月前
1.15.22026/08/202 个月前

其他发布通道:beta → 1.1.5。

关于 @21st-dev/cli 的常见问题

@21st-dev/cli 是什么?

The 21st CLI: search, retrieve and install 21st.dev components from your terminal, and configure the 21st MCP for your editor.

如何安装 @21st-dev/cli?

在项目目录运行 npm install @21st-dev/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 21st,可以用 npx 21st 直接运行。

@21st-dev/cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/21st-dev__cli 是否存在。

@21st-dev/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@21st-dev/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@21st-dev/cli 可以商用吗?

@21st-dev/cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@21st-dev/cli 的下载量有多少?

根据 npm 官方下载统计,@21st-dev/cli 在 2026/10/05 – 2026/11/03 这 30 天内被下载 35,215 次,日均约 1,174 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@21st-dev/cli 还在维护吗?

最新版本 1.18.0 发布于 2026/10/07(30 天前);至今共发布 66 个版本,其中过去 12 个月发布了 42 个;首次发布于 2025/03/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。