← BLOG
Tutorial

为 Claude 代码创建自定义技能和命令

技能将重复的提示变为可重复使用的命令. 写一个SKILL.md一次,用/skill-name来引用它,克洛德代码每次执行全部工作流程.

技能是为 Claude Code 定义可重用工作流程的 Markdown 文件。您无需每次想要部署、运行代码审查或生成文档时都键入相同的复杂提示,只需编写一次 SKILL.md 并使用斜杠命令调用它即可。

什么是克劳德代码技能?

技能是一个 Markdown 文件 (SKILL.md),其中包含 Claude Code 在调用它时遵循的指令。它可以包括描述、工具限制、上下文设置和分步说明。将其视为具有超能力的已保存提示。

如何创建技能?

在您的项目的. claude/ 技能/ 目录( 与团队共享) 或 ~/. claude/ 技能/( 个人) 中创建 SKILL. md 文件 :

# .claude/skills/deploy.md
---
name: deploy
description: Deploy the current branch to staging
allowed-tools: Bash, Read
---

## Steps
1. Run the test suite: `npm run test`
2. If tests pass, build the project: `npm run build`
3. Deploy to staging: `npm run deploy:staging`
4. Verify the deployment by checking the health endpoint
5. Post a summary of what was deployed

现在您可以调用它:

# In Claude Code
> /deploy

现有哪些前题选项?

选项它会做什么示例
名称斜线命令名称部署
说明在技能列表中显示部署至中转
允许的工具限制技能可以使用的工具巴什,读取, 编辑
禁用模式调用防止接通人工智能电话真实
上下文会话处理叉 (在孤立上下文中运行)

在技能方面有什么好的应用?

  • +部署工作流程(测试-建立-部署-核查)
  • +代码审查核对表(安全、性能、样式)
  • +文档生成( API 文件、 更改日志、 READMEs)
  • +数据库操作(迁移、种子、备份)
  • +接纳新队员(项目巡视、设置核查)
  • +发布管理(版本出错、更改日志、标签、发布)

在技能方面如何使用变量?

通过 $ARGUMENTS(全文)和位置变量(0美元、1美元等)提供技能支持参数:

# .claude/skills/create-component.md
---
name: create-component
description: Create a new React component
---

Create a new React component named $0 in the components directory.

Requirements:
- TypeScript with proper props interface
- Tailwind CSS for styling
- Export as default
- Include basic unit test in __tests__/

Usage: /create-component UserProfile

有论据的引用

# Single argument
> /create-component UserProfile

# Multiple arguments
> /create-component UserProfile --with-tests --with-story

你怎么和你的团队分享技能?

将技能输入您的项目中的 . claude/ 技能/ 目录, 并将它们指定为 git 。 每个复制回波的开发者都获得同样的技能. 个人技能进入~.claude/技能/,不分享.

常见问题

QQ 回博客时免费开始——单元1