Learn OpenCode
Understand AI coding agent design from scratch, one mechanism at a time
The Core Pattern
Every AI coding agent shares the same loop: call the model, execute tools, feed results back. Production systems add policy, permissions, and lifecycle layers on top.
System Architecture
Five layers compose into a complete AI coding agent. Each layer builds on the one below it.
Architectural Layers
Five orthogonal concerns that compose into a complete agent
Tools & Execution
4 sessionsThe smallest useful agent is a loop that calls the model, runs tools, and feeds results back.
The loop stays stable while capabilities register into a dispatch table.
Dangerous actions need a harness decision point before the shell runs.
Cross-cutting behavior belongs around the loop, not tangled inside it.
Planning & Control
3 sessionsExtensibility
1 sessionsConcurrency
1 sessionsComparison: Claude Code
Both agents share the same core loop architecture, differing in policy layers
| Mechanism | Claude Code | OpenCode |
|---|---|---|
| Core Loop | while(model responds) | while(tool_use) via Effect/Stream |
| Tool Dispatch | Function calling API | TOOL_MAP registry + Schema |
| Permission Model | User confirmation prompt | Wildcard patterns · allow/deny/ask · Deferred |
| Extensibility | CLI flags + env vars | Plugin SDK · Hooks API · Skill system |
| Subagents | @mentions | Named agents · clean context · task_id resume |
| Skill System | Custom instructions | SKILL.md · priority chain · YAML frontmatter |
| Config | CLAUDE.md + env | opencode.jsonc · deepMerge · JSON Schema |
Reference: learn.shareai.run — Claude Code learning site
Learning Path
10 progressive sessions, from a simple loop to a complete agent system
The Agent Loop
The smallest useful agent is a loop that calls the model, runs tools, and feeds results back.
Tool Dispatch
The loop stays stable while capabilities register into a dispatch table.
Permission Gate
Dangerous actions need a harness decision point before the shell runs.
Hook System
Cross-cutting behavior belongs around the loop, not tangled inside it.
Task Categories
Routing tasks by category decouples intent from implementation.
Subagent
Subagents give each subtask a clean context while preserving the main thread.
Skill Loading
Inject specialized knowledge only when the task actually needs it.
Plugin SDK
A well-designed hook system makes the agent infinitely extensible.
Background Tasks
The agent can keep reasoning while slow work completes elsewhere.
Config & Session
A single config file controls the entire agent harness behavior.