首页 › tutorials › Skill跨平台适配:五端兼容实战

Skill跨平台适配:五端兼容实战

概述

2026年最被低估的能力跃迁:你写的 SKILL.md 不再只能跑在 Claude Code 里。Agent Skills 开放标准让同一个 Skill 文件夹在 Claude Code、Cursor、Gemini CLI、Codex CLI、GitHub Copilot 五个平台上即装即用。本教程将带你从零构建一个跨平台 Skill,覆盖目录差异、触发机制、权限声明、调试排错的全链路。

适用人群:已掌握 SKILL.md 基础写法的开发者、需要跨团队跨工具共享 Skill 的工程负责人、正在从 .cursorrules 迁移到 AGENTS.md 体系的团队。

学习目标:完成本教程后,你将能够构建一个在五个主流 AI 编码工具上零修改直接运行的 Skill,并掌握跨平台兼容性测试方法论。

前置条件

条件 说明
Claude Code ≥ 2.0 已安装并完成首次配置
至少两个目标平台 如 Cursor、Gemini CLI 或 Codex CLI
Git 基础 能完成 clone、commit、push
SKILL.md 基础知识 了解 YAML frontmatter 和 Markdown 指令体
Terminal 环境 Bash/Zsh,支持 ls、cat、mkdir

一、为什么跨平台 Skill 是 2026 年的必修课

1.1 生态碎片化的现实

2026 年主流 AI 编码工具的指令文件格式如下:

工具 指令文件 Skill 路径 触发方式
Claude Code SKILL.md .claude/skills/ /skill-name 或自动触发
Cursor .cursorrules / AGENTS.md .cursor/skills/ @skill-name
Gemini CLI SKILL.md .gemini/skills/ /skill-name
Codex CLI SKILL.md .codex/skills/ 自动加载
GitHub Copilot copilot-instructions.md .github/skills/ Chat 中 #skill-name

五个工具,五套目录结构,五种触发方式。如果团队中有人用 Cursor、有人用 Claude Code、有人用 Gemini CLI,你就要维护五份几乎相同的指令——直到 Agent Skills 开放标准出现。

1.2 Agent Skills 开放标准的核心约定

Anthropic 于 2025 年底发布 Agent Skills 规范,2026 年初被 Codex CLI、Gemini CLI、Cursor 相继采纳,形成事实标准。核心约定只有三条:

  1. SKILL.md 是唯一入口:每个 Skill 是一个文件夹,包含一个 SKILL.md 文件
  2. YAML frontmatter 定义元数据:name、description、trigger 是必填字段
  3. Markdown body 定义行为:纯 Markdown 指令,不依赖任何工具特有语法
graph TB
    subgraph "Agent Skills Open Standard"
        A[SKILL.md 文件夹] --> B[YAML Frontmatter]
        A --> C[Markdown 指令体]
    end

    subgraph "五端运行时"
        B --> D[Claude Code]
        B --> E[Cursor]
        B --> F[Gemini CLI]
        B --> G[Codex CLI]
        B --> H[Copilot]
    end

    C --> D
    C --> E
    C --> F
    C --> G
    C --> H

    style A fill:#f9f,stroke:#333
    style D fill:#7cf,stroke:#333
    style E fill:#7cf,stroke:#333
    style F fill:#7cf,stroke:#333
    style G fill:#7cf,stroke:#333
    style H fill:#7cf,stroke:#333

二、五端目录结构与加载机制

2.1 各平台的 Skill 安装路径

# Claude Code(全局)
~/.claude/skills/my-skill/SKILL.md

# Claude Code(项目级)
.claude/skills/my-skill/SKILL.md

# Cursor(项目级)
.cursor/skills/my-skill/SKILL.md

# Gemini CLI(全局)
~/.gemini/skills/my-skill/SKILL.md

# Gemini CLI(项目级)
.gemini/skills/my-skill/SKILL.md

# Codex CLI(项目级)
.codex/skills/my-skill/SKILL.md

# GitHub Copilot(项目级)
.github/skills/my-skill/SKILL.md

关键区别:Claude Code 和 Gemini CLI 支持全局 + 项目级两层路径,Cursor 和 Codex CLI 目前仅支持项目级。这意味着你要优先使用项目级路径来保证最大兼容性。

