OpenCode Async Agent Plugin
Async background delegation for OpenCode — run multiple AI agents in parallel.
Features
- Parallel Execution — Delegate tasks to background agents while you continue working
- Multiple Agents — Use explore, researcher, or any custom agent
- Model Override — Specify which model runs each task (e.g.,
minimax/MiniMax-M2.5)
- Session Persistence — Resume cancelled tasks without losing context
- Slash Commands —
/delegation to list all delegation status and metadata
- System Prompt Injection — Your
~/.config/opencode/async-agent.md config is automatically loaded
- AI-Powered Analysis — Use
delegation_read(ai=true) to get comprehensive session analysis
Installation
From npm (Recommended)
The plugin is published on npm as opencode-async-agent. Add it to your OpenCode config:
Global config (~/.config/opencode/opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["opencode-async-agent"]
}
Or project config (opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["opencode-async-agent"]
}
Restart OpenCode — the plugin will be installed automatically via Bun and loaded on startup.
Manual Setup
If you prefer local development:
-
Clone and build:
git clone https://github.com/aptdnfapt/opencode-async-agent
cd opencode-async-agent
npm install
npm run build
-
Copy to OpenCode plugins:
mkdir -p ~/.config/opencode/plugin
cp dist/async-agent.js ~/.config/opencode/plugin/
-
Restart OpenCode — the plugin auto-registers on startup
Usage
The plugin adds these tools to your OpenCode agent:
| Tool |
Description |
delegate(prompt, agent) |
Start a background task |
delegate(prompt, agent, model) |
Start with specific model |
delegation_read(id) |
Get completed result (simple mode) |
delegation_read(id, mode="full") |
Get all messages in session |
delegation_read(id, ai=true) |
AI-powered session analysis |
delegation_read(id, ai=true, ai_model="provider/model") |
Use specific model for analysis |
delegation_list() |
List active/completed tasks |
delegation_cancel(id|all) |
Cancel running task(s) |
delegation_resume(id, prompt?) |
Resume cancelled task |
Slash Commands
/delegation — List all active and completed delegations for the current session, including:
- Delegation ID (with
opencode -s {id} command to open session)
- Status (running/completed/error/cancelled)
- Agent used
- Duration
- Start time
- Title/description
Configuration
Step 1: Find Model Names
First, run this command to see available models and get the full provider/model string:
opencode models | grep <model-name>
For example:
opencode models | grep minimax
# Output: minimax/MiniMax-M2.5
# minimax/MiniMax-M2.1
Step 2: Configure Models
Recommended: Create ~/.config/opencode/async-agent.md:
# Async Agent Model Configuration
## Recommended Models
### Fast
- `minimax/MiniMax-M2.5`
### Good Understanding
- `synthetic/hf:moonshotai/Kimi-K2.5`
## Notes
Format: `provider/model` — pass to `delegate()` via the `model` parameter.
This file is automatically injected into your agent's system prompt, so it knows which models to use when you ask it to delegate tasks.
Alternative: Create subagent markdown files with hardcoded models. Learn more at Agents Documentation
AI-Powered Session Analysis
The delegation_read tool now supports AI-powered analysis to help main agents understand what happened in delegated sessions.
Usage
# Automatic model selection (uses parent session's model)
delegation_read(id="session123", ai=true)
# Or specify a custom model
delegation_read(id="session123", ai=true, ai_model="minimax/MiniMax-M2.5")
Model Selection Priority
When ai=true and no ai_model is specified:
- Uses
ai_model (if provided)
- Falls back to parent session's model (captured when delegation was created)
- Falls back to OpenCode default model (from
opencode config)
- Errors if no model available
Analysis Output
The AI provides a comprehensive markdown report covering:
| Section |
What It Evaluates |
| Summary |
2-3 sentence overview |
| What's AI Missed |
Requirements not met from original prompt |
| Wrong Doings |
Incorrect assumptions or bad approaches |
| Gave Up / Shortcuts |
Premature abandonment or skipped steps |
| Messed Up |
Broken functionality or introduced issues |
| Good Points / Choices |
Sound decisions worth replicating |
| Session Completion |
Proper finish, stream cut out, or ambiguous |
| Overall Status |
Assessment of session reliability |
| Next Action |
Recommendation for main agent |
Debug Logging
To enable detailed logging of AI analysis calls:
export OC_ASYNC_DEBUG=true
Logs are saved to ~/.cache/opencode-delegation-ai/ in JSON format with:
- Timestamp
- Delegation ID
- Model used
- Status (success/error)
- Duration
- Result or error message
Requirements
AI analysis requires:
- Completed session — Only works on sessions with
completed status
- Valid model — Provider must exist in
~/.cache/opencode/models.json
- API key — Provider must be configured in
~/.local/share/opencode/auth.json
- Timeout — 60 seconds max for analysis API call
How I Use It
For Parallel Research
My workflow with async agent goes like this:
My workflow with async agent goes like this:
-
Use Claude Opus 4.5 as my main planner — I tell Opus what I want to build, including tech stack, key libraries, APIs, etc.
-
Identify knowledge gaps — When I don't know much about a specific component or tech choice
-
Launch parallel research — I tell Opus: "Send 15 minimax agents to research this part"
Opus then makes multiple delegate() tool calls with:
delegate(prompt="Research React patterns for large apps", agent="explore", model="minimax/MiniMax-M2.5")
- Each delegation is a separate session owned by the main session
- Agents perform research using web search, zread/zai for GitHub, grep.app for code examples, MCP tools, or cloned OSS codebases
-
Continue planning while research runs — Opus keeps working with me on the plan while the async agents investigate in the background
-
Check live progress — To see what a delegation is doing in real-time:
- Press
Ctrl+X then ← / → to navigate sessions
- Child sessions appear under parent (owned by main agent)
- You can watch the agent work live
-
Get notified + read results — When research completes, <system-reminder> fires to notify Opus, Opus reads the results internally with delegation_read(id), then explains the findings to me
The parallelism is key — 15 agents researching different aspects simultaneously means comprehensive information in the time it would take to do one sequential query.
Note: I've also tried using async agent for parallel feature implementation but haven't found good success with that.
Project Structure
src/plugin/
plugin.ts — Entry point, tool registration
manager.ts — Delegation state machine
tools.ts — Tool factories
types.ts — Type definitions
rules.ts — System prompt injection
utils.ts — Helpers
dist/
async-agent.js — Bundled output
License
MIT