opencode
In-depth reference for how OpenCode works — the AI agent framework that powers this environment. Covers: agents (definition, loading, modes, model assignment), skills (discovery, loading, structure), tools (built-in + custom, permissions), commands (slash commands, frontmatter, routing), sessions (lifecycle, prompting, subagents), config (opencode.jsonc, providers, MCP servers, plugins), and the full REST/SSE API. Load this skill when you need to understand OpenCode internals, debug agent/tool/skill issues, extend the framework, create custom tools, or work with the session API.
What this skill does
# OpenCode — Agent Framework Reference
OpenCode is the AI agent framework running this environment. It manages agents, skills, tools, commands, sessions, providers, and plugins. Everything is configured via files in the config directory (`/opt/opencode/` in the Kortix sandbox, or `.opencode/` in a project).
## Architecture Overview
```
┌─────────────────────────────────────────────────────┐
│ OpenCode │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Agents │ │ Skills │ │ Tools │ │
│ │ (.md) │ │ (SKILL.md)│ │ (.ts) │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
│ │ │ │ │
│ ┌────▼──────────────▼──────────────▼─────┐ │
│ │ Session Engine │ │
│ │ (prompt → model → tool calls → text) │ │
│ └────────────────┬───────────────────────┘ │
│ │ │
│ ┌────────────────▼───────────────────────┐ │
│ │ Provider Layer │ │
│ │ (Anthropic, OpenAI, Kortix router) │ │
│ └────────────────────────────────────────┘ │
│ │
│ Config: opencode.jsonc │ Plugins │ MCP Servers │
└─────────────────────────────────────────────────────┘
```
---
## Agents
### What is an Agent?
An agent is a **persona** — a system prompt combined with permission rules, model preferences, and behavioral constraints. Defined as `.md` files with YAML frontmatter.
### Agent Definition File
Location: `agents/*.md` or `agents/**/*.md` in the config directory.
```markdown
---
description: "Short description shown in UI and Task tool"
model: provider/model-id
mode: primary
permission:
bash: allow
edit: allow
read: allow
task: allow
skill: allow
# ... tool permissions
---
# Agent Name
System prompt content goes here. This entire markdown body
becomes the agent's system prompt.
```
### Frontmatter Fields
| Field | Type | Required | Description |
|---|---|---|---|
| `description` | string | Yes | Shown in UI and Task tool agent list |
| `mode` | `primary` / `subagent` / `all` | Yes | Controls where the agent appears |
| `model` | string | No | Default model as `provider/model-id` (e.g., `anthropic/claude-opus-4-6`) |
| `permission` | object | No | Tool permission rules (`allow` / `deny` per tool name) |
| `temperature` | number | No | Model temperature |
| `topP` | number | No | Top-P sampling |
| `steps` | number | No | Max tool-use steps per turn |
| `hidden` | boolean | No | Hide from UI |
### Agent Modes
| Mode | User-selectable | Task tool | Use case |
|---|---|---|---|
| `primary` | Yes | Hidden from list, but **can be spawned by name** | Main agent the user interacts with |
| `subagent` | No | Listed and spawnable | Specialist agents for Task tool delegation |
| `all` | Yes | Yes | Available everywhere |
**Key insight:** The Task tool's description filters out `primary` mode agents (`a.mode !== "primary"`), but `Agent.get()` (the execution path) has **no mode guard**. A primary agent CAN self-spawn by name via `subagent_type: "agent-name"`.
### Agent Name Derivation
The agent name is the **filename without `.md`**. For nested paths, only the filename matters:
- `agents/kortix.md` → name: `kortix`
- `agents/specialised/my-agent.md` → name: `my-agent`
### Agent Loading Order
1. Built-in agents (compaction, title, summary — hidden infrastructure)
2. Config directory agents (`agents/*.md`)
3. Config overrides from `opencode.jsonc` `"agent"` section (can disable built-in agents)
### Disabling Built-in Agents
In `opencode.jsonc`:
```json
{
"agent": {
"build": { "disable": true },
"plan": { "disable": true },
"explore": { "disable": true },
"general": { "disable": true }
}
}
```
### Agent Permission System
Permissions control which tools an agent can use. Rules are evaluated per-tool-call:
```yaml
permission:
bash: allow # Allow all bash commands
edit: allow # Allow file editing
task: allow # Allow spawning subagents
skill: allow # Allow loading skills
web-search: allow # Allow web search tool
```
Subagent sessions inherit parent permissions but can have additional restrictions. The Task tool hardcodes `todowrite: deny` and `todoread: deny` for all subagent sessions (lines 77-82 of task.ts).
---
## Skills
### What is a Skill?
A skill is a **knowledge package** — domain-specific instructions, workflows, and resources that inject into the agent's context when loaded via the `skill()` tool. Skills transform a general-purpose agent into a specialist on demand.
### Skill Structure
```
skill-name/
├── SKILL.md # Required: frontmatter + instructions
├── scripts/ # Optional: executable code
├── references/ # Optional: supplementary docs
└── assets/ # Optional: templates, images
```
### SKILL.md Format
```markdown
---
name: my-skill
description: "Detailed description of when to load this skill. Include trigger phrases."
---
# Skill Title
Instructions loaded into context when the skill is triggered.
These become part of the agent's working knowledge.
```
**Frontmatter fields:**
| Field | Required | Description |
|---|---|---|
| `name` | Yes | Skill identifier (used in `skill({ name: "..." })`) |
| `description` | Yes | Trigger description — the agent reads this to decide when to load the skill |
### Skill Discovery
Skills are discovered from multiple locations (loaded in order, later overwrites earlier):
1. **Global external dirs:** `~/.claude/skills/**/SKILL.md`, `~/.agents/skills/**/SKILL.md`
2. **Project external dirs:** Walk up from project dir looking for `.claude/skills/`, `.agents/skills/`
3. **OpenCode config dirs:** `{config}/skills/**/SKILL.md` or `{config}/skill/**/SKILL.md`
4. **Additional paths:** From `opencode.jsonc` `skills.paths` array
5. **URL downloads:** From `opencode.jsonc` `skills.urls` array
### Skill Loading Flow
1. On startup, all `SKILL.md` files are scanned and their **name + description** are extracted (~100 tokens each)
2. These descriptions are included in the `skill` tool's description (available_skills list)
3. The agent reads descriptions and decides when to load a skill
4. When loaded via `skill({ name: "..." })`, the full SKILL.md body is injected into context
5. Bundled files (scripts/, references/) are listed but not loaded — the agent reads them as needed
### How the skill tool works
The `skill` tool (defined in `src/tool/skill.ts`):
1. Lists all accessible skills in its description (filtered by agent permissions)
2. When called with a skill name, reads the full SKILL.md content
3. Returns `<skill_content name="...">` block with the content + skill base directory
4. Also lists up to 10 files in the skill directory for the agent to reference
---
## Tools
### What is a Tool?
A tool is a **capability** the agent can invoke — bash commands, file operations, web search, etc. Tools are defined in TypeScript and registered with the framework.
### Built-in Tools
These are part of OpenCode core:
| Tool | Description |
|---|---|
| `bash` | Execute shell commands |
| `read` | Read files |
| `edit` | Edit files (string replacement) |
| `write` | Write/create files |
| `glob` | File pattern matching |
| `grep` | Content search |
| `task` | Spawn subagent sessions |
| `skill` | Load skills |
| `todowrite` | Manage task list |
| `todoread` | Read task list |
| `question` | Ask user questions |
### Custom Tools
Custom tools are TypeScript files in `tools/*.ts` in the config directory. They use the `Tool.define()` API:
```typescript
import { Tool } from "opencode/tool"
import z from "zod"
export default Tool.define("my-tool", async (ctx) => {
return {
description: "What this tool does",
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.