> For the complete documentation index, see [llms.txt](https://www.opencodebook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opencodebook.xyz/en/chapter_14_skill_system/14.1_skill_definition_and_structure.md). Agents can also search and read this documentation through its [MCP server](https://www.opencodebook.xyz/~gitbook/mcp).

# 14.1 Skill Definition and Structure

> **Model**: claude-opus-4-6 (anthropic/claude-opus-4-6) **Generation Date**: 2026-02-17

***

If Plugins extend OpenCode's **engine layer** (modifying tools, intercepting messages, injecting parameters), then Skills extend the **Agent knowledge layer** -- they inject domain-specific knowledge, instructions, and best practices into the Agent.

A simple analogy: a Plugin is like adding new hardware to a car (turbocharger, navigation system), while a Skill is like giving the driver a new operating manual ("this is how you should drive in snowy conditions").

## 14.1.1 Skill File Format: Markdown

The Skill definition format is extremely simple -- a Markdown file with YAML frontmatter, with a fixed filename of `SKILL.md`:

```markdown
---
name: git-master
description: Expert at Git operations including atomic commits, rebase, squash, and history search
---

# Git Master Skill

When performing Git operations, follow these guidelines:

## Commit Messages
- Use conventional commits format: `type(scope): description`
- Types: feat, fix, refactor, docs, test, chore
...

## Rebase Strategy
...
```

The Skill data model is defined using a Zod Schema:

```typescript
// skill/skill.ts
export const Info = z.object({
  name: z.string(),          // Skill name (parsed from frontmatter)
  description: z.string(),   // Skill description
  location: z.string(),      // Absolute path to the SKILL.md file
  content: z.string(),       // Markdown body content (excluding frontmatter)
})
```

The YAML frontmatter is parsed using `ConfigMarkdown.parse()` -- sharing the same logic as OpenCode's configuration file parser, with support for comments and flexible formatting.

## 14.1.2 Skill Directory Discovery Mechanism

Skill discovery is a multi-layered scanning process, searching in order from global to project-level, from external to internal:

```
Search layers (priority from low to high):

1. Global external directories
   ~/.claude/skills/**/SKILL.md
   ~/.agents/skills/**/SKILL.md

2. Project external directories (traversing upward to the worktree root)
   <project>/.claude/skills/**/SKILL.md
   <project>/.agents/skills/**/SKILL.md

3. OpenCode configuration directories
   <config-dirs>/{skill,skills}/**/SKILL.md

4. Additional paths declared in configuration
   Directories in config.skills.paths

5. Remote URLs (downloaded via Discovery.pull())
   Addresses in config.skills.urls
```

The search logic in the source code:

```typescript
// skill/skill.ts
const EXTERNAL_DIRS = [".claude", ".agents"]
const EXTERNAL_SKILL_GLOB = new Bun.Glob("skills/**/SKILL.md")
const OPENCODE_SKILL_GLOB = new Bun.Glob("{skill,skills}/**/SKILL.md")

const state = Instance.state(async () => {
  const skills: Record<string, Info> = {}

  // 1. Scan global external directories
  if (!Flag.OPENCODE_DISABLE_EXTERNAL_SKILLS) {
    for (const dir of EXTERNAL_DIRS) {
      const root = path.join(Global.Path.home, dir)
      await scanExternal(root, "global")
    }

    // 2. Scan upward from the project directory to the worktree root
    for await (const root of Filesystem.up({
      targets: EXTERNAL_DIRS,
      start: Instance.directory,
      stop: Instance.worktree,
    })) {
      await scanExternal(root, "project")
    }
  }

  // 3. Scan OpenCode configuration directories
  for (const dir of await Config.directories()) {
    for await (const match of OPENCODE_SKILL_GLOB.scan({ cwd: dir })) {
      await addSkill(match)
    }
  }

  // 4. Scan additional paths from configuration
  for (const skillPath of config.skills?.paths ?? []) {
    // Supports ~/ and relative paths
    const resolved = resolveSkillPath(skillPath)
    for await (const match of SKILL_GLOB.scan({ cwd: resolved })) {
      await addSkill(match)
    }
  }

  // 5. Download Skills from remote URLs
  for (const url of config.skills?.urls ?? []) {
    const list = await Discovery.pull(url)
    for (const dir of list) {
      // ...
    }
  }

  return { skills, dirs }
})
```

**Compatibility by design**: OpenCode not only searches its own `.opencode/skills/` directory but also searches `.claude/skills/` and `.agents/skills/` -- this allows existing Claude Code Skills and Skills from other Agent frameworks to be used directly by OpenCode.

**Name collision handling**: If Skills with the same name appear in multiple paths, later-loaded ones override earlier-loaded ones (project-level overrides global-level), and a warning log entry is recorded.

## 14.1.3 Skill Metadata

Each Skill's metadata is extracted from the YAML frontmatter:

| Field         | Required | Description                                                               |
| ------------- | -------- | ------------------------------------------------------------------------- |
| `name`        | Yes      | Unique identifier for the Skill                                           |
| `description` | Yes      | Short description of the Skill (displayed to both the Agent and the user) |

The Skill's `content` field is the Markdown body -- the pure content after stripping the frontmatter. This content is injected into the conversation context when the Agent invokes the `skill` tool.

## 14.1.4 Remote Skill Discovery

The `Discovery.pull()` function implements the ability to download Skills from remote URLs:

```typescript
// skill/discovery.ts
export async function pull(url: string): Promise<string[]> {
  // 1. Fetch index.json (the Skill index file)
  const data = await fetch(new URL("index.json", base).href)
    .then(response => response.json())

  // index.json format:
  // {
  //   "skills": [
  //     { "name": "git-master", "files": ["SKILL.md", "examples/..."] },
  //     { "name": "frontend-ui", "files": ["SKILL.md"] }
  //   ]
  // }

  // 2. Download all files for each Skill in parallel
  await Promise.all(list.map(async (skill) => {
    const root = path.join(cache, skill.name)
    await Promise.all(skill.files.map(async (file) => {
      const link = new URL(file, `${host}/${skill.name}/`).href
      const dest = path.join(root, file)
      await get(link, dest)  // Download with caching
    }))
  }))

  return result  // Returns a list of directories containing SKILL.md
}
```

Remote Skills are downloaded to a cache directory (`~/.cache/opencode/skills/`), and a simple cache is implemented using file existence checks -- if a file already exists, the download is skipped.

## 14.1.5 Summary

The design of the Skill system reflects several principles:

1. **Simple format**: Pure Markdown + YAML frontmatter -- no programming knowledge is needed to create a Skill.
2. **Multi-source discovery**: Global directories, project directories, configuration paths, remote URLs -- Skills can come from anywhere.
3. **Cross-tool compatibility**: By searching `.claude/` and `.agents/` directories, the system is compatible with Skill formats from other AI coding assistants.
4. **Instance-level caching**: The Skill list is managed through `Instance.state()`, with each project instance having its own independent Skill collection.