2.2 跨平台安装脚本

以下脚本将同一个 Skill 符号链接到所有平台目录:

#!/bin/bash
# install-skill-everywhere.sh
# 用法: ./install-skill-everywhere.sh ./my-skill

SKILL_PATH="${1:-./my-skill}"
SKILL_NAME=$(basename "$SKILL_PATH")

# Claude Code 项目级
mkdir -p .claude/skills
cp -r "$SKILL_PATH" .claude/skills/"$SKILL_NAME"

# Cursor 项目级
mkdir -p .cursor/skills
cp -r "$SKILL_PATH" .cursor/skills/"$SKILL_NAME"

# Gemini CLI 项目级
mkdir -p .gemini/skills
cp -r "$SKILL_PATH" .gemini/skills/"$SKILL_NAME"

# Codex CLI 项目级
mkdir -p .codex/skills
cp -r "$SKILL_PATH" .codex/skills/"$SKILL_NAME"

# GitHub Copilot 项目级
mkdir -p .github/skills
cp -r "$SKILL_PATH" .github/skills/"$SKILL_NAME"

echo "✅ $SKILL_NAME installed to all 5 platforms"
ls -la .claude/skills/"$SKILL_NAME"/SKILL.md \
       .cursor/skills/"$SKILL_NAME"/SKILL.md \
       .gemini/skills/"$SKILL_NAME"/SKILL.md \
       .codex/skills/"$SKILL_NAME"/SKILL.md \
       .github/skills/"$SKILL_NAME"/SKILL.md

常见问题:如果你更倾向于保持单一来源,可以用符号链接代替 cp -r:

# 用符号链接(单一来源,修改一处即全部生效)
ln -s "$(pwd)/$SKILL_PATH" .claude/skills/"$SKILL_NAME"
ln -s "$(pwd)/$SKILL_PATH" .cursor/skills/"$SKILL_NAME"
# ... 其他平台同理

三、SKILL.md 跨平台兼容性字段详解

3.1 Frontmatter 字段兼容矩阵

字段 Claude Code Cursor Gemini CLI Codex CLI Copilot
name ✅ 必填 ✅ 必填 ✅ 必填 ✅ 必填 ✅ 必填
description ✅ 必填 ✅ 必填 ✅ 必填 ✅ 必填 ⚠️ 可选
trigger ✅ 推荐 ⚠️ 忽略 ✅ 推荐 ⚠️ 忽略 ⚠️ 忽略
allowed-tools ✅ 支持 ❌ 忽略 ⚠️ 部分支持 ❌ 忽略 ❌ 忽略
disable-context ✅ 支持 ❌ 忽略 ❌ 忽略 ❌ 忽略 ❌ 忽略
version ⚠️ 可选 ⚠️ 可选 ⚠️ 可选 ⚠️ 可选 ⚠️ 可选

规则:只使用 name 和 description 两个必填字段作为跨平台最小公共子集。其余字段按需添加,不支持的平台会静默忽略。

3.2 最小兼容 Frontmatter 模板

---
name: commit-conventional
description: >
  Generate Conventional Commits style commit messages.
  Analyzes staged changes and produces structured commit output.
  Triggered by /commit or when user asks to commit.
---

# Commit Conventional Skill

## Instructions

...(指令体)

这个模板在五个平台上都能被正确解析。name 决定斜杠命令名称(/commit-conventional),description 用于自动触发匹配。

3.3 平台增强字段的使用策略

当某个字段仅部分平台支持时,采用渐进增强策略:

---
name: api-tester
description: Run API tests and validate responses against schemas.
trigger: When user mentions API testing, endpoint validation, or schema checking.
allowed-tools: Bash, Read, WebFetch
---

# API Tester Skill
...

四、Markdown 指令体的跨平台编写准则

4.1 三个"绝对不要"

规则一:不要使用 HTML 标签

<!-- ❌ Cursor 和 Codex 可能无法正确解析 -->
<details>
<summary>Click to expand</summary>
Content here
</details>

<!-- ✅ 使用纯 Markdown -->
**Details**: Content here

规则二:不要引用工具特有的配置路径

