Skip to content

API Tool Reference

What You'll Learn

By reading this API reference, you will:

  • Understand the parameters and return values of the 4 core tools
  • Master the correct way to call tools
  • Learn how to handle common error scenarios

Tool Overview

The OpenCode Agent Skills plugin provides the following 4 tools:

Tool NameDescriptionUse Cases
get_available_skillsGet list of available skillsView all available skills with search and filtering support
read_skill_fileRead skill filesAccess documentation, configuration, and other support files within skills
run_skill_scriptExecute skill scriptsRun automation scripts within the skill directory
use_skillLoad skillInject SKILL.md content into the session context

get_available_skills

Get the list of available skills with optional search filtering.

Parameters

ParameterTypeRequiredDescription
querystringNoSearch query string to match skill names and descriptions (supports * wildcard)

Return Value

Returns a formatted skill list, each item containing:

  • Skill name and source label (e.g., skill-name (project))
  • Skill description
  • List of available scripts (if any)

Example Return:

git-helper (project)
  Git operations and workflow automation tools
  [scripts: tools/commit.sh, tools/branch.sh]

code-review (user)
  Code review checklist and quality standards

Error Handling

  • Returns a hint message when no matches are found
  • Returns similar skill suggestions if the query parameter contains a typo

Usage Examples

List all skills:

User input:
List all available skills

AI calls:
get_available_skills()

Search for skills containing "git":

User input:
Find skills related to git

AI calls:
get_available_skills({
  "query": "git"
})

Search using wildcard:

AI calls:
get_available_skills({
  "query": "code*"
})

Returns:
code-review (user)
  Code review checklist and quality standards

read_skill_file

Read support files within a skill directory (documentation, configuration, examples, etc.).

Parameters

ParameterTypeRequiredDescription
skillstringYesSkill name
filenamestringYesFile path (relative to skill directory, e.g., docs/guide.md, scripts/helper.sh)

Return Value

Returns a confirmation message of successful file loading.

Example Return:

File "docs/guide.md" from skill "code-review" loaded.

The file content is injected into the session context in XML format:

xml
<skill-file skill="code-review" file="docs/guide.md">
  <metadata>
    <directory>/path/to/skills/code-review</directory>
  </metadata>
  
  <content>
[Actual file content]
  </content>
</skill-file>

Error Handling

Error TypeReturn Message
Skill not foundSkill "xxx" not found. Use get_available_skills to list available skills.
Unsafe pathInvalid path: cannot access files outside skill directory.
File not foundFile "xxx" not found. Available files: file1, file2, ...

Security Mechanisms

  • Path safety check: Prevents directory traversal attacks (e.g., ../../../etc/passwd)
  • Only files within the skill directory can be accessed

Usage Examples

Read skill documentation:

User input:
View the usage guide for code-review skill

AI calls:
read_skill_file({
  "skill": "code-review",
  "filename": "docs/guide.md"
})

Read configuration file:

AI calls:
read_skill_file({
  "skill": "git-helper",
  "filename": "config.json"
})

run_skill_script

Execute executable scripts within a skill directory.

Parameters

ParameterTypeRequiredDescription
skillstringYesSkill name
scriptstringYesScript relative path (e.g., build.sh, tools/deploy.sh)
argumentsstring[]NoArray of command-line arguments to pass to the script

Return Value

Returns the script output.

Example Return:

Building project...
✓ Dependencies installed
✓ Tests passed
Build complete.

Error Handling

Error TypeReturn Message
Skill not foundSkill "xxx" not found. Use get_available_skills to list available skills.
Script not foundScript "xxx" not found in skill "yyy". Available scripts: script1, script2, ...
Execution failedScript failed (exit 1): error message

Script Discovery Rules

The plugin automatically scans executable files in the skill directory:

  • Maximum recursion depth: 10 levels
  • Skip hidden directories (starting with .)
  • Skip common dependency directories (node_modules, __pycache__, .git, etc.)
  • Only include files with executable bit set (mode & 0o111)

Execution Environment

  • Working directory (CWD) changes to the skill directory
  • Scripts execute within the skill directory context
  • Output is returned directly to the AI

Usage Examples

Execute build script:

User input:
Run the project's build script

AI calls:
run_skill_script({
  "skill": "git-helper",
  "script": "tools/build.sh"
})

Execute with arguments:

AI calls:
run_skill_script({
  "skill": "deployment",
  "script": "deploy.sh",
  "arguments": ["--env", "production", "--force"]
})

use_skill

Load the SKILL.md content of a skill into the session context.

Parameters

ParameterTypeRequiredDescription
skillstringYesSkill name (supports namespace prefix, e.g., project:my-skill, user:my-skill)

Return Value

Returns a confirmation message of successful skill loading, including available scripts and file list.

Example Return:

Skill "code-review" loaded.
Available scripts: tools/check.sh, tools/format.sh
Available files: docs/guide.md, examples/bad.js

The skill content is injected into the session context in XML format:

xml
<skill name="code-review">
  <metadata>
    <source>user</source>
    <directory>/path/to/skills/code-review</directory>
    <scripts>
      <script>tools/check.sh</script>
      <script>tools/format.sh</script>
    </scripts>
    <files>
      <file>docs/guide.md</file>
      <file>examples/bad.js</file>
    </files>
  </metadata>

  [Claude Code tool mapping...]
  
  <content>
[Actual SKILL.md content]
  </content>
</skill>

Namespace Support

Use namespace prefixes to precisely specify skill source:

NamespaceDescriptionExample
project:Project-level OpenCode skillsproject:my-skill
user:User-level OpenCode skillsuser:my-skill
---------
---------
No prefixUses default prioritymy-skill

Error Handling

Error TypeReturn Message
Skill not foundSkill "xxx" not found. Use get_available_skills to list available skills.

Auto-injection Features

When loading a skill, the plugin automatically:

  1. Lists all files in the skill directory (excluding SKILL.md)
  2. Lists all executable scripts
  3. Injects Claude Code tool mapping (if required by the skill)

Usage Examples

Load skill:

User input:
Help me perform a code review

AI calls:
use_skill({
  "skill": "code-review"
})

Specify source using namespace:

AI calls:
use_skill({
  "skill": "user:git-helper"
})

Appendix: Source Code Reference

Click to expand source code locations

Last updated: 2026-01-24

ToolFile PathLine Range
GetAvailableSkills toolsrc/tools.ts29-72
ReadSkillFile toolsrc/tools.ts74-135
RunSkillScript toolsrc/tools.ts137-198
UseSkill toolsrc/tools.ts200-267
Tool registrationsrc/plugin.ts160-167
Skill type definitionsrc/skills.ts43-52
Script type definitionsrc/skills.ts35-38
SkillLabel type definitionsrc/skills.ts30
resolveSkill functionsrc/skills.ts269-283

Key Types:

  • Skill: Complete skill metadata (name, description, path, scripts, template, etc.)
  • Script: Script metadata (relativePath, absolutePath)
  • SkillLabel: Skill source identifier (project, user, claude-project, etc.)

Key Functions:

  • resolveSkill(): Resolve skill name, supports namespace prefixes
  • isPathSafe(): Validate path safety, prevent directory traversal
  • findClosestMatch(): Fuzzy match suggestion

Coming Up Next

This course has completed the API tool reference documentation for OpenCode Agent Skills.

For more information, please check: