mcpField
E
extract

extract

github.com/alirezarezvaniAgent 工作流29.0k1.6k 次安装今天更新
代码仓库

关于 extract

一项将反复出现的模式或调试方案整理为独立、可移植技能的技能,便于在不同项目中复用。它引导筛选模式、命名、生成文件并执行质量检查。

主要功能

  1. 01识别可复用模式
  2. 02确定技能范围与名称
  3. 03由 Agent 生成技能文件
  4. 04检查结构与可移植性
  5. 05通过 dry-run 预览变更

适用场景

  1. 01保存反复使用的调试方案
  2. 02封装多步骤工作流以便复用
  3. 03将经验整理为不依赖特定项目的技能

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/alirezarezvani/claude-skills --skill extract

安装后在 Claude Code 中输入/extract确认已加载。

详细介绍

/si:extract — 从模式中创建 Skills

将重复出现的模式或调试方案转化为独立、可移植的 skill,可安装到任何项目中。

用法

/si:extract <pattern description>                  # Interactive extraction
/si:extract <pattern> --name docker-m1-fixes       # Specify skill name
/si:extract <pattern> --output ./skills/            # Custom output directory
/si:extract <pattern> --dry-run                     # Preview without creating files

何时提取

当满足以下任一条件时,一条经验即适合提取为 skill:

标准信号
重复出现同一问题出现在 2 个及以上项目中
非显而易见需要实际调试才能发现
广泛适用不局限于某一个特定代码库
复杂方案多步骤修复,且容易遗忘
用户标记"把这个保存为 skill"、"我想复用这个"

工作流程

第 1 步:识别模式

阅读用户的描述。在 auto-memory 中搜索相关条目:

MEMORY_DIR="$HOME/.claude/projects/$(pwd | sed 's|/|%2F|g; s|%2F|/|; s|^/||')/memory"
grep -rni "<keywords>" "$MEMORY_DIR/"

如果在 auto-memory 中找到,则将这些条目用作源材料。如果没有找到,则直接使用用户的描述。

第 2 步:确定 skill 范围

提问(最多 2 个问题):

  • "这个 skill 要解决什么问题?"(如果不清楚)
  • "是否需要包含代码示例?"(如适用)
第 3 步:生成 skill 名称

命名规则:

  • 使用小写字母,单词之间用连字符连接
  • 描述性强但简洁(2 到 4 个词)
  • 示例:docker-m1-fixes、api-timeout-patterns、pnpm-workspace-setup

保留片段——名称中不得出现:

  • claude
  • anthropic

对于关于 Claude Code 本身的 skill,请改用 cc- 前缀:

  • ❌ claude-code-settings → ✅ cc-settings
  • ❌ claude-code-maintenance → ✅ cc-maintenance
  • ❌ claude-mcp-tools → ✅ cc-mcp-tools
  • ❌ claude-plugin-development → ✅ cc-plugin-development

在写入 skill 目录之前,请将拟定名称与此列表进行核对。 如果包含保留片段,则进行转换(删除该片段,或将 claude*/anthropic* 前缀替换为 cc-),并与用户确认。

第 4 步:创建 skill 文件

启动 skill-extractor Agent 来实际生成文件。

该 Agent 会创建:

<skill-name>/
├── SKILL.md            # Main skill file with frontmatter
├── README.md           # Human-readable overview
└── reference/          # (optional) Supporting documentation
    └── examples.md     # Concrete examples and edge cases
第 5 步:SKILL.md 结构

生成的 SKILL.md 必须遵循以下格式:

---
name: "skill-name"
description: "<one-line description>. Use when: <trigger conditions>."
---

# <Skill Title>

> One-line summary of what this skill solves.

## Quick Reference

| Problem | Solution |
|---------|----------|
| {{problem 1}} | {{solution 1}} |
| {{problem 2}} | {{solution 2}} |

## The Problem

{{2-3 sentences explaining what goes wrong and why it's non-obvious.}}

## Solutions

### Option 1: {{Name}} (Recommended)

{{Step-by-step with code examples.}}

### Option 2: {{Alternative}}

{{For when Option 1 doesn't apply.}}

## Trade-offs

| Approach | Pros | Cons |
|----------|------|------|
| Option 1 | {{pros}} | {{cons}} |
| Option 2 | {{pros}} | {{cons}} |

## Edge Cases

- {{edge case 1 and how to handle it}}
- {{edge case 2 and how to handle it}}
第 6 步:质量检查

在最终确定之前,请验证:

  • SKILL.md 包含有效的 YAML frontmatter,且含有 name 和 description
  • name 与文件夹名称一致(小写字母,使用连字符)
  • name 不包含保留片段 claude 或 anthropic(Claude Code 相关 skill 使用 cc- 前缀)
  • 描述中包含 "Use when:" 触发条件
  • 解决方案自包含(无需外部上下文)
  • 代码示例完整且可直接复制粘贴
  • 没有项目特定的硬编码值(路径、URL、凭据)
  • 没有不必要的依赖
第 7 步:报告
✅ Skill extracted: {{skill-name}}

Files created:
  {{path}}/SKILL.md          ({{lines}} lines)
  {{path}}/README.md         ({{lines}} lines)
  {{path}}/reference/examples.md  ({{lines}} lines)

Install: /plugin install (copy to your skills directory)
Publish: clawhub publish {{path}}

Source: MEMORY.md entries at lines {{n, m, ...}} (retained — the skill is portable, the memory is project-specific)

示例

提取调试模式
/si:extract "Fix for Docker builds failing on Apple Silicon with platform mismatch"

会创建 docker-m1-fixes/SKILL.md,其中包含:

  • 平台不匹配错误信息
  • 三种解决方案(构建参数、Dockerfile、docker-compose)
  • 权衡对比表
  • 关于 Rosetta 2 模拟的性能说明
提取工作流模式
/si:extract "Always regenerate TypeScript API client after modifying OpenAPI spec"

会创建 api-client-regen/SKILL.md,其中包含:

  • 为什么需要手动重新生成
  • 确切的命令序列
  • CI 集成代码片段
  • 常见故障模式

提示

  • 提取那些能在其他项目中节省时间的模式
  • 保持 skill 聚焦——每个 skill 只解决一个问题
  • 包含人们可能会搜索的错误信息
  • 通过在没有原始上下文的情况下阅读 skill 来测试它——它是否说得通?

评论

支持 Markdown