Extract successful experiences and lessons learned from the context of the current session, and automatically generate a reusable Claude Code Skill file.
Background
This is a "meta-skill"—a skill used to create other skills. By analyzing the tasks completed in the current session, it extracts key steps, common pitfalls, and best practices, solidifying one-off problem solving into a repeatable workflow.
Instructions
You are an experience extraction assistant, helping users turn work experience from a session into a reusable Claude Code Skill. Please follow these steps:
Step 1: Analyze the current session context
Review the entire session history, identify and extract the following information:
- Original requirement: What problem did the user initially want to solve?
- Execution steps: What key steps were taken to complete the task?
- Failed experiences: Which attempts failed? What were the reasons for the failure?
- Successful solution: What solution was ultimately adopted?
- Key findings: What important precautions, checkpoints, or tips are there?
Step 2: Collect user input
⚠️ Required: Use the AskUserQuestion tool to collect necessary information.
Use the AskUserQuestion tool to ask the user:
-
Skill name: What is this skill called?
- Let the user input it; suggest using kebab-case format (e.g.
api-caller、file-processor)
- Let the user input it; suggest using kebab-case format (e.g.
-
Main function description: Describe in one sentence what this skill does
- Let the user input it or suggest based on the analysis results
-
Trigger words: What words will users use to trigger this skill?
- Let the user input them; suggest 2-3 in each of Chinese and English
-
Save location:
- Options:
- "Current plugin directory skills/ (Recommended)"
- "Custom path"
- Options:
Step 3: Decide whether scripts are needed
Automatically determine whether supporting scripts are needed based on the nature of the task (do not ask the user):
Cases where scripts are needed:
- Calling external APIs (such as OpenRouter, OpenAI, etc.)
- Complex file processing (binary files, encoding conversion, etc.)
- Requires specific libraries (such as ffmpeg, whisper, etc.)
- Involves network requests, data parsing, etc.
Cases where scripts are not needed:
- Purely prompt-driven workflows
- Mainly combinations of bash commands
- Simple file operations
Script language selection:
- Prefer Python, using the uv script format (inline dependency declarations)
- When JavaScript is needed, use Bun (built into Max, faster than Node.js)
Python uv script template:
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests",
# "其他依赖",
# ]
# ///
import sys
# 脚本内容...
Step 4: Generate SKILL.md content
Based on the analysis results and user input, generate SKILL.md in the following format:
---
name: {skill-name}
description: {功能描述}。Use when user wants to {触发词1}, {触发词2}, {trigger1}, {trigger2}.
---
# {Skill Title}
{简要说明这个 skill 的功能和来源}
## Background
> 此 skill 从 [具体任务描述] 的实践经验中提取。
{描述这个 skill 解决的问题场景}
## Prerequisites
{列出依赖条件,如环境变量、工具等}
## Instructions
{详细的执行步骤,来自成功的方案}
### Step 1: {步骤标题}
{具体操作}
### Step 2: {步骤标题}
{具体操作}
...
## Common Pitfalls
{从失败经验中提取的常见陷阱}
| 错误做法 | 正确做法 | 原因 |
|---------|---------|------|
| ❌ {错误示例} | ✅ {正确示例} | {解释} |
## Best Practices
{从成功经验中提取的最佳实践}
- {实践1}
- {实践2}
- ...
## Troubleshooting
{常见问题及解决方案,来自实际遇到的错误}
**问题:{问题描述}**
- 原因:{原因分析}
- 解决:{解决方案}
## Example Interaction
{一个典型的使用示例}
用户:{示例输入}
助手:
1. {步骤1}
2. {步骤2}
...
Step 5: Write the file
Use the Write tool to write the generated content to the corresponding directory:
skills/{skill-name}/SKILL.md
skills/{skill-name}/{script-name}.py # 如果需要脚本
If a Python script was created, add executable permissions:
chmod +x skills/{skill-name}/{script-name}.py
Step 6: Update documentation (optional)
Ask the user whether CLAUDE.md needs to be updated to register the new skill:
- Update the project structure diagram
- Update the Skills table
Step 7: Show the results
After completion, tell the user:
- The path of the created file
- How to use the Skill
- The list of trigger words
Output Quality Guidelines
The generated SKILL.md should:
- Executable: The steps are clear and can be followed directly
- Valuable: Contains genuinely useful experience, not vague generalities
- Pitfall avoidance first: Highlights failure experiences and common pitfalls
- Code examples: Key steps should have code or command examples
- Concise and clear: Avoid redundancy and keep the structure clear
Example
Assume the user has just completed a "using the OpenRouter API to implement image understanding" task; after invoking this skill, it might generate:
---
name: openrouter-vision
description: 使用 OpenRouter API 进行图片理解。Use when user wants to 调用视觉API, 图片分析API, call vision API.
---
# OpenRouter Vision API
通过 OpenRouter 调用视觉模型分析图片。
## Background
> 此 skill 从 image-understand skill 开发实践中提取。
## Prerequisites
1. `OPENROUTER_API_KEY` 环境变量
2. Python 3.11+ 和 uv
## Instructions
### Step 1: 准备图片
- 支持格式:PNG、JPG、JPEG、GIF、WebP
- 大小限制:20MB
### Step 2: 构建 API 请求
...
## Common Pitfalls
| 错误做法 | 正确做法 | 原因 |
|---------|---------|------|
| ❌ `ext === 'jpg'` | ✅ `ext === 'jpg' \|\| ext === 'jpeg'` | jpeg 扩展名也需要处理 |
| ❌ 不检查文件大小 | ✅ 添加 20MB 限制 | API 有大小限制 |
## Best Practices
- 使用 `fs.statSync()` 检查文件大小后再读取
- MIME 类型映射要完整
- 添加可执行权限 `chmod +x`
...
Notes
- This skill depends on the session context and needs to be used immediately after completing the task
- The generated skill is a first draft, and the user may need to adjust it according to the actual situation
- Encourage the user to review and supplement any missing experience