The OpenCode Framework uses OpenCode as its agent orchestration layer. The core framework resides in the .opencode/ directory.
| Agent | Purpose |
|---|---|
analyze |
Research, investigation, and audits |
design |
Architecture and system design |
plan |
Strategy and planning |
build |
TCR implementation discipline |
release |
Publishing and versioning |
| Subagent | Purpose |
|---|---|
investigator |
Codebase architectural analysis |
scout |
Web research (parallelizable) |
tester |
Hypothesis validation |
drafter |
Content creation |
critic |
Prose review |
general |
General-purpose coding tasks |
lit-commands |
Literate command processing |
Commands define structured, multi-phase workflows that automate the development lifecycle:
| Command | Phase | Description |
|---|---|---|
/research |
Discovery | Deep-dive exploration producing Markdown reports |
/audit |
Discovery | Codebase audit for tech debt and architecture |
/debug |
Discovery | Scientific, hypothesis-driven forensic investigation |
/investigate |
Discovery | Root cause analysis |
/plan |
Strategy | Mandatory bridge to execution plans |
/build |
Execution | TCR loop implementation |
/fix |
Execution | Bug fix with regression prevention |
/draft |
Execution | Content creation into finished documents |
/onboard |
All | Project orientation for new developers |
/scaffold |
All | Project initialization with modern tooling |
/commit |
Shipping | Conventional commits with grouped changes |
/release |
Shipping | Version bump, changelog, git tagging |
/todo |
All | Task management |
/note |
All | Journal entry creation |
/sandbox |
All | Docker sandbox setup and management |
The framework enforces a strict architectural boundary between discovering what to do and actually doing it. Data flows unidirectionally:
- Discovery:
/research,/audit,/debugcreate read-only artifacts in.knowledge/notes/ - Strategy:
/plangenerates actionable roadmaps in.knowledge/plans/ - Execution:
/build(code) or/draft(prose) perform actual work
The /build command enforces a high-discipline development lifecycle through a strict TCR loop:
- Pre-flight Verification: Ensures a clean
mainbranch and passing tests. - Isolation: All work occurs on an auto-generated, kebab-case feature branch.
- The Loop (Red-Green-Verify):
- Red: A failing test is written to define the step's goal.
- Green: Minimal code is written to pass the test.
- Verify: If the test fails, the agent is allowed one quick fix. If it fails again, the change is automatically reverted (
git checkout .), preserving the last known stable state.
- Integration: Upon completion, the feature branch is merged, the roadmap is updated, and the branch is deleted.
Literate Commands are Markdown files that define guided, multi-step workflows with embedded executable code blocks. They enable structured automation with variable collection, conditional logic, and automated script execution.
A literate command is a .md file with YAML frontmatter that defines:
- Variables: Named inputs with types and prompts
- Conditions: Branching logic based on variable values
- Steps: Executable blocks with descriptions
---
literate: true
variables:
- name: project_name
type: string
prompt: "What is your project name?"
- name: use_docker
type: boolean
prompt: "Enable Docker support?"
conditions:
use_docker:
true: include_docker
false: skip_docker
---Literate commands execute in four phases:
- Parse: Read and validate the Markdown file, extract frontmatter
- Substitute: Collect variables from user, replace placeholders
- Route: Evaluate conditions, determine which steps to execute
- Execute: Run the selected steps in sequence
---
literate: true
variables:
- name: feature
type: string
prompt: "Feature name?"
---
# Feature Implementation Workflow
## Step 1: Create Branch
Run: `git checkout -b feature/{{feature}}`
## Step 2: Implement Feature
{{implementation_steps}}Tasks are managed via the todowrite tool within agent sessions:
- Visible task list for both user and agent
- State lifecycle: pending → in_progress → completed
- Priority levels: high, medium, low
Use the /todo command or todowrite tool directly to manage tasks.
The /debug command implements a principled approach to problem-solving:
- Status & Context Analysis: Gather error logs, stack traces, and recent changes.
- Hypothesis Formulation: Propose a specific root cause hypothesis.
- Isolated Testing: Create a temporary diagnostic branch (
debug/hyp-*). - RCA Synthesis: Generate a Root Cause Analysis report.
The Sandbox Plugin provides Docker-based isolation for tool execution. It ensures that potentially dangerous operations run in a controlled environment without affecting the host system.
When enabled, commands are executed inside a Docker container rather than directly on the host:
- Setup: The
/sandboxcommand initializes a Docker image and volume mounts - Routing: Mode-specific commands can be configured to run in sandbox
- Execution: Commands execute inside the container with limited permissions
- Cleanup: Container is removed after execution
.opencode/
├── sandbox/
│ ├── sandbox.sh # Sandbox management script
│ ├── dockerfile # Container definition
│ └── dockerfile # Alternative container definition
└── plugins/
└── sandbox.js # Sandbox plugin implementation
# Setup the sandbox environment
opencode /sandbox setup
# Run commands in sandbox mode
opencode --sandbox [command]
# Teardown the sandbox
opencode /sandbox teardownUse the sandbox for:
- Running untrusted code
- Testing potentially destructive operations
- Isolated development environments
- Reproducible build environments
The framework uses a timestamp-based git hook to enforce journaling:
- Hook location:
.opencode/tools/pre-commit.py - Install:
make install-hooks - Rule: Journal entry timestamp must be newer than file modifications
.opencode/ # Framework runtime (agents, commands, tools)
├── agents/ # Primary agent definitions
│ └── subagents/ # Specialized subagents
├── commands/ # High-level commands
├── tools/ # Utilities (pre-commit.py, etc.)
├── style-guide.md # Prose style rules
└── README.md # Framework self-documentation
.knowledge/
├── plans/ # Saved execution plans
├── notes/ # Research artifacts and analysis notes
├── log/ # Daily journal entries (YYYY-MM-DD.yaml)
└── drafts/ # Content drafts
tasks.yaml # Project roadmap (managed by task tool)
- CLI Engine: OpenCode (Node.js-based agent framework)
- Core Automation: Python (Scripts in
.opencode/tools/) - Validation & Health: Make (source of truth for builds/tests)
- State & Versioning: Git
- Documentation: Markdown (journals, plans, reports)
Next: See Development & Contribution for the rules of the road.