Programmatic Tool Calling (PTC) plugin for OpenCode.
This plugin enables models to execute JavaScript code that can orchestrate multiple tool calls, agents, and skills in a single execution context.
Add the plugin to your opencode.json:
{
"plugin": ["file:///path/to/opencode-pct"]
}Or install from npm (when published):
{
"plugin": ["opencode-pct"]
}Once installed, the plugin exposes two new tools:
Execute JavaScript code that can call available tools, agents, and skills programmatically.
Arguments:
code(string, required): JavaScript code to executelistAvailable(boolean, optional): If true, returns list of available functions instead of executing code
Example:
// Read multiple files in parallel
const [file1, file2] = await Promise.all([
tools.read({ filePath: "/path/to/file1.ts" }),
tools.read({ filePath: "/path/to/file2.ts" }),
]);
// Search for patterns
const matches = await tools.grep({ pattern: "TODO", path: "src" });
// Delegate to an agent for complex analysis
const analysis = await agents.explore("Find all API endpoints and their handlers");
// Log progress
log("Analysis complete, found endpoints");
// Return structured result
return {
file1Length: file1.length,
file2Length: file2.length,
matches: matches.split("\n").length,
analysis
};List all available tools, agents, and skills with their TypeScript-style signatures.
Inside the executed JavaScript code, these globals are available:
| Global | Description |
|---|---|
tools |
Object containing all available tools as async functions |
agents |
Object containing all available agents as async functions |
skills |
Object containing all available skills as async functions |
log(...args) |
Function to log messages (captured in output) |
context |
Object with sessionID and messageID |
- Discovery: On execution, the plugin fetches all available tools, agents, and skills from the OpenCode session
- Translation: Each capability is translated into an async JavaScript function
- Execution: The provided code is executed in a sandboxed async context with access to these functions
- Orchestration: Tool calls made during execution are tracked and reported in the output
# Install dependencies
bun install
# Build
npm run build
# Type check
npm run typecheckMIT