<!-- ❌ 只在 Claude Code 有效 -->
Read the file at ~/.claude/settings.json to check permissions.

<!-- ✅ 使用参数化路径 -->
Read the tool's settings file (e.g., ~/.claude/settings.json for Claude Code,
~/.cursor/settings.json for Cursor) to check permissions.

规则三:不要依赖特定工具的内置命令

<!-- ❌ 只有 Claude Code 有 Skill tool -->
Invoke the "skill-creator" skill to generate a new skill.

<!-- ✅ 使用条件分支 -->
If using Claude Code: invoke the "skill-creator" skill.
If using Cursor: use @skill-creator in chat.
If using Gemini CLI: use the /skill-creator command.
Otherwise: follow the manual steps below.

4.2 工具调用指令的抽象层

跨平台 Skill 最大的挑战是工具调用指令。不同平台的工具名称和调用方式各异:

## Tool Usage Guidelines

### File Reading
- Claude Code / Gemini CLI: Use the `Read` tool
- Cursor: Use `@file` reference or Read tool
- Codex CLI: Use the built-in file reader

### Command Execution
- Claude Code: Use the `Bash` tool
- Cursor: Use the terminal tool
- Codex CLI: Use shell execution

### Web Access
- Claude Code: Use `WebFetch` or `WebSearch`
- Cursor: Use browser tool
- Gemini CLI: Use Google Search tool

在 Skill 指令中,你应该使用意图描述而非具体工具名:

## Step 1: Read Configuration

Read the project's package.json file using your available file reading capability.
Extract the "scripts" section and list all available npm scripts.

这种方式让每个平台的 Agent 自动映射到自己的工具,无需硬编码工具名。


五、触发机制的跨平台适配

5.1 触发方式对比

graph LR
    subgraph "用户输入"
        U[User Message]
    end

    subgraph "Claude Code"
        U --> C1["/skill-name"]
        U --> C2["Auto-trigger via description match"]
    end

    subgraph "Cursor"
        U --> CR1["@skill-name in chat"]
        U --> CR2["Auto-trigger in Agent mode"]
    end

    subgraph "Gemini CLI"
        U --> G1["/skill-name"]
        U --> G2["Auto-trigger via description"]
    end

    subgraph "Codex CLI"
        U --> CX1["Auto-load on session start"]
        U --> CX2["Auto-trigger via description"]
    end

    subgraph "Copilot"
        U --> CP1["#skill-name in chat"]
        U --> CP2["Auto-trigger via description"]
    end

5.2 description 字段的触发优化

description 字段是跨平台自动触发机制的核心。编写时要考虑:

  1. 包含触发关键词:明确列出用户可能使用的短语
  2. 语义覆盖:同义词、缩写、相关术语都要覆盖
  3. 避免歧义:描述要足够独特,不会与其他 Skill 冲突
# ❌ 描述太宽泛,容易误触发
description: Help with Git operations.

# ❌ 描述太窄,用户换一种说法就触发不了
description: Generate conventional commits from git diff --cached output.

# ✅ 平衡具体性与覆盖面
description: >
  Generate structured commit messages following Conventional Commits specification.
  Triggered when user mentions: commit, commit message, conventional commit,
  write commit, generate commit, commit changes.

六、实战案例:跨平台代码审查 Skill

6.1 需求定义

构建一个 code-review Skill,功能如下: - 分析当前分支相对于 main 分支的变更 - 按安全、性能、可维护性三个维度生成审查报告 - 输出结构化的审查清单

要求在 Claude Code、Cursor、Gemini CLI 三个平台上零修改运行。

6.2 创建 Skill 目录

mkdir -p skills/code-review

6.3 编写 SKILL.md

---
name: code-review
description: >
  Perform structured code review on current branch changes versus main branch.
  Analyzes security vulnerabilities, performance issues, and maintainability.
  Triggered when user mentions: code review, review code, review PR,
  check my code, audit changes, review changes.
---

# Code Review Skill

## Context

You are a senior code reviewer. Analyze the changes on the current Git branch
compared to the main branch and produce a structured review report.

## Steps

### Step 1: Gather Changes

Run the following command to get the diff:

