A multi-agent orchestration system for opencode, featuring 18 specialized subagents, context compression (ACP), and a formal Phase A/B/C development workflow.
- Overview
- Prerequisites
- Quick Start
- Agent System
- Workflow
- Skills
- Plugins
- ACP (Active Context Pruning)
- Environment Variables
- Configuration Reference
- Directory Structure
This repository provides a reproducible opencode configuration that turns opencode into a multi-agent development team. The orchestrator delegates work to specialized subagents through a structured 3-phase pipeline:
| Phase | Purpose | Agents Involved |
|---|---|---|
| A — Planning | Requirements analysis and plan creation | plan-runner, spec-critic, api-docs-researcher |
| B — Execution | Code implementation with mandatory lint gate | code-explorer, code-executor, test-verifier |
| C — Review | Quality assurance and documentation | code-reviewer, docs-reviewer, documenter, security-reviewer |
The system uses ACP for automatic context compression and a structured Phase A/B/C workflow for task orchestration.
| Dependency | Version | Purpose |
|---|---|---|
| opencode | Latest | AI coding assistant — the runtime for this config |
| Node.js | >= 18 | Plugin runtime (plan-post-approval.ts, opencode-rtk) |
| Go (optional) | >= 1.21 | Building or running native plugins |
| Git | Latest | Source control for plan files and repository management |
| ACP plugin | npm: opencode-acp@latest |
Context compression plugin |
| RTK plugin | npm: opencode-rtk@^0.0.1 |
Token usage tracking |
git clone <your-repo-url> ~/StubbornBetterOpencode
cd ~/StubbornBetterOpencode
# Main opencode configuration
cp scripts/setup/opencode.jsonc ~/.config/opencode/opencode.jsonc
# Agent definitions and workflow instructions
cp scripts/setup/AGENTS.md ~/.config/opencode/AGENTS.md
# ACP (context compression) configuration
cp scripts/setup/acp.jsonc ~/.config/opencode/acp.jsonc
mkdir -p ~/.config/opencode/plugins
# Plan post-approval plugin (handles plan→execution handoff)
cp scripts/setup/plan-post-approval.ts ~/.config/opencode/plugins/plan-post-approval.ts
# Agent definition files (18 subagents)
cp -r config/opencode/agents ~/.config/opencode/agents
Note: Make sure
~/.config/opencode/plugins/exists before copying the plugin.
cd ~/.config/opencode
npm init -y
npm install @opencode-ai/plugin@1.17.13 opencode-rtk@^0.0.1
Or use the package.json from config/opencode/:
{
"dependencies": {
"@opencode-ai/plugin": "1.17.13",
"opencode-rtk": "^0.0.1"
}
}
Skills live in config/opencode/skills/ in this repo. Copy or symlink them to ~/.config/opencode/skills/:
# Option A: Copy all skills
cp -r config/opencode/skills/* ~/.config/opencode/skills/
# Option B: Symlink for live updates
ln -sfn $(pwd)/config/opencode/skills/* ~/.config/opencode/skills/
Available skills (14 total):
| Skill | Directory |
|---|---|
| agent-delegation | config/opencode/skills/agent-delegation/ |
| agent-workflow | config/opencode/skills/agent-workflow/ |
| CoT-budget | config/opencode/skills/CoT-budget/ |
| documenter | config/opencode/skills/documenter/ |
| kryton | config/opencode/skills/kryton/ |
| ponytail | config/opencode/skills/ponytail/ |
| productionalizer | config/opencode/skills/productionalizer/ |
| project-context | config/opencode/skills/project-context/ |
| pythonic-quality | config/opencode/skills/pythonic-quality/ |
| quality-gate | config/opencode/skills/quality-gate/ |
| security-investigation | config/opencode/skills/security-investigation/ |
| skill-creator | config/opencode/skills/skill-creator/ |
| task-management | config/opencode/skills/task-management/ |
| terse-mode | config/opencode/skills/terse-mode/ |
Create ~/.config/opencode/.env for any API keys or endpoints your LLM provider needs. Source it at shell start.
Tip: opencode expands
${VAR_NAME}syntax in config files. Never hardcode secrets.
opencode
The default agent is orchestrator. Type /rtk for token savings, /acp context for compression stats.
The system defines 18 subagents (plus the autonomous supervisor mode). All agents inherit the session's active model — no hardcoded model bindings.
| Agent | Role | Has Tools | Can Read | Can Edit | Can Bash |
|---|---|---|---|---|---|
orchestrator |
Coordinates work via Task delegation | question, todowrite, task | Plans only | Denied | Denied |
plan-runner |
Creates .opencode/plans/*.md plans |
glob, grep, read, edit, bash, task | Any | Plans only | ls, find, cat, mkdir, touch, grep |
productionalizer |
Productionalizes code — researches, creates formal plans | read, glob, grep, bash, task | Any | Denied | ls, find, cat, wc, grep, pwd |
code-executor |
Implements code slices | read, glob, grep, edit, bash, task | Any | Allow (in scope) | git, ls, cat, cd, mkdir, cp, mv, rm, chmod |
code-explorer |
Reads existing code for context | read, glob, grep, bash | Any | Denied | ls, find, cat, pwd |
code-reviewer |
Reviews stable cumulative diff | read, glob, grep, bash | Any | Denied | ls, find, cat, pwd |
test-verifier |
Runs scoped test suites | read, glob, grep, bash, task | Any | Denied | npm, ls, find, pwd, cat, grep |
security-reviewer |
Security-sensitive diff review | read, glob, grep, bash, question | Any | Denied | ls, find, cat, pwd |
docs-reviewer |
CLI/config/env docs review audit | read, glob, grep, bash | Any | Denied | ls, find, cat, pwd |
documenter |
Reads code and writes documentation | read, glob, grep, edit, bash, task | Any | Docs files | ls, find, cat, pwd, grep |
spec-critic |
Architectural ambiguity critique | read, glob, grep, bash, question | Any | Denied | ls, find, cat, pwd, grep |
api-docs-researcher |
External API documentation research | read, glob, grep, bash | Any | Denied | ls, find, cat, pwd, grep, wc, curl |
host-security-investigator |
Host-level security investigation | read, glob, grep, bash, question | Any | Denied | ls, find, cat, pwd, grep |
systematic-debugger |
Root-cause analysis and bug fixing | read, glob, grep, edit, bash, task | Any | Allow (in scope) | git, ls, cat, cd, mkdir, cp, mv, rm, chmod |
refactor-agent |
Codebase audit, modularization | read, glob, grep, edit, bash, task | Any | Allow (in scope) | ls, find, cat, pwd, grep, cp, mv, rm |
systemadmin |
Server management, Docker, networking, infra | read, glob, grep, edit, bash, task | Any | Allow | Docker, systemctl, ssh, git, apt, npm, ls, cat, mv, cp, rm |
brainstorming-general |
Idea generation, creative exploration | read, glob, grep, bash, question | Any | Denied | ls, find, cat, pwd, grep |
brainstorming-business |
Business strategy, frameworks, research | read, glob, grep, bash, question | Any | Denied | ls, find, cat, pwd, grep |
autonomous |
Self-approval skill mode — loaded on demand via skill tool, not a subagent |
skill, task, question, todowrite | Any (review) | Config/admin only | Config/admin only |
Subagents activate automatically when the orchestrator detects trigger keywords in user messages:
| Trigger Keywords | Agent Activated |
|---|---|
| implement, write, add, change, update, fix, refactor, create | code-executor |
| read, find, locate, explore, list, search, grep, show | code-explorer |
| test, verify, check, lint, typecheck | test-verifier |
| review, audit | code-reviewer |
| security audit, vulnerability scan, threat model | security-reviewer |
| documentation check, doc review | docs-reviewer |
| document, write docs, readme | documenter |
| plan, strategy | plan-runner |
| critique, spec review | spec-critic |
| research api, api docs, sdk docs | api-docs-researcher |
| host audit, server security | host-security-investigator |
| debug, root cause, bug fix | systematic-debugger |
| refactor, modularize, cleanup | refactor-agent |
| server, docker, system, infrastructure, deployment, monitor, service, network | systemadmin |
| brainstorm, ideas, creative, explore, options, alternatives, imagine | brainstorming-general |
| strategy, business, framework, industry, market, best practice, thesis, ROI | brainstorming-business |
| productionalize, production-ready, deploy hardening | productionalizer |
The development process follows a Phase A / B / C pipeline managed by the orchestrator.
- User request → orchestrator identifies scope
plan-runnerinvestigates and writes a plan to.opencode/plans/*.md- User reviews and approves or revises via the PlanApprove gate
- On approval,
plan-post-approval.tsplugin:- Detects the
question.asked/question.repliedevents - Compacts the session context
- Injects the approved plan as handoff instructions to the orchestrator
- Detects the
code-explorerreads existing code for context- Orchestrator calls
todowriteto define TODOs from the plan code-executorimplements slices one at a time (narrow prompts)- Mandatory lint gate — after every code change:
test-verifierrunsscripts/lint.sh(or language-specific equivalent)- If lint fails → fix before proceeding
- This is a blocking gate — no exceptions
- Repeat for each slice until the plan is complete
code-reviewerreviews the cumulative diff for correctnessdocs-reviewerchecks whether docs need updatingdocumenterwrites/updates documentationsecurity-reviewer(when applicable) checks auth, secrets, file handling- Orchestrator summarizes the results
- Bug fixing: Route directly to
systematic-debugger(structured RCA pipeline) - Refactoring: Route to
refactor-agent(modularization, AI-readability) - Security audit: Add
security-reviewerfor auth/file/shell-sensitive areas - Terse/caveman mode: Load
terse-mode+ponytail+CoT-budgetskills before delegating
All plans live in .opencode/plans/ at the project root. The plan-post-approval plugin reads them and passes their content into the handoff prompt.
Skills are loaded on demand via the skill tool. They provide specialized instructions and workflows.
| Skill | Description |
|---|---|
agent-delegation |
Decision framework for when to delegate vs. handle inline |
agent-workflow |
Phase A/B/C orchestration workflow details |
CoT-budget |
Chain-of-thought token budget — caps reasoning by task complexity |
customize-opencode |
Config/skill/agent/plugin editing for opencode itself (built-in) |
documenter |
Codebase documentation workflow (what this README was written with) |
kryton |
Knowledge base integration — save/retrieve/persist context across sessions |
ponytail |
Code generation decision ladder — YAGNI / stdlib / native / oneliner / MVP |
productionalizer |
Production readiness assessment and deployment hardening |
project-context |
LLM server, deployment, project context |
pythonic-quality |
Python code quality standards (SOLID, Liskov, idiomatic) |
quality-gate |
Lint, typecheck, code review gates — pre-merge enforcement |
security-investigation |
Host/server security audit workflow |
skill-creator |
Creating and updating skill files |
task-management |
Feature subtask tracking with status and dependencies |
terse-mode |
Minimal communication protocol — caveman mode, 15-30% token savings |
Tracks token usage and savings. Commands are auto-rewritten:
- Config:
~/.config/rtk/config.toml - Type
/rtkin the TUI for savings summary - Avoid
rtk cat— usertk read
Handles automatic context compression. opencode's built-in auto-compaction is disabled (compaction.auto: false) — ACP controls all context management.
- Config:
~/.config/opencode/acp.jsonc - Commands:
/acp context,/acp stats,/acp sweep,/acp compress,/acp manual
Custom TypeScript plugin that automates the handoff after a plan is approved:
- Listens for
question.askedevents with headerPlanApprove - On approval (
question.replied), extracts the plan file path - Compacts the session via
session.summarize - Injects a structured handoff prompt to the orchestrator with TODOs
Configuration is read from opencode.jsonc → agent.orchestrator.plan_post_approval_handoff_agent (defaults to "orchestrator").
ACP manages context window compression automatically. Configured at ~/.config/opencode/acp.jsonc:
| Setting | Value | Description |
|---|---|---|
| enabled | true |
Active |
| compress.mode | "range" |
Range-based compression |
| compress.permission | "allow" |
No prompt needed |
| compress.maxContextLimit | "55%" |
Trigger compression at 55% |
| compress.minContextLimit | "45%" |
Resume at 45% |
| turnProtection.turns | 2 |
Protect last 2 turns from compression |
| strategies.deduplication.enabled | true |
Remove duplicate content |
| strategies.purgeErrors.enabled | true |
Auto-purge error stack traces after 4 turns |
| nudgeFrequency | 5 |
Check every 5 turns |
Commands:
/acp context— Show current context status/acp stats— Compression statistics/acp sweep— Force compression sweep/acp compress— Manual compression/acp manual— Toggle manual mode
Create ~/.config/opencode/.env for environment-specific variables. Never commit this file.
The .env file should contain any API keys, tokens, or endpoints your configured provider or MCP servers require. Source it at shell start (e.g., via ~/.bashrc.d/ or .bashrc) so variables are available when opencode starts.
# ~/.config/opencode/.env
# Add API keys for your LLM provider(s), MCP servers, or other services
# OPENCODE_API_KEY=your-key-here
Tip: Reference variables in
opencode.jsoncas${VARIABLE_NAME}— opencode expands them at startup. No hardcoded secrets in config files.
Located at ~/.config/opencode/opencode.jsonc.
| Key | Value | Notes |
|---|---|---|
$schema |
https://opencode.ai/config.json |
Authoritative schema — check before editing |
default_agent |
"orchestrator" |
Primary agent on session start |
share |
"manual" |
Manual sharing mode |
autoupdate |
true |
Auto-update opencode |
provider |
(your LLM provider) | Configured in opencode.jsonc — see provider docs |
The config uses a provider block with a baseURL, apiKey, and model list. Swap in any OpenAI-compatible provider.
"plugin": [
"opencode-rtk", // Token tracking
"opencode-acp@latest", // Context compression
"plugins/plan-post-approval.ts" // Plan→execution handoff
]
Plugins load in order. The plan-post-approval.ts path is relative to ~/.config/opencode/.
"permission": {
"question": "allow",
"todowrite": "allow",
"edit": "ask", // Prompts for file edits
"bash": "ask" // Prompts for shell commands
}
Each agent also has its own permission block in its .md definition file (e.g., agents/orchestrator.md). Agent-level permissions override global permissions for that agent.
- PermissionObjectConfig is a flat
{pattern: action}object — arrays of[{pattern, action}]are invalid and will crash opencode on startup. - Last-match-wins ordering: a later
"*": "deny"beats an earlier"*": "allow". - Config changes require a restart — opencode does not hot-reload.
Each agent is defined in ~/.config/opencode/agents/<agent-name>.md with YAML frontmatter:
---
description: Role description
mode: primary | subagent
hidden: true | false
temperature: 0.2
permission:
read: allow
edit: deny
bash: deny
# ... tool-specific permissions
---
The orchestrator uses mode: primary and has no read/write/bash access — it coordinates solely via Task delegation.
~/.config/opencode/
opencode.jsonc # Main configuration
AGENTS.md # Agent definitions and workflow docs
acp.jsonc # ACP context compression config
.env # API keys (gitignored, never commit)
package.json # Plugin dependencies
node_modules/ # Installed plugin packages
plugins/
plan-post-approval.ts # Plan→execution handoff plugin
agents/
orchestrator.md # Agent definition files (18 total)
plan-runner.md
code-executor.md
... # One per subagent
skills/
agent-delegation/ # Skill directories (14 total)
agent-workflow/
...
Project repo root:
config/opencode/ # Source of truth for config
scripts/setup/ # Deployment copies for easy setup
docs/ # Documentation
Private — internal use configuration. See repository license for details.