How does opencode SDK handle skills automatically?
how does opencode sdk handle skills? does it load them automatically?
Now I have a clear picture. Let me summarize how OpenCode SDK handles skills:
##How OpenCode SDK Handles Skills
###Skills are NOT loaded automatically into conversations
Skills in OpenCode are loaded on-demand, not automatically. Here's how the system works:
###1. Skill Discovery (at initialization)
When an OpenCode instance is created for a project, the Skill.state() function (packages/opencode/src/skill/skill.ts:44-127) lazily scans and discovers all available skills from multiple locations:
Project-level:
- .opencode/skill/<name>/SKILL.md
- .opencode/skills/<name>/SKILL.md
- .claude/skills/<name>/SKILL.md
Global:
- ~/.config/opencode/skills/<name>/SKILL.md
- ~/.claude/skills/<name>/SKILL.md
The discovery uses glob patterns:
{skill,skills}/**/SKILL.mdfor OpenCode directoriesskills/**/SKILL.mdfor Claude-compatible directories
###2. Skill Metadata Exposed to Agents
The SkillTool (packages/opencode/src/tool/skill.ts) is registered in the tool registry. When the tool is initialized, it:
- Fetches all discovered skills via
Skill.all() - Filters them by agent permissions
- Embeds their names and descriptions (not full content) into the tool's description:
<available_skills>
<skill>
<name>git-release</name>
<description>How to create a release</description>
</skill>
</available_skills>
###3. On-Demand Loading via Tool Call
The agent sees the available skills listed in the tool description. When the agent decides it needs a skill, it explicitly calls:
skill({ name: "git-release" })
Only then does OpenCode:
- Verify the skill exists
- Check permissions via
ctx.ask() - Parse and return the full
SKILL.mdcontent
###4. SDK Access
The SDK exposes a /skill endpoint to list all available skills:
import { createOpencodeClient } from "@opencode-ai/sdk"
const client = createOpencodeClient()
const skills = await client.app.skills()
###Key Design Points:
| Aspect | Behavior |
|---|---|
| Discovery | Automatic on instance init (lazy) |
| Full Content Loading | On-demand via skill tool call |
| Permission Control | Configurable via opencode.json with allow/deny patterns |
| Can be Disabled | Set skill: false in agent config or use OPENCODE_DISABLE_CLAUDE_CODE_SKILLS env var |
This design keeps the system prompt lean—agents only see skill names/descriptions, and load the full instructions when actually needed.
END OF POST