Open-Source AI Coding Agent – OpenCode

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:

  1. Primary Agents – User-facing, switchable via Tab key, there are build and plan agents
  2. 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:

  1. opencode.json – JSON configuration
  2. 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

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.