OpenCode
Spec-driven AI development with betterspec and OpenCode.
OpenCode
betterspec integrates with OpenCode in two complementary ways:
- Global plugin — install once, works across all your projects
- Project scaffold —
betterspec initcreates agent files for OpenCode in your project
Global Plugin (Recommended)
Add betterspec to the plugin array in your opencode.json (global or project-level):
{
"plugin": ["betterspec@git+https://github.com/betterspec/betterspec.git"]
}Restart OpenCode. That's it.
The plugin automatically:
- Auto-discovers betterspec skills from the
skills/directory - Injects spec context into every LLM call — active changes, task progress, and enforcement rules
- Warns on unspecced edits — if an agent edits a file not covered by any active spec, a warning is injected
See .opencode/INSTALL.md on GitHub for detailed setup, migration from the old approach, and troubleshooting.
Project Scaffold (betterspec init)
Running betterspec init with OpenCode selected creates four specialized agent definition files:
betterspec init
# Select your AI tool: OpenCodeAgent Files in .opencode/agents/
| Agent | File | Role |
|---|---|---|
| Planner | .opencode/agents/planner.md | Reads the proposal. Writes requirements, scenarios, design, and tasks. |
| Builder | .opencode/agents/builder.md | Reads specs. Implements tasks one by one, marking them off as it goes. |
| Validator | .opencode/agents/validator.md | Independent review with clean context — verifies implementation against specs. |
| Archivist | .opencode/agents/archivist.md | Archives the completed change, extracts knowledge, and updates capabilities. |
The Golden Rule
The builder never validates its own work.
The Builder and Validator agents are intentionally separate roles. The Validator runs with a clean context (no build history), so it can catch errors that self-review misses — the same reason code review exists in human teams.
Workflow
A typical workflow with OpenCode and betterspec:
- Propose a change:
betterspec propose "Add rate limiting" - Switch to the Planner agent to flesh out specs
- Switch to the Builder agent to implement tasks
- Switch to the Validator agent to review the work
- If issues are found, the Builder fixes them
- The Archivist archives the change and extracts knowledge