Architecture & Runtime
This chapter explains how OpenCode completes a task: config merge, agent tool selection, and how Plan/Build split work via permissions.
1. Agent Execution Loop
The TUI session is a typical tool-augmented agent loop:
Unlike pure chat, state lives in tool output and LSP diagnostics, and every tool call passes through permission gates.
2. Primary vs Subagent
Primary agents
- Switch with Tab (Build / Plan)
- Own the main conversation thread
- Configured under
agent.build,agent.plan, etc. inopencode.json
Subagents
- Delegated via the
tasktool or manually with@explore - Can spawn child sessions; navigate with arrow keys:
- Enter child: default
Leader+Down - Between children:
Right/Left - Back to parent:
Up
- Enter child: default
Intent: Explore/Scout stay read-only so the main thread is not flooded with glob/grep output; General handles parallel subtasks.
3. Configuration Merge Order
OpenCode loads config from several sources and shallow-merges (later keys win):
- Remote config (
.well-known/opencode, org defaults) - Global
~/.config/opencode/opencode.json - File pointed to by
OPENCODE_CONFIG - Project root
opencode.json(walk up to Git root) .opencode/directory (agents, commands, plugins, skills…)- Inline JSON from
OPENCODE_CONFIG_CONTENT - Managed config (enterprise, macOS, etc.)
- MDM
.mobileconfig(highest priority, user cannot override)
In practice:
- Personal prefs → global
- Team rules → project
opencode.json+ AGENTS.md - Enterprise policy → remote / managed
TUI appearance and keybindings live in tui.json, separate from opencode.json.
4. Permission System
Permissions are central—they replace older simple tools: true/false flags.
Each permission key gates a tool group:
Values:
allow— run silentlyask— prompt for approvaldeny— disabled
Plan agent defaults use ask or deny for edit, bash, etc.—“talk, don’t touch.”
Bash command rules are supported:
More specific rules override earlier * matches.
5. Multi-session
OpenCode can run multiple sessions in one project, e.g.:
- Session A: Plan a feature
- Session B: Build a bugfix
- Session C: Explore-only code search
Useful when long tasks should not interfere. Parallel Build sessions may cause Git conflicts—use branches or serialize merges.
6. Headless Mode
Good for a shared agent gateway or CI integration.
7. Privacy Model
OpenCode states it does not store your code or context (see official FAQ). Data still flows through:
- Your chosen LLM provider (cloud API)
- Local LSP / MCP processes
For compliance:
- Use offline local models where required
- Disable unnecessary
websearch - Audit MCP server permissions