> 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.2_skill_loading_flow.md). Agents can also search and read this documentation through its [MCP server](https://www.opencodebook.xyz/~gitbook/mcp).

# 14.2 Skill Loading Flow

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

***

Discovery is only the first step -- discovered Skills still need to be invoked through tool calls to actually take effect. This section analyzes the complete flow from Skill discovery to injection into the Agent context.

## 14.2.1 Skill.dirs() -- Building Search Paths

`Skill.dirs()` returns all directory paths that contain Skills. These paths are passed to the Agent's System Prompt so that the Agent knows which Skills are available:

```typescript
// skill/skill.ts
export async function dirs() {
  return state().then((x) => x.dirs)
}
```

During the Skill discovery process, the directory of each successfully loaded Skill is recorded in the `dirs` Set:

```typescript
const addSkill = async (match: string) => {
  const md = await ConfigMarkdown.parse(match)
  // ... parsing and validation ...
  dirs.add(path.dirname(match))  // Record the directory
  skills[parsed.data.name] = { /* ... */ }
}
```

## 14.2.2 SkillTool -- Loading Skills into Context via Tool Calls

Skills are not automatically loaded all at once when the Agent starts -- that would waste precious context window space. Instead, the Agent **loads Skills on demand** by invoking the `skill` tool.

The `skill` tool workflow:

```
1. Agent sees the list of available Skills (in the System Prompt)
2. Agent determines that a particular Skill is needed for the current task
3. Agent calls the skill tool: skill({ name: "git-master" })
4. The tool returns the complete Markdown content of the Skill
5. The Skill content enters the conversation context as a tool call result
6. The Agent's subsequent behavior is guided by the Skill content
```

This on-demand loading design means:

* **Token savings**: Only Skills that are actually needed occupy context window space.
* **Agent autonomy**: The Agent autonomously decides which Skills to load based on task requirements.
* **Dynamic composition**: Different Skills can be loaded at different stages within the same session as needed.

## 14.2.3 The Relationship Between Skills and the Agent Prompt

The Agent's System Prompt includes the names and descriptions of all available Skills, but **does not include the full content** of the Skills:

```
Available Skills:
- git-master: Expert at Git operations including atomic commits, rebase, squash
- frontend-ui-ux: Designer-turned-developer who crafts stunning UI/UX
- playwright: Browser automation via Playwright MCP
```

After seeing this list, the Agent decides whether to load a Skill based on the user's request. For example:

* User says "help me commit the code" -> Agent loads `git-master`
* User says "fix this CSS layout" -> Agent loads `frontend-ui-ux`
* User says "test this web page" -> Agent loads `playwright`

This "directory + on-demand loading" pattern is similar to "Demand Paging" in operating systems -- rather than preloading all content, it is loaded only when actually accessed.

> **Extended Explanation**: Demand Paging is a memory management strategy in operating systems where pages are not loaded into physical memory until they are actually referenced. This avoids wasting memory on pages that may never be used. The Skill system applies the same philosophy -- Skill content is not loaded into the context window until the Agent actually needs it, thereby conserving the limited context space.

## 14.2.4 Skill Query API

The Skill module exposes three public methods:

```typescript
// Get a single Skill
export async function get(name: string): Promise<Info | undefined> {
  return state().then((x) => x.skills[name])
}

// Get all Skills
export async function all(): Promise<Info[]> {
  return state().then((x) => Object.values(x.skills))
}

// Get all Skill directories
export async function dirs(): Promise<string[]> {
  return state().then((x) => x.dirs)
}
```

These APIs are consumed by the following components:

| Consumer              | API Used          | Purpose                                    |
| --------------------- | ----------------- | ------------------------------------------ |
| `skill` tool          | `Skill.get(name)` | Load the content of a specified Skill      |
| System Prompt builder | `Skill.all()`     | Get the Skill list to display to the Agent |
| Tool Registry         | `Skill.dirs()`    | Load custom tools from Skill directories   |
| Command module        | `Skill.all()`     | Register Skills as Slash Commands          |

## 14.2.5 Summary

The Skill loading flow follows the principle of "lazy loading":

```
Instance startup
  |
Skill discovery: scan all paths, build the Skill index
  |
System Prompt: inject Skill names and description list into the Agent
  |
Agent running: invoke the skill tool as needed
  |
Skill content injected into conversation context
  |
Agent behavior guided by the Skill
```

This two-phase design (discover and index first, then load content on demand) is the optimal strategy given the limited context window resources.