```bash
git diff main...HEAD --stat

Then get the full diff for detailed analysis:

git diff main...HEAD

If the main branch is named differently (master, develop), adapt accordingly. Check available branches first if unsure.

Step 2: Analyze Changes

Review each modified file and categorize findings into three dimensions:

Security (🔴 Critical)

Performance (🟡 Warning)

Maintainability (🔵 Info)

Step 3: Generate Report

Output the review in the following format:

# Code Review Report

## Summary
- **Branch**: [branch name]
- **Files changed**: [count]
- **Lines added**: [count] | **Lines removed**: [count]
- **Overall assessment**: [APPROVE / REQUEST_CHANGES / NEEDS_DISCUSSION]

## Findings

### 🔴 Security Issues ([count])
| # | File | Line | Issue | Severity |
|---|------|------|-------|----------|
| 1 | ... | ... | ... | Critical |

### 🟡 Performance Concerns ([count])
| # | File | Issue | Impact |
|---|------|-------|--------|
| 1 | ... | ... | Medium |

### 🔵 Maintainability Notes ([count])
| # | File | Suggestion | Priority |
|---|------|------------|----------|
| 1 | ... | ... | Low |

## Recommended Actions
1. [Most critical action]
2. [Second priority]
3. [Third priority]

## Positive Highlights
- [Something done well in the changes]

Rules

  1. Be specific: Always reference exact file paths and line numbers
  2. Be constructive: Every finding should include a suggested fix
  3. Prioritize: Sort findings by severity, not by file order
  4. Acknowledge good patterns: Call out well-written code
  5. Stay scope-focused: Only review changed lines, not the entire codebase
  6. No false positives: If uncertain about a finding, mark it as [UNCERTAIN]
### 6.4 安装到三个平台

```bash
# 一次性复制到三个平台
for dir in .claude .cursor .gemini; do
  mkdir -p "$dir/skills"
  cp -r skills/code-review "$dir/skills/"
done

# 验证安装
find . -path "*/skills/code-review/SKILL.md" -exec echo "✅ {}" \;

预期输出:

✅ .claude/skills/code-review/SKILL.md
✅ .cursor/skills/code-review/SKILL.md
✅ .gemini/skills/code-review/SKILL.md

6.5 各平台触发方式

平台 触发方式 命令示例
Claude Code 斜杠命令 /code-review
Claude Code 自然语言 "review my code"
Cursor @ 引用 @code-review review my code
Gemini CLI 斜杠命令 /code-review
Gemini CLI 自然语言 "review code on this branch"

七、跨平台调试排错指南

7.1 常见兼容性问题

flowchart TD
    A[Skill 不触发] --> B{检查平台}
    B -->|Claude Code| C["验证 .claude/skills/ 路径"]
    B -->|Cursor| D["验证 .cursor/skills/ 路径<br>确认 Agent 模式开启"]
    B -->|Gemini CLI| E["验证 .gemini/skills/ 路径<br>确认 Skill 被识别"]

    C --> F{frontmatter 格式正确?}
    D --> F
    E --> F

    F -->|No| G["修复 YAML 语法<br>检查缩进和引号"]
    F -->|Yes| H{description 匹配?}

    H -->|No| I["扩展 description 关键词"]
    H -->|Yes| J["检查 Skill 是否冲突<br>查看同名 Skill"]

    G --> K[重新加载]
    I --> K
    J --> K

    K --> L[✅ 验证触发]

7.2 各平台调试命令

Claude Code:

# 查看 Claude Code 识别到的所有 Skills
claude /skills

# 验证 Skill 文件格式
cat .claude/skills/code-review/SKILL.md | head -20

Cursor: - 打开 Command Palette → "Cursor: List Skills" - 检查 Output 面板的 "Cursor Agent" 日志 - 确认 .cursor/skills/ 目录在项目根目录

Gemini CLI:

# 列出已安装的 Skills
gemini /skills

