Skip to content

OpenCode Internals

Quick reference for understanding OpenCode's internal architecture. Designed for building frameworks on top of OpenCode.

Core Concepts

ConceptWhat It IsLocation
SessionA conversation with message historySQLite DB
ProjectA workspace with worktreeSQLite DB
AgentExecution mode with permissionsConfig + Code
SkillReusable capability module.opencode/skill/*/SKILL.md
ToolAtomic operation (read, write, bash)packages/opencode/src/tool/
PartMessage component (text, tool call, file)SQLite DB

Directory Structure

text
~/.local/share/opencode/          # Data directory
├── opencode.db                   # SQLite database (sessions, messages, parts)
├── projects/                     # Project-specific data
└── cache/                        # Cached skills, models

.opencode/                        # Project config directory
├── opencode.json{,c}             # Main config file
├── agent/                        # Custom agents
│   └── *.md                      # Agent definitions
├── skill/                        # Custom skills
│   └── */SKILL.md                # Skill definitions
├── command/                      # Slash commands
│   └── *.md                      # Command templates
├── tool/                         # Custom tools
│   └── *.{ts,js}                 # Tool implementations
└── plugin/                       # Plugins
    └── *.{ts,js}                 # Plugin code

Key Files

FilePurpose
packages/opencode/src/storage/schema.tsDatabase schema exports
packages/opencode/src/session/session.sql.tsSession/Message/Part tables
packages/opencode/src/project/project.sql.tsProject table
packages/opencode/src/tool/registry.tsTool registration
packages/opencode/src/skill/skill.tsSkill discovery/loading
packages/opencode/src/agent/agent.tsAgent definitions
packages/opencode/src/config/config.tsConfig loading

Data Flow

text
User Input → Intent Classification → Agent Selection → Tool Execution → Response
                    ↓                        ↓
              Load Context            Check Permissions
                    ↓                        ↓
              Load Skill              Execute Tool

Quick Reference

Database Location

text
~/.local/share/opencode/opencode.db

Config Precedence (low → high)

  1. Remote .well-known/opencode
  2. Global ~/.config/opencode/opencode.json
  3. Custom config (OPENCODE_CONFIG)
  4. Project opencode.json
  5. .opencode/ directory configs
  6. Inline config (OPENCODE_CONFIG_CONTENT)
  7. Managed config (enterprise)

Skill Discovery Paths

  1. .claude/skills/**/SKILL.md
  2. .agents/skills/**/SKILL.md
  3. .opencode/skill/**/SKILL.md
  4. Config skills.paths
  5. Config skills.urls (remote)

Documentation Sections

Released under the MIT License.