OpenCode Support Design
Date: 2025-11-22 Author: Bot & Jesse Status: Design Complete, Awaiting Implementation
Overview
Add full superpowers support for OpenCode.ai using a native OpenCode plugin architecture that shares core functionality with the existing Codex implementation.
Background
OpenCode.ai is a coding agent similar to Claude Code and Codex. Previous attempts to port superpowers to OpenCode (PR #93, PR #116) used file-copying approaches. This design takes a different approach: building a native OpenCode plugin using their JavaScript/TypeScript plugin system while sharing code with the Codex implementation.
Key Differences Between Platforms
- Claude Code: Native Anthropic plugin system + file-based skills
- Codex: No plugin system → bootstrap markdown + CLI script
- OpenCode: JavaScript/TypeScript plugins with event hooks and custom tools API
OpenCode's Agent System
- Primary agents: Build (default, full access) and Plan (restricted, read-only)
- Subagents: General (research, searching, multi-step tasks)
- Invocation: Automatic dispatch by primary agents OR manual
@mentionsyntax - Configuration: Custom agents in
opencode.jsonor~/.config/opencode/agent/
Architecture
High-Level Structure
-
Shared Core Module (
lib/skills-core.js)- Common skill discovery and parsing logic
- Used by both Codex and OpenCode implementations
-
Platform-Specific Wrappers
- Codex: CLI script (
.codex/superpowers-codex) - OpenCode: Plugin module (
.opencode/plugin/superpowers.js)
- Codex: CLI script (
-
Skill Directories
- Core:
~/.config/opencode/superpowers/skills/(or installed location) - Personal:
~/.config/opencode/skills/(shadows core skills)
- Core:
Code Reuse Strategy
Extract common functionality from .codex/superpowers-codex into shared module:
1// lib/skills-core.js
2module.exports = {
3 extractFrontmatter(filePath), // Parse name + description from YAML
4 findSkillsInDir(dir, maxDepth), // Recursive SKILL.md discovery
5 findAllSkills(dirs), // Scan multiple directories
6 resolveSkillPath(skillName, dirs), // Handle shadowing (personal > core)
7 checkForUpdates(repoDir) // Git fetch/status check
8};
Skill Frontmatter Format
Current format (no when_to_use field):
1---
2name: skill-name
3description: Use when [condition] - [what it does]; [additional context]
4---
OpenCode Plugin Implementation
Custom Tools
Tool 1: use_skill
Loads a specific skill's content into the conversation (equivalent to Claude's Skill tool).
1{
2 name: 'use_skill',
3 description: 'Load and read a specific skill to guide your work',
4 schema: z.object({
5 skill_name: z.string().describe('Name of skill (e.g., "superpowers:brainstorming")')
6 }),
7 execute: async ({ skill_name }) => {
8 const { skillPath, content, frontmatter } = resolveAndReadSkill(skill_name);
9 const skillDir = path.dirname(skillPath);
10
11 return `# ${frontmatter.name}
12# ${frontmatter.description}
13# Supporting tools and docs are in ${skillDir}
14# ============================================
15
16${content}`;
17 }
18}
Tool 2: find_skills
Lists all available skills with metadata.
1{
2 name: 'find_skills',
3 description: 'List all available skills',
4 schema: z.object({}),
5 execute: async () => {
6 const skills = discoverAllSkills();
7 return skills.map(s =>
8 `${s.namespace}:${s.name}
9 ${s.description}
10 Directory: ${s.directory}
11`).join('\n');
12 }
13}
Session Startup Hook
When a new session starts (session.started event):
-
Inject using-superpowers content
- Full content of the using-superpowers skill
- Establishes mandatory workflows
-
Run find_skills automatically
- Display full list of available skills upfront
- Include skill directories for each
-
Inject tool mapping instructions
1**Tool Mapping for OpenCode:** 2When skills reference tools you don't have, substitute: 3- `TodoWrite` → `update_plan` 4- `Task` with subagents → Use OpenCode subagent system (@mention) 5- `Skill` tool → `use_skill` custom tool 6- Read, Write, Edit, Bash → Your native equivalents 7 8**Skill directories contain:** 9- Supporting scripts (run with bash) 10- Additional documentation (read with read tool) 11- Utilities specific to that skill -
Check for updates (non-blocking)
- Quick git fetch with timeout
- Notify if updates available
Plugin Structure
1// .opencode/plugin/superpowers.js
2const skillsCore = require('../../lib/skills-core');
3const path = require('path');
4const fs = require('fs');
5const { z } = require('zod');
6
7export const SuperpowersPlugin = async ({ client, directory, $ }) => {
8 const superpowersDir = path.join(process.env.HOME, '.config/opencode/superpowers');
9 const personalDir = path.join(process.env.HOME, '.config/opencode/skills');
10
11 return {
12 'session.started': async () => {
13 const usingSuperpowers = await readSkill('using-superpowers');
14 const skillsList = await findAllSkills();
15 const toolMapping = getToolMappingInstructions();
16
17 return {
18 context: `${usingSuperpowers}\n\n${skillsList}\n\n${toolMapping}`
19 };
20 },
21
22 tools: [
23 {
24 name: 'use_skill',
25 description: 'Load and read a specific skill',
26 schema: z.object({
27 skill_name: z.string()
28 }),
29 execute: async ({ skill_name }) => {
30 // Implementation using skillsCore
31 }
32 },
33 {
34 name: 'find_skills',
35 description: 'List all available skills',
36 schema: z.object({}),
37 execute: async () => {
38 // Implementation using skillsCore
39 }
40 }
41 ]
42 };
43};
File Structure
superpowers/
├── lib/
│ └── skills-core.js # NEW: Shared skill logic
├── .codex/
│ ├── superpowers-codex # UPDATED: Use skills-core
│ ├── superpowers-bootstrap.md
│ └── INSTALL.md
├── .opencode/
│ ├── plugin/
│ │ └── superpowers.js # NEW: OpenCode plugin
│ └── INSTALL.md # NEW: Installation guide
└── skills/ # Unchanged
Implementation Plan
Phase 1: Refactor Shared Core
-
Create
lib/skills-core.js- Extract frontmatter parsing from
.codex/superpowers-codex - Extract skill discovery logic
- Extract path resolution (with shadowing)
- Update to use only
nameanddescription(nowhen_to_use)
- Extract frontmatter parsing from
-
Update
.codex/superpowers-codexto use shared core- Import from
../lib/skills-core.js - Remove duplicated code
- Keep CLI wrapper logic
- Import from
-
Test Codex implementation still works
- Verify bootstrap command
- Verify use-skill command
- Verify find-skills command
Phase 2: Build OpenCode Plugin
-
Create
.opencode/plugin/superpowers.js- Import shared core from
../../lib/skills-core.js - Implement plugin function
- Define custom tools (use_skill, find_skills)
- Implement session.started hook
- Import shared core from
-
Create
.opencode/INSTALL.md- Installation instructions
- Directory setup
- Configuration guidance
-
Test OpenCode implementation
- Verify session startup bootstrap
- Verify use_skill tool works
- Verify find_skills tool works
- Verify skill directories are accessible
Phase 3: Documentation & Polish
- Update README with OpenCode support
- Add OpenCode installation to main docs
- Update RELEASE-NOTES
- Test both Codex and OpenCode work correctly
Next Steps
-
Create isolated workspace (using git worktrees)
- Branch:
feature/opencode-support
- Branch:
-
Follow TDD where applicable
- Test shared core functions
- Test skill discovery and parsing
- Integration tests for both platforms
-
Incremental implementation
- Phase 1: Refactor shared core + update Codex
- Verify Codex still works before moving on
- Phase 2: Build OpenCode plugin
- Phase 3: Documentation and polish
-
Testing strategy
- Manual testing with real OpenCode installation
- Verify skill loading, directories, scripts work
- Test both Codex and OpenCode side-by-side
- Verify tool mappings work correctly
-
PR and merge
- Create PR with complete implementation
- Test in clean environment
- Merge to main
Benefits
- Code reuse: Single source of truth for skill discovery/parsing
- Maintainability: Bug fixes apply to both platforms
- Extensibility: Easy to add future platforms (Cursor, Windsurf, etc.)
- Native integration: Uses OpenCode's plugin system properly
- Consistency: Same skill experience across all platforms