OpenCode is a an open-source AI coding agent – essentially a terminal-based AI assistant for software development. It’s comparable to Claude Code, but open-sourced and provide-agnostic. It’s been attracting lots of community adoption now.
Core Architecture Pattern: OpenCode uses a hierarchical agent model with two tiers:
- Primary Agents – User-facing, switchable via Tab key, there are build and plan agents
- Subagents – Specialized workers invoked by primary agents or via @ mentions, there are general and explore subagents
Agents interact with the codebase through tools – discrete capabilities the LLM can invoke:
File Operations include read, write, edit and patch; Search/Discovery tools include grep(ripgrep), glob, list; Execution tools include bash, lsp, and webfetch.
Workflow Tools: todowrite, todoread, question, skill
OpenCode implements a three-tier permission system:
- allow – Execute without confirmation
- ask – Prompt user before execution
- deny – Block entirely This is combined with glob pattern matching for fine-grained control (e.g., “bash(git *)”: “allow” permits git commands while requiring approval for others).
Agents are defined in two places:
- opencode.json – JSON configuration
- Markdown files in ~/.config/opencode/agents/ (global) or .opencode/agents/ (project)
OpenCode has a Hook-Based Architecture: Plugins subscribe to events across the agent lifecycle. This is the Observer pattern – allowing extensions without modifying core code.
- tool.execute.before / tool.execute.after – Intercept tool calls
- session.created / session.idle – Track session state
- message.updated – React to conversation changes