Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Creating and Using a Skill in VS Code

Creating and Using a Skill in VS Code

This tutorial will walk you through creating an Agent Skill from scratch and actually running it in VS Code + GitHub Copilot.

We'll create a dice-rolling Skill that teaches the Agent to generate random numbers via terminal commands.


Preparation

Environment requirements

This tutorial uses VS Code, but Agent Skills are an open format. The same Skill can also be used in compatible tools such as Claude Code, OpenCode, and OpenAI Codex.

For more on VS Code, see:VS Code Tutorial。


Creating the Skill directory and files

VS Code looks for Skills in the project's .agents/skills/ directory by default.

First, create the following directory structure in your project:

Create directory structure

Run this in the project root

mkdir

-p

.agents

/

skills

/

roll-dice

Then create the following file at .agents/skills/roll-dice/SKILL.md:

Example: full SKILL.md content


name

:

roll

dice

description

:

Roll dice using a random number generator. Use this when the user asks to roll dice (d6, d20, etc.) or generate a random dice value.


Dice-rolling method

Use the following shell command to generate

1

a random number between 1 and the specified number of sides:

macOS

/

Linux



  

echo $



(



(



RANDOM



%



<



sides



>



+



1



)



)



  

Windows PowerShell



  

Get



-



Random



-



Minimum



1



-



Maximum



(



<



sides



>



+



1



)



  

**

Usage notes:

**

Replace `

<

sides

` with the number of dice sides specified by the user:

d6: Replace `

<

sides

` with

6

d20: Replace `

<

sides

` with

20

Other numbers of sides follow the same pattern.

**

Output:

**

Simply return the random result number; no extra explanation is needed.

A single file, fewer than 20 lines, and you have a complete Skill.


File structure breakdown

Let's understand the role of this file part by part.

YAML frontmatter

Field Purpose Description
name The unique identifier of the Skill It must exactly match the folder name, using lowercase letters and hyphens
description Trigger condition description Tells the Agent when to use this Skill; this is the key field the Agent uses to decide whether to activate it

Body (Markdown body)

The body contains the instructions the Agent actually follows after the Skill is activated.

Here we tell the Agent: when the user asks to roll dice, use the operating system's random number command and pass the number of dice sides into the command.

We provide commands for both macOS/Linux and Windows, and the Agent automatically selects based on the current environment.


Test your Skill

After creating the file, verify it with these steps:

  1. Open your project in VS Code

  2. Open the Copilot Chat panel (shortcut Ctrl+Shift+I or Cmd+Shift+I), or click the button in the top right:

  3. Select Agent mode at the bottom of the chat panel
  4. Input /skills command, and confirm roll-dice appears in the Skill list

  5. You can see roll-dice in the Skill list:

If roll-dice doesn't appear in the /skills list, check that the file path is correct:.agents/skills/roll-dice/SKILL.md, and note that SKILL.md must be uppercase.

After confirming the Skill is loaded, type in the chat:



Roll a d20

The Agent should automatically activate the roll-dice Skill, run the terminal command, and return a random number between 1 and 20.


What happens behind the scenes

When you use this Skill in Copilot Chat, three steps take place under the hood:

Step 1: Discovery

When the chat session begins, the Agent scans the default Skill directory (.agents/skills/) and finds roll-dice.

It only reads name and description, learning that "this Skill is for rolling dice."

Step 2: Activation

When you type "Roll a d20," the Agent matches your question with roll-dice's description.

After a successful match, the Agent loads the full SKILL.md body into the context.

Step 3: Execution

Following the instructions in the body, the Agent recognizes that you're using macOS (or Linux) and selects the bash command.

It substitutes 20 for d20 in the command, runs echo $((RANDOM % 20 + 1)), and returns the result to you.


Troubleshooting common problems

Problem Possible cause Solution
/skills list is empty SKILL.md file path is incorrect Confirm the file is in the project's .agents/skills/roll-dice/ directory
Agent doesn't run the command Differences in model tool-calling reliability Try switching models, or state it more explicitly: "roll a d20 for me"
Command execution failed Shell environment differences Confirm the $RANDOM command works in a macOS/Linux terminal

Cross-tool usage tips

Although this tutorial uses VS Code, Skills can be used with other tools as well:

Tool Skill storage location
VS Code + Copilot .agents/skills/ or .github/copilot/
Claude Code .claude/skills/ or ~/.claude/skills/
OpenAI Codex .codex/skills/

Different tools may use different default directories, but the Skill's format and file structure are universal.