如何使用 Claude Code(又称 Claudinho)的技能

发布: (2026年4月28日 GMT+8 22:17)
4 分钟阅读
原文: Dev.to

Source: Dev.to

介绍

作为使用 Claude 的起点,我一直在尝试充分利用它的功能。在与朋友聊天时,我们开始讨论 skills(技能)。

什么是 Skills?

在 Claude 文档中,skills 是带有额外上下文的更个性化的代理。例如,在让聊天生成新报告之前,你可以说:

“以减脂目标的营养师身份,为我制定最佳的饮食方案。”

随后,代理在该目标上会更加精准。如果你想在以后任务中复用该上下文,skills 是最佳选择。你可以创建一个单一指令,在不同目标之间复用该上下文。

创建代码审查 Skill

在工作中,我们经常遇到 RuboCop 问题,因为项目包含需要重构以符合 RuboCop 规则的遗留代码。这很繁琐,所以我创建了一个 skill,在我们将代码推送到 GitHub 之前处理审查。

Skill 定义

# Create a /review-code skill to review Ruby and JavaScript code.
# The skill will:
# • Read the project's .rubocop.yml and .eslintrc.js files and extract the configured rules.
# • Identify files to review:
#     - If no argument is passed, run `git diff main...HEAD --name-only`
#       and read each relevant file before reviewing.
# • Produce a report with sections:
#     - Ruby rules grouped by category (Lint, Security, Metrics, Naming, Style, Layout)
#       – separating blocks that must be merged from warnings.
#     - JavaScript rules grouped (Errors, Warnings, Modern code in app/webpack/,
#       Vue, Legacy code in app/assets/javascripts/).
# • Report format:
#     🔴 Blockers
#     🟡 Warnings
#     🟢 Good practices observed
#     📋 Summary
# • Be direct and specific: quote the problematic snippet and show the corrected version.
#   Do not list rules that were not violated.

工作原理

  1. 读取配置文件 – 该 skill 解析 .rubocop.yml.eslintrc.js,以了解哪些规则是激活的。

  2. 选择文件 – 如果在没有参数的情况下运行该 skill,它会执行

    git diff main...HEAD --name-only

    并过滤出 Ruby (*.rb) 和 JavaScript (*.js, *.vue) 文件。

  3. 分析代码 – 对每个文件,skill 检查相关规则并将发现分类为 Blockers(阻断项)、Warnings(警告)或 Good practices(良好实践)。

  4. 生成报告 – 输出遵循上面列出的带表情符号的章节,引用违规片段并提供修正后的代码。

使用 Skill

在定义 skill 之后,它会在你的 Claude 项目会话中可用。通过输入斜杠指令来调用它:

/review-code

如果只想审查代码库的某个子集,也可以将特定文件或目录作为参数传入。skill 将返回一份简明、可操作的报告,帮助你在提交之前应用建议的修复。

0 浏览
Back to Blog

相关文章

阅读更多 »