Skills(也叫 Slash Commands)是 Claude Code 中可复用的提示模板系统。它们本质上是存储在特定目录下的 Markdown 文件,当用户通过 /skill-name 语法调用时,其内容会被加载到 Claude 的上下文中,引导 Claude 按照预定义的工作流执行任务。
如果说 CLAUDE.md 是”始终加载的背景知识”,那么 Skills 就是”按需调用的专业能力”。你不需要每次都重复描述复杂的工作流——只需定义一次,随时调用。
在 Claude Code 中,你只需输入斜杠命令即可调用 Skill:
> /commit
> /review-pr 123
> /deploy stagingClaude Code 会查找对应的 Skill 文件,将其内容加载到上下文中,然后按照 Skill 中定义的指令执行。
Skill 文件是带有特定结构的 Markdown 文件,存储在 .claude/skills/ 目录下:
一个典型的 Skill 文件内容如下:
# Commit Skill
Review all staged changes using git diff --cached.
Write a concise commit message following conventional commits format:
- type(scope): description
- Types: feat, fix, docs, style, refactor, test, chore
Rules:
- Keep the subject line under 72 characters
- Use imperative mood ("add" not "added")
- Include a body if the change is complex
- Reference related issues if applicable
After writing the message, create the commit.Skills 存在于两个层级:
~/.claude/skills/):你个人的 Skills,在所有项目中可用。适合个人工作流偏好。.claude/skills/):提交到项目仓库,团队共享。适合项目特定的工作流。项目级 Skills 可以被版本控制,团队成员 pull 代码后即可使用相同的 Skills。
理解两者的区别至关重要:
CLAUDE.md 适合放项目约定、技术栈说明、代码规范等始终需要的信息。Skills 适合放具体的任务流程——部署流程、代码审查清单、发布流程等。
Skills 可以接受参数。当你输入 /review-pr 123 时,123 会作为参数传递给 Skill。Skill 文件中可以引用这些参数:
# Review PR Skill
Fetch and review the pull request specified by the user.
Steps:
1. Use gh pr view with the provided PR number to get details
2. Use gh pr diff to review the changes
3. Check for:
- Code quality issues
- Missing tests
- Security concerns
- Documentation gaps
4. Provide a structured review summary一个完整的部署 Skill 示例:
# Deploy Skill
Execute a full deployment pipeline for the specified environment.
## Pre-deploy Checks
1. Run the full test suite: npm test
2. Run linting: npm run lint
3. Ensure no uncommitted changes exist
4. Verify the current branch is up to date with remote
## Build
1. Run the production build: npm run build
2. Verify build output exists and is valid
## Deploy
1. Deploy to the specified environment using the deploy script
2. Run: ./scripts/deploy.sh <environment>
3. Wait for deployment to complete
## Post-deploy Verification
1. Run smoke tests against the deployed environment
2. Check health endpoints
3. Report deployment status
If any step fails, stop immediately and report the error.
Do NOT proceed with deployment if tests or build fail.Skills 不是全部预加载到 context 的。Claude Code 启动时只加载 skill 的名称和描述(frontmatter 中的 name 和 description),完整内容是延迟加载的。当用户输入 /skill-name 或 AI 判断需要某个 skill 时,才通过 ToolSearch 工具获取完整定义。
当用户输入 /commit 时,Claude Code 并不是自己去读取文件——而是调用内部的 Skill Tool,由它负责查找、加载和注入 skill 内容。这个过程对用户是透明的。
除了手动 /name 调用,AI 还能自动匹配 skill。系统会将当前任务描述与所有 skill 的 description 做语义匹配。如果匹配度高,自动加载该 skill。这就是为什么 skill 的 description 字段非常重要——它决定了 AI 能否在正确的时机”想起”这个 skill。
每个 skill 文件的 YAML frontmatter 是召回的关键:
---
name: deploy
description: Execute deployment pipeline with pre-checks, build, and verification
---name 用于精确匹配(/deploy),description 用于语义匹配(AI 自主判断)。一个好的 description 应当准确描述 skill 的用途和适用场景,这样 AI 才能在用户描述相关任务时自动想到调用它。
Skill 的加载只是把 markdown 内容注入 context。AI 仍然需要理解并执行其中的指令。这意味着 skill 的质量直接影响执行效果——写得越清晰、越具体,AI 执行得越准确。
这也意味着 Skill 本质上是一种上下文注入机制——它不改变 Claude 的能力,而是通过精心编写的提示来引导 Claude 的行为。
gh、npm),明确写出来。Skills (also called Slash Commands) are a reusable prompt template system in Claude Code. They are essentially Markdown files stored in specific directories. When invoked via /skill-name syntax, their content is loaded into Claude’s context, guiding Claude to execute tasks according to predefined workflows.
If CLAUDE.md is “always-loaded background knowledge,” then Skills are “on-demand specialized capabilities.” You don’t need to repeat complex workflow descriptions every time — define once, invoke anytime.
In Claude Code, simply type a slash command to invoke a Skill:
> /commit
> /review-pr 123
> /deploy stagingClaude Code finds the corresponding Skill file, loads its content into context, and executes according to the instructions defined in the Skill.
Skill files are Markdown files with a specific structure, stored in the .claude/skills/ directory:
A typical Skill file looks like this:
# Commit Skill
Review all staged changes using git diff --cached.
Write a concise commit message following conventional commits format:
- type(scope): description
- Types: feat, fix, docs, style, refactor, test, chore
Rules:
- Keep the subject line under 72 characters
- Use imperative mood ("add" not "added")
- Include a body if the change is complex
- Reference related issues if applicable
After writing the message, create the commit.Skills exist at two levels:
~/.claude/skills/): Your personal Skills, available across all projects. Ideal for personal workflow preferences..claude/skills/): Committed to the project repository, shared with the team. Ideal for project-specific workflows.Project-level Skills can be version-controlled — team members can use the same Skills after pulling the code.
Understanding the difference is crucial:
CLAUDE.md is suited for project conventions, tech stack descriptions, and coding standards — information always needed. Skills are suited for specific task processes — deployment procedures, code review checklists, release workflows, and so on.
Skills can accept arguments. When you type /review-pr 123, 123 is passed as an argument to the Skill. The Skill file can reference these arguments:
# Review PR Skill
Fetch and review the pull request specified by the user.
Steps:
1. Use gh pr view with the provided PR number to get details
2. Use gh pr diff to review the changes
3. Check for:
- Code quality issues
- Missing tests
- Security concerns
- Documentation gaps
4. Provide a structured review summaryA complete deployment Skill example:
# Deploy Skill
Execute a full deployment pipeline for the specified environment.
## Pre-deploy Checks
1. Run the full test suite: npm test
2. Run linting: npm run lint
3. Ensure no uncommitted changes exist
4. Verify the current branch is up to date with remote
## Build
1. Run the production build: npm run build
2. Verify build output exists and is valid
## Deploy
1. Deploy to the specified environment using the deploy script
2. Run: ./scripts/deploy.sh <environment>
3. Wait for deployment to complete
## Post-deploy Verification
1. Run smoke tests against the deployed environment
2. Check health endpoints
3. Report deployment status
If any step fails, stop immediately and report the error.
Do NOT proceed with deployment if tests or build fail.Skills are not all preloaded into context. When Claude Code starts, it only loads each skill’s name and description (from the YAML frontmatter), while the full content is deferred. The complete skill definition is only fetched via the ToolSearch tool when the user types /skill-name or when the AI determines a skill is needed.
When the user types /commit, Claude Code does not read the file itself — instead, the internal Skill Tool is invoked, which handles the lookup, loading, and injection. This process is transparent to the user.
Beyond manual /name invocation, the AI can also match skills automatically. The system compares the current task description against all skills’ descriptions using semantic matching. If the match score is high enough, the skill is loaded automatically. This is why the description field is so important — it determines whether the AI can “recall” the right skill at the right moment.
The YAML frontmatter in each skill file is the key to recall:
---
name: deploy
description: Execute deployment pipeline with pre-checks, build, and verification
---name is used for exact matching (/deploy), while description is used for semantic matching (AI’s autonomous judgment). A good description should accurately convey the skill’s purpose and applicable scenarios, so the AI can automatically think to invoke it when the user describes a related task.
Loading a skill merely injects its markdown content into the context. The AI still needs to understand and execute the instructions within. This means the quality of the skill directly impacts execution accuracy — the clearer and more specific the instructions, the more precisely the AI performs.
This also means Skills are fundamentally a context injection mechanism — they don’t change Claude’s capabilities, but guide Claude’s behavior through carefully crafted prompts.
gh, npm, etc.), state them explicitly.