File size: 6,689 Bytes
7a1ad33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# Creating Agent Skills

Agent Skills let you extend Gemini CLI with specialized expertise, procedural
workflows, and task-specific resources. This guide walks you through both
automated and manual methods for creating and organizing your skills.

## Quickstart: Create a skill with a prompt

The fastest way to create a new skill is to use the built-in `skill-creator`.
This meta-skill guides you through designing, scaffolding, and validating your
expertise.

Simply ask Gemini CLI to create a skill for you:

> "Create a new skill called 'code-reviewer' that analyzes local files for
> common errors and style violations."

Gemini will then:

1.  Generate a new directory for your skill (for example, `my-new-skill/`).
2.  Create a `SKILL.md` file with the necessary YAML frontmatter (`name` and
    `description`).
3.  Create the standard resource directories: `scripts/`, `references/`, and
    `assets/`.

Once created, you can find your new skill in `.gemini/skills/code-reviewer/`.

## Manual creation

1.  **Create a directory** for your skill (for example, `my-new-skill/`).
2.  **Create a `SKILL.md` file** inside the new directory.

### 1. Create the directory structure

The first step is to create the necessary folders for your skill and its
scripts.

**macOS/Linux**

```bash
mkdir -p .gemini/skills/code-reviewer/scripts
```

**Windows (PowerShell)**

```powershell
New-Item -ItemType Directory -Force -Path ".gemini\skills\code-reviewer\scripts"
```

### 2. Define the skill (`SKILL.md`)

The `SKILL.md` file defines the skill's purpose and instructions for the agent.
Create a file at `.gemini/skills/code-reviewer/SKILL.md`.

```markdown
---
name: code-reviewer
description:
  Expertise in reviewing code changes for correctness, security, and style. Use
  when the user asks to "review" their code or a PR.
---

# Code Reviewer Instructions

You act as a senior software engineer specialized in code quality. When this
skill is active, you MUST:

1.  **Analyze**: Review the provided code for logical errors, security
    vulnerabilities, and style violations.
2.  **Review**: Use the bundled `scripts/review.js` utility to perform an
    automated check.
3.  **Feedback**: Provide constructive feedback, clearly distinguishing between
    critical issues and minor improvements.
```

### 3. Add the tool logic

Skills can bundle resources like scripts to perform deterministic tasks. Create
a file at `.gemini/skills/code-reviewer/scripts/review.js`.

```javascript
// .gemini/skills/code-reviewer/scripts/review.js
const file = process.argv[2];

if (!file) {
  console.error('Usage: node review.js <file>');
  process.exit(1);
}

console.log(`Reviewing ${file}...`);
// Simple mock review logic
setTimeout(() => {
  console.log(`Result: Success (No major issues found in ${file})`);
}, 500);
```

### 4. Test the skill

Gemini CLI automatically discovers skills in the `.gemini/skills` directory.

1.  Start a new session and ask a question that triggers the skill's
    description: "Can you review index.js"
2.  Gemini identifies the request matches the `code-reviewer` description and
    asks for permission to activate it.
3.  Once you approve, Gemini executes the bundled script:
    `node .gemini/skills/code-reviewer/scripts/review.js index.js`

To determine whether your skill has been correctly loaded, run the command:

```bash
/skills
```

### 5. Optional: Share your skill

You can share your skills in several ways depending on your target audience.

- **Workspace skills**: Commit your skill to a `.gemini/skills/` directory in
  your project repository.
- **Extensions**: Bundle your skill within a
  [Gemini CLI extension](../extensions/writing-extensions.md).
- **Git repositories**: Share the skill directory as a standalone Git repo and
  install it using `gemini skills install <url>`.

---

## Core concepts

Now that you've built your first skill, let's explore the core components and
workflows for developing more complex expertise.

### Skill structure

While a `SKILL.md` file is the only required component, we recommend the
following structure for organizing your skill's resources.

```text
my-skill/
β”œβ”€β”€ SKILL.md       (Required) Instructions and metadata
β”œβ”€β”€ scripts/       (Optional) Executable scripts
β”œβ”€β”€ references/    (Optional) Static documentation
└── assets/        (Optional) Templates and other resources
```

When a skill is activated, the model is granted access to this entire directory.
You can instruct the model to use the tools and files found within these
folders.

### Metadata and triggers

The `SKILL.md` file uses YAML frontmatter for metadata.

- **`name`**: A unique identifier for the skill. This should match the directory
  name.
- **`description`**: **CRITICAL.** This is how Gemini decides when to use the
  skill. Be specific about the tasks it handles and the keywords that should
  trigger it.

### Discovery tiers

Gemini CLI discovers skills from several locations, following a specific order
of precedence (lowest to highest):

1.  **Built-in Skills**: Included with Gemini CLI (pre-approved).
2.  **Extension Skills**: Bundled within [extensions](../extensions/).
3.  **User Skills**: `~/.gemini/skills/` or the `~/.agents/skills/` alias.
4.  **Workspace Skills**: `.gemini/skills/` or the `.agents/skills/` alias.

### Discovery aliases

You can use `.agents/skills` as an alternative to `.gemini/skills`. This alias
is compatible with other AI agent tools following the
[Agent Skills](https://agentskills.io) standard.

## Advanced development

Once you've built a basic skill, you can use specialized scripts and workflows
to streamline your development process.

### Creation scripts

If you are developing a skill and want to use the same scripts the built-in
tools use, you can find them in the core package. These scripts help automate
the initialization, validation, and packaging of skills.

- **Initialize**: `node scripts/init_skill.cjs <name> --path <dir>`
- **Validate**: `node scripts/validate_skill.cjs <path/to/skill>`
- **Package**: `node scripts/package_skill.cjs <path/to/skill>` (Creates a
  `.skill` zip file)

### Linking for local development

If you are developing a skill in a separate directory, you can link it to your
user skills directory for testing:

```bash
gemini skills link .
```

## Next steps

- [Skill best practices](./skills-best-practices.md): Learn strategies for
  building reliable and effective skills.
- [Agent Skills overview](./skills.md): Deep dive into discovery tiers and the
  skill lifecycle.
- [Get started with Agent Skills](./tutorials/skills-getting-started.md): A
  quick walkthrough of triggering and using skills.