# 验证路径
ls -la .gemini/skills/*/SKILL.md

7.3 YAML Frontmatter 常见语法错误

# ❌ 错误:description 中有未转义的冒号
description: Generate commit messages: conventional format.

# ✅ 正确:用 > 折叠或引号包裹
description: >
  Generate commit messages following conventional format.

# ❌ 错误:name 包含空格
name: code review

# ✅ 正确:用短横线连接
name: code-review

# ❌ 错误:trigger 是列表格式(某些平台不支持)
trigger:
  - /review
  - review code

# ✅ 正确:用自然语言字符串
trigger: When user mentions code review, review PR, or audit changes.

八、进阶:条件分支与平台检测

8.1 指令中的条件分支

对于某些需要平台特定行为的 Skill,可以在指令体中添加条件逻辑:

## Execution Strategy

Detect your current environment and adapt accordingly:

### If running in Claude Code:
- Use the `Bash` tool for all command execution
- Use the `Read` tool for file operations
- Use the `Grep` tool for code search

### If running in Cursor:
- Use the terminal for command execution
- Use the file explorer for reading files
- Use the search panel for code search

### If running in Gemini CLI:
- Use shell execution for commands
- Use the file reading capability for files
- Use Google Search integration for web lookups

### Universal fallback:
- Describe what needs to be done in plain language
- The agent will map to its available tools automatically

8.2 跨平台工具权限声明

Claude Code 的 allowed-tools 字段可以被其他平台安全忽略。利用这一点:

---
name: deploy-check
description: >
  Pre-deployment checklist runner. Validates environment configs,
  runs tests, and confirms readiness.
  Triggered by: deploy check, pre-deploy, deployment readiness.
allowed-tools: Bash, Read, Grep, Glob
---

在 Claude Code 中,allowed-tools 限制 Skill 只能使用这四个工具。其他平台忽略该字段,但 Skill 仍然正常运行。


九、团队级跨平台 Skill 分发

9.1 Git Marketplace 方案

创建一个 Git 仓库作为团队的 Skill 注册中心:

# 仓库结构
team-skills/
├── marketplace.json          # Skill 索引
├── code-review/
│   └── SKILL.md
├── deploy-check/
│   └── SKILL.md
├── api-tester/
│   └── SKILL.md
└── README.md

marketplace.json 格式:

{
  "name": "Team Skills Registry",
  "skills": [
    {
      "name": "code-review",
      "description": "Structured code review with security, performance, and maintainability analysis",
      "version": "1.2.0",
      "author": "platform-team",
      "tags": ["review", "security", "quality"]
    },
    {
      "name": "deploy-check",
      "description": "Pre-deployment validation checklist",
      "version": "1.0.0",
      "author": "devops-team",
      "tags": ["deploy", "ci", "validation"]
    }
  ]
}

9.2 各平台安装 Marketplace

# Claude Code
claude config add-plugin-marketplace https://github.com/your-org/team-skills

# Cursor(通过 settings.json)
# 在 .cursor/settings.json 中添加:
# {
#   "plugins.marketplaces": ["https://github.com/your-org/team-skills"]
# }

# Gemini CLI
# 在 .gemini/settings.json 中添加:
# {
#   "marketplaces": ["https://github.com/your-org/team-skills"]
# }

9.3 CI/CD 验证 Skill 兼容性

在团队 Skill 仓库中添加兼容性检查:

# .github/workflows/skill-validation.yml
name: Skill Compatibility Check

on: [push, pull_request]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Validate SKILL.md frontmatter
        run: |
          for skill in */SKILL.md; do
            echo "Checking $skill"
            # 检查 YAML frontmatter 是否存在
            head -1 "$skill" | grep -q "^---" || { echo "ERROR: Missing frontmatter in $skill"; exit 1; }
            # 检查必填字段
            grep -q "^name:" "$skill" || { echo "ERROR: Missing 'name' in $skill"; exit 1; }
            grep -q "^description:" "$skill" || { echo "ERROR: Missing 'description' in $skill"; exit 1; }
          done

      - name: Check for platform-specific syntax
        run: |
          # 检测是否包含仅 Claude Code 特有的工具调用
          for skill in */SKILL.md; do
            if grep -q "Use the.*Skill tool" "$skill"; then
              echo "WARNING: $skill contains Claude Code specific syntax"
            fi
          done

十、跨平台 Skill 设计检查清单

在发布任何跨平台 Skill 之前,逐项检查:

检查项 说明 状态
Frontmatter 仅使用 name + description 确保最小公共子集 ☐
YAML 语法严格正确 无未转义冒号、无列表格式 trigger ☐
无 HTML 标签 Cursor 和 Codex 可能解析异常 ☐
无工具特有路径硬编码 使用相对路径或参数化描述 ☐
无工具特有命令调用 用意图描述替代具体工具名 ☐
description 包含触发关键词 覆盖同义词和缩写 ☐
指令体可独立运行 不依赖其他 Skill 的输出 ☐
已在至少两个平台测试 验证零修改运行 ☐
name 使用短横线命名 无空格、无下划线、无驼峰 ☐
指令体以 # 标题开头 标准 Markdown 结构 ☐

十一、性能考量:Token 经济与上下文窗口

跨平台 Skill 面临一个隐藏问题:不同平台对上下文窗口的处理方式不同。

11.1 指令长度控制

策略 说明 Token 节省
分层指令 先给概要,需要时再展开 ~40%
条件块 只加载当前平台相关的部分 ~30%
引用外部文件 复杂规则放在附属 .md 文件中 ~50%
精简 description 用关键词列表替代长段落 ~20%

11.2 示例:分层指令结构

---
name: api-docs
description: >
  Generate OpenAPI documentation from code annotations.
  Triggered by: generate API docs, OpenAPI spec, Swagger docs.
---

# API Documentation Generator

## Quick Mode (default)

When user asks for API docs:
1. Scan route/controller files for endpoint definitions
2. Extract HTTP methods, paths, request/response schemas
3. Output a minimal OpenAPI 3.0 spec

## Detailed Mode

When user explicitly requests detailed documentation:
1. Perform Quick Mode steps
2. Add authentication requirements from middleware analysis
3. Generate example requests/responses
4. Add error response schemas
5. Include rate limiting information

## Full Specification Mode

When user requests complete API specification:
1. Perform Detailed Mode steps
2. Add server configurations
3. Generate webhook definitions
4. Include deprecation notices
5. Produce a complete, validatable OpenAPI 3.1 document

这种分层设计让 Agent 在大多数场景下只加载 Quick Mode 的指令,节省大量 Token。


延伸阅读


参考来源

  1. Extend Claude with skills - Claude Code Docs — Anthropic 官方 Skills 创建和管理文档
  2. Claude Code Skills Complete Guide: SKILL.md, MCP, Subagents & Teams — SKILL.md 格式与多平台集成的深度指南
  3. Claude Skills: The Complete 2026 Guide — Build, Install & Use — 覆盖构建、安装、分发全流程的 2026 年度指南
  4. Cross-Platform Agent Portability: One SKILL.md for Every Runtime — SKILL.md 跨平台运行时的技术分析
  5. Equipping agents for the real world with Agent Skills — Anthropic 工程博客对 Agent Skills 标准的官方解读

训练营适用性评估

维度 说明
适合训练营类型 企业级 AI 编码工具标准化培训、DevOps/SRE 工具链统一工作坊、跨职能团队 Skill 共享实战
预计教学时长 4-5 小时(含实操),建议拆分为两个半天
前置训练 需完成 SKILL.md 基础编写训练,建议先完成"从零到发布"教程
实操环境要求 至少安装 Claude Code + 一个其他平台(Cursor 或 Gemini CLI),有 Git 仓库
难度等级 ⭐⭐⭐ 中高级,需要理解 YAML、Git、多工具协作

[!tip] 51学通信知识星球 星主:爱卫生(微信:gprshome201101)——公众号「51学通信」创办者,19 年通信行业运维与讲师经验,著有《GPRS网络信令实例详解》《EPC原理与实践》《5G核心网原理与实践》三本纸质书(各大电商平台有售)。 星球定位:深耕 5G 核心网、IMS、NFV/AI、云原生等 ICT 领域,主打运维岗位与信令分析。 当前规模:5200 篇主题 / 990 个回答,198 元/年。 加入福利:加入星球后请加爱卫生微信,拉您进知识星球年度陪伴与答疑群——不限量回复您的各种问题,另有群内分享。 AI 加持:51学通信知识星球已作为 skill 接入 WorkBuddy,使用 deepseek-4-flash 在海量星球帖子中精准找贴、找视频、找 FAQ 和案例,做总结、找文档和 PPT 等场景全覆盖。

51学通信知识星球海报-扫码加入