opencode-delegation
v0.1.2
Published
OpenCode plugin for delegating low-cognitive tasks to cheap worker subagents. Reduces token waste, context pollution, and improves long-task stability.
Maintainers
Readme
opencode-delegation
OpenCode plugin that delegates low-cognitive-density tasks to a cheap worker subagent. Reduces token waste, context pollution, and improves long-task stability.
Problem
When running test suites, builds, log monitoring, or heavy search through an AI coding assistant, the main (strong) model wastes expensive tokens on low-cognition work — watching output scroll by, waiting for processes to finish, summarizing verbose logs. This pollutes the context window and burns budget on work a cheap model can handle.
Solution
The plugin configures a worker agent backed by a cheap model and a delegation-manager skill that guides the main model to use OpenCode's built-in task tool for long-running or high-output commands. The main model calls task({ subagent_type: "worker" }), which creates a visible subagent session in the UI. The plugin also trims oversized bash output and injects hints into the bash tool description.
┌─────────────────────────────────────────────┐
│ Main Agent (strong model) │
│ │
│ 1. Receives task │
│ 2. Decides: delegate or handle myself? │
│ 3. If delegate → task({ subagent_type }) │
│ 4. Subagent visible in UI │
│ 5. Receives result │
│ 6. Continues with high-value analysis │
└──────────────────┬──────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Worker Agent (cheap model) │
│ │
│ - Runs command, observes output │
│ - Detects anomalies (errors, warnings) │
│ - Summarizes if output > 200 lines │
│ - Returns structured result │
│ - Visible in UI for progress tracking │
└─────────────────────────────────────────────┘Installation
npm package
npm install --save-dev opencode-delegationAdd to your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"small_model": "opencode/big-pickle",
"plugin": ["opencode-delegation"],
"agent": {
"worker": {
"description": "Executes low-cognitive-density tasks: run commands, observe output, detect anomalies, return structured results.",
"mode": "subagent",
"model": "opencode/big-pickle",
"steps": 20,
"permission": {
"bash": "allow",
"read": "allow",
"edit": "deny",
"task": "deny",
"todowrite": "deny",
"question": "deny",
"webfetch": "deny",
"glob": "allow",
"grep": "allow"
}
}
},
"skills": {
"paths": ["./node_modules/opencode-delegation/skill"]
}
}
modelis set toopencode/big-pickleby default. You can change it to any cheap model you prefer (e.g.,"openai/gpt-4o-mini").
skills.pathsis additive — it adds to the default skill scan paths, not replaces them. Your existing skills will still load.
.opencode directory (alternative)
If you prefer not to use npm, copy the files manually from the npm package (or from this repo):
# From the npm package
cp node_modules/opencode-delegation/agent/worker.md .opencode/agents/worker.md
cp -r node_modules/opencode-delegation/skill/delegation-manager .opencode/skills/delegation-managerOr create them by hand — see agent/worker.md and skill/delegation-manager/SKILL.md in the repo.
OpenCode auto-discovers agents and skills from .opencode/agents/ and .opencode/skills/.
your-project/
├── .opencode/
│ ├── agents/worker.md
│ └── skills/delegation-manager/SKILL.md
└── ...How it works
Skill-guided delegation
The delegation-manager skill teaches the main model when and how to delegate. It guides the model to call:
task({
subagent_type: "worker",
description: "short description",
prompt: "what to do + what to focus on"
})The subagent session is visible in the UI, so you can track progress.
Bash hint injection
The plugin's tool.definition hook adds a reminder to the bash tool's description: for long-running or high-output commands, prefer task with the worker agent.
Output trimming
If the main model runs bash directly and the output exceeds 300 lines, the plugin's tool.execute.after hook truncates it and attaches a summary (test counts, first error, stderr presence).
Worker agent
| Setting | Value |
|---------|-------|
| model | opencode/big-pickle (configurable) |
| steps | 20 |
| bash | allow |
| read | allow |
| glob | allow |
| grep | allow |
| edit | deny |
| task | deny |
Worker can execute commands, read files, and search code. Cannot edit files, spawn sub-agents, or interact with the user.
Project structure
opencode-delegation/
├── src/
│ ├── plugin.ts # Plugin — hooks only (no custom tools)
│ ├── lifecycle/
│ │ ├── filter.ts # Output extraction (test summary, errors, stderr)
│ │ └── monitor.ts # Event monitoring (MVP stub)
│ └── ...
├── skill/
│ └── delegation-manager/
│ └── SKILL.md # Guides main model to use task({ subagent_type: "worker" })
├── agent/
│ └── worker.md # Worker agent definition
└── ...License
MIT
