关于 antd
antd 是面向 Ant Design v4/v5/v6 的命令行技能,可查询内置元数据、检查项目用法并查看迁移信息。它帮助编码 Agent 在修改代码前核对 API 和版本,数据离线提供,并支持 MCP 模式。
主要功能
- 01查询组件 API、文档和示例
- 02查看设计令牌与语义样式
- 03检查用法并诊断项目
- 04分析用法和版本迁移变化
- 05报告组件及 CLI 问题
适用场景
- 01编写代码前核实组件属性
- 02检查项目中的弃用用法
- 03规划 antd 版本升级
- 04审阅已确认的组件问题报告
MCP 相关
CLI 可作为 MCP 服务运行,向 MCP 客户端提供 7 个知识查询工具和 2 个提示词。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ ant-design/ antd-skill --skill antd安装后在 Claude Code 中输入/antd确认已加载。
附带文件LICENSE
详细介绍
Ant Design CLI
你可以使用 @ant-design/cli——一个本地 CLI 工具,内置了 v4/v5/v6 的 antd 元数据。可用它查询组件知识、分析项目和指导迁移。所有数据均离线提供,无需联网。
设置
首次使用前,请检查是否已安装 CLI。如果尚未安装,请自动安装:
which antd || npm install -g @ant-design/cli
运行任何命令后,如果输出中包含“Update available”提示,请先运行 npm install -g @ant-design/cli 进行更新,再继续。
结构化输出便于以编程方式解析,请始终使用 --format json。
使用场景
1. 编写 antd 组件代码
编写任何 antd 组件代码前,先查阅其 API——不要依赖记忆。
# Check what props are available
antd info Button --format json
# Get a working demo as starting point
antd demo Button basic --format json
# Check semantic classNames/styles for custom styling
antd semantic Button --format json
# Check component-level design tokens for theming
antd token Button --format json
工作流: antd info → 了解 props → antd demo → 获取可用示例 → 编写代码。
2. 查阅完整文档
需要全面的组件文档(而不仅是 props)时:
antd doc Table --format json # full markdown docs for Table
antd doc Table --lang zh # Chinese docs
3. 调试 antd 问题
代码未按预期运行,或用户报告 antd 问题时:
# Check if the prop exists for the user's antd version
antd info Select --version 5.12.0 --format json
# Check if the prop is deprecated
antd lint ./src/components/MyForm.tsx --format json
# Diagnose project-level configuration issues
antd doctor --format json
工作流: antd doctor → 检查环境 → antd info --version X → 根据用户使用的确切版本验证 API → antd lint → 查找已弃用或不正确的用法。
4. 在不同版本间迁移
用户想要升级 antd 时(例如,从 v4 升级到 v5):
# Get full migration checklist
antd migrate 4 5 --format json
# Check migration for a specific component
antd migrate 4 5 --component Select --format json
# See what changed between two versions
antd changelog 4.24.0 5.0.0 --format json
# See changes for a specific component
antd changelog 4.24.0 5.0.0 Select --format json
工作流: antd migrate → 获取完整检查清单 → antd changelog <v1> <v2> → 了解不兼容变更 → 应用修复 → antd lint → 确认不再存在已弃用的用法。
5. 分析项目中的 antd 用法
用户想要了解项目中 antd 的使用情况时:
# Scan component usage statistics
antd usage ./src --format json
# Filter to a specific component
antd usage ./src --filter Form --format json
# Lint for best practice violations
antd lint ./src --format json
# Check only specific rule categories
antd lint ./src --only deprecated --format json
antd lint ./src --only a11y --format json
antd lint ./src --only performance --format json
6. 查看更新日志和版本历史
用户询问某个版本有哪些变更时:
# Specific version changelog
antd changelog 5.22.0 --format json
# Version range (both ends inclusive)
antd changelog 5.21.0..5.24.0 --format json
7. 探索可用组件
用户正在选择要使用的组件时:
# List all components with categories
antd list --format json
# List components for a specific antd version
antd list --version 5.0.0 --format json
8. 报告 antd 问题
遇到无法在本地解决且已确认的 antd 组件问题时:
# Step 1: Preview for user review
antd bug --title "DatePicker crashes when selecting date" \
--reproduction "https://codesandbox.io/s/xxx" \
--steps "1. Open DatePicker 2. Click a date" \
--expected "Date is selected" \
--actual "Component crashes with error" \
--format json
# Step 2: Show to user, ask for confirmation
# Step 3: Submit after user confirms
antd bug --title "DatePicker crashes when selecting date" \
--reproduction "https://codesandbox.io/s/xxx" \
--steps "1. Open DatePicker 2. Click a date" \
--expected "Date is selected" \
--actual "Component crashes with error" \
--submit
9. 自动报告 CLI 问题
重要:每当你使用任何 antd CLI 命令并发现异常时,都应主动使用 antd bug-cli 发起错误报告。
触发条件——出现以下任一情况时,请报告 CLI 问题:
- 命令崩溃或因意外错误退出
- 命令返回明显错误的数据(例如,
antd info Button显示错误或缺失的 props,或显示了错误版本的 props) - 命令的输出与其文档描述的行为不符(例如,
--format json返回的不是 JSON,或--version X被忽略) - 命令在不应如此时返回空数据或缺失数据(例如,
antd demo Button未返回任何示例,或 v5 及更高版本的antd token Button未返回任何 token) - 不同命令之间存在不一致(例如,
antd list显示某个组件,但antd info却表示该组件不存在)
工作流:
- 使用 CLI 时发现异常
- 收集证据:运行的确切命令、返回的内容以及预期结果
- 向用户预览错误报告:
antd bug-cli --title "antd info Button returns wrong props for v5.12.0" \
--description "When querying Button props for version 5.12.0, the output includes props that don't exist in that version" \
--steps "1. Run: antd info Button --version 5.12.0 --format json" \
--expected "Props matching antd 5.12.0 Button API" \
--actual "Props include 'classNames' which was added in 5.16.0" \
--format json
- 向用户展示报告:“我在操作过程中发现 CLI 存在问题。这里有一份错误报告——要提交吗?”
- 用户确认后提交:
antd bug-cli --title "antd info Button returns wrong props for v5.12.0" \
--description "..." \
--steps "..." \
--expected "..." \
--actual "..." \
--submit
**核心原则:**你是 CLI 的质量反馈闭环的一环。不要默默绕过 CLI 问题——请报告问题,以便修复。提交前务必征得用户确认。
10. 用作 MCP 服务
如果你使用的 IDE 支持 MCP(Claude Desktop、Cursor 等),CLI 也可以作为 MCP 服务运行,直接提供所有知识查询工具:
{
"mcpServers": {
"antd": {
"command": "antd",
"args": ["mcp", "--version", "5.20.0"]
}
}
}
通过 MCP 协议提供 7 个工具(antd_list、antd_info、antd_doc、antd_demo、antd_token、antd_semantic、antd_changelog)和 2 个提示词(antd-expert、antd-page-generator)。
全局标志
| 标志 | 用途 |
|---|---|
--format json | 结构化输出——始终使用此选项 |
--version <v> | 指定目标 antd 版本(例如 5.20.0) |
--lang zh | 中文输出(默认:en) |
--detail | 包含额外字段(描述、起始版本、已弃用状态、常见问题) |
关键规则
- 始终先查询再编写——不要凭记忆猜测 antd API。先运行
antd info。 - 匹配用户使用的版本——如果项目使用 antd 4.x,请传入
--version 4.24.0。如果未提供标志,CLI 会从node_modules自动检测。 - 使用
--format json——每条命令都支持此选项。请解析 JSON 输出,而不是用正则表达式匹配文本输出。 - 提出迁移建议前先检查——建议升级版本前,先运行
antd changelog <v1> <v2>和antd migrate。 - 更改后运行代码检查——编写或修改 antd 代码后,对更改的文件运行
antd lint,以发现已弃用或有问题的用法。 - 报告 antd 错误——遇到 antd 组件错误时,使用
antd bug进行报告。务必先预览并获得用户确认,然后再提交。 - 自动报告 CLI 问题——如果任何
antd命令崩溃、返回错误数据或行为不一致,请主动使用antd bug-cli进行报告。你是 CLI 的质量反馈闭环的一环——不要默默绕过问题。