For the complete documentation index, see llms.txt. This page is also available as Markdown.

Deep Dive into OpenCode — Table of Contents and Outline

Model: claude-opus-4-6 (anthropic/claude-opus-4-6) Tools: OpenCode Generated: 2025-02-17 GitHub: https://github.com/0xtresser/OpenCode-Book


Language

中文版本

Book Structure Overview

As of OpenCode version 1.2.5.

This book is divided into five parts and eighteen chapters, systematically covering OpenCode's architecture design and implementation principles — from foundational concepts to source code analysis, from core mechanisms to ecosystem extensions, and from theory to practice.

Part
Chapter Range
Core Topics
Est. Word Count

Part I: Foundations

Chapters 1–3

Background, Setup, Overall Architecture

~15,000 words

Part II: Core Architecture

Chapters 4–8

Session, Tool, Agent, Provider, MCP

~30,000 words

Part III: Key Mechanisms

Chapters 9–12

Permissions, Snapshot, Event Bus, TUI

~20,000 words

Part IV: Ecosystem

Chapters 13–16

Plugin System, oh-my-opencode, IDE Extensions

~20,000 words

Part V: Practice

Chapters 17–18

Hands-on Labs, Design Philosophy & Future Outlook

~15,000 words


Part I: Foundations

Chapter 1: The Era of AI Programming Assistants

Guiding readers to understand the technical background and industry context behind OpenCode's creation.


Chapter 2: Project Structure and Development Environment

Setting up the development environment and building a macro-level understanding of the project structure.


Chapter 3: Overall Architecture Design

Understanding OpenCode's architectural layers and data flow from a global perspective.


Part II: Core Architecture

Chapter 4: Session System

The session is OpenCode's core abstraction — understanding it means understanding the entire conversation management mechanism.


Chapter 5: Tool System

Tools are the only way Agents interact with the external world.


Chapter 6: Agent System

An Agent is the abstraction that gives an LLM its "personality" and "capability boundaries."


Chapter 7: Provider (Multi-Model Adaptation Layer)

Understanding how OpenCode uniformly interfaces with 20+ LLM Providers.


Chapter 8: MCP (Model Context Protocol)

MCP is the core protocol for OpenCode to connect with external tool ecosystems.


Part III: Key Mechanisms

Chapter 9: Permission Control System

Security is the lifeline of AI Agents — deeply understanding how OpenCode controls Agent behavior boundaries.


Chapter 10: Snapshot and File System

Understanding how OpenCode safely manages file changes and rollbacks.


Chapter 11: Event Bus and Scheduler

Understanding the core mechanism for decoupled inter-module communication.


Chapter 12: Command Line Interface and TUI

Understanding OpenCode's frontend implementation from a user interaction perspective.


Part IV: Ecosystem

Chapter 13: Plugin System

Understanding the core of OpenCode's extensibility — the Plugin architecture.


Chapter 14: Skill System

Skills are modular extension units for Agent capabilities.


Chapter 15: oh-my-opencode Deep Dive

As the most complex third-party Plugin in the OpenCode ecosystem, oh-my-opencode demonstrates the full power of the Plugin system.


Chapter 16: IDE Extensions and ACP

Understanding how OpenCode integrates with various IDEs.


Part V: Practice

Chapter 17: Hands-on Labs

Through five progressive experiments, build key components of an AI programming assistant from scratch.


Chapter 18: Design Philosophy, Best Practices, and Future Outlook

Summarizing the entire book, distilling design wisdom, and looking ahead to future directions.


Appendices

Appendix A: OpenCode Configuration Reference Manual

  • Complete list and description of opencode.json configuration options

Appendix B: oh-my-opencode Configuration Reference Manual

  • Complete list and description of oh-my-opencode.json configuration options

Appendix C: Built-in Tool API Reference

  • Parameters, return values, and permission requirements for each built-in tool

Appendix D: MCP Protocol Quick Reference

  • Core concepts, transport methods, message formats

Appendix E: Glossary

  • Definitions of terms: LLM, Token, Context Window, Function Calling, Agent, MCP, ACP, LSP, AST, SSE, Monorepo, TUI, etc.

  • Official documentation links

  • Related papers and articles

  • Recommended open-source projects


Source Code File Index

Quick reference table for key source code files covered in this book

Chapter
Key Files

Chapter 4: Session

session/index.ts, session/processor.ts, session/llm.ts, session/compaction.ts, session/system.ts, session/instruction.ts, session/prompt.ts, session/message-v2.ts, session/retry.ts, session/revert.ts, session/status.ts, session/summary.ts, session/todo.ts

Chapter 5: Tool

tool/tool.ts, tool/registry.ts, tool/truncation.ts, tool/bash.ts, tool/edit.ts, tool/read.ts, tool/write.ts, tool/glob.ts, tool/grep.ts, tool/task.ts, tool/lsp.ts, tool/webfetch.ts, tool/websearch.ts, tool/todo.ts, tool/skill.ts, tool/plan.ts, tool/batch.ts, tool/question.ts, tool/apply_patch.ts, tool/multiedit.ts, tool/codesearch.ts

Chapter 6: Agent

agent/agent.ts, agent/prompt/*.txt, session/prompt/*.txt

Chapter 7: Provider

provider/provider.ts, provider/transform.ts, provider/models.ts, provider/auth.ts, provider/error.ts, provider/sdk/copilot/

Chapter 8: MCP

mcp/index.ts, mcp/auth.ts, mcp/oauth-provider.ts, mcp/oauth-callback.ts

Chapter 9: Permission

permission/next.ts, permission/index.ts, permission/arity.ts

Chapter 10: Snapshot

snapshot/index.ts, file/index.ts, file/ignore.ts, file/ripgrep.ts, file/watcher.ts, patch/index.ts, worktree/index.ts

Chapter 11: Bus

bus/index.ts, bus/bus-event.ts, bus/global.ts, scheduler/index.ts

Chapter 12: CLI/TUI

cli/bootstrap.ts, cli/cmd/*.ts, cli/cmd/tui/app.tsx, cli/cmd/tui/component/, cli/cmd/tui/routes/

Chapter 13: Plugin

plugin/index.ts, plugin/codex.ts, plugin/copilot.ts

Chapter 14: Skill

skill/index.ts, skill/skill.ts, skill/discovery.ts, command/index.ts

Chapter 15: oh-my-opencode

oh-my-opencode/src/index.ts, agents/*.ts, tools/*, hooks/*, features/*, plugin/*, mcp/*, config/*

Chapter 16: IDE/ACP

acp/agent.ts, acp/session.ts, acp/types.ts, sdks/vscode/, extensions/zed/

Last updated