Chapter 2: Architecture and Agent Loop

April 13, 2026 ยท View on GitHub

Welcome to Chapter 2: Architecture and Agent Loop. In this part of OpenCode Tutorial: Open-Source Terminal Coding Agent at Scale, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.

OpenCode is built around an interactive coding-agent loop optimized for terminal-native development.

Core Loop

flowchart LR
    A[Task Input] --> B[Reasoning]
    B --> C[Tool Selection]
    C --> D[Execution]
    D --> E[Result Synthesis]
    E --> F[Next Step or Finish]

Key Components

ComponentRole
client UIterminal interaction and control
agent runtimeplanning + execution orchestration
tool systemfile, shell, and search operations
provider layermodel routing and inference integration

Why This Matters

Understanding this loop helps you tune OpenCode behavior without relying on trial and error.

Source References

Summary

You now have the architecture mental model required for safe customization.

Next: Chapter 3: Model and Provider Routing

How These Components Connect

flowchart TD
    A[User Input] --> B[OpenCode Client TUI]
    B --> C[Agent Runtime]
    C --> D[Planning Phase]
    D --> E[Tool Execution]
    E --> F[File Edits / Shell Cmds]
    F --> G[Result Synthesis]
    G --> B