中文 | English
A Chinese tutorial series on learning Coding Agent engineering architecture from the OpenCode source code.
OpenCode is an excellent open-source Coding Agent project with complete implementations of core concepts such as Agent, Tool, Permission, Skill, Session, and Provider. This repository documents the tutorials I compiled while studying the OpenCode source code, aiming to help readers understand the engineering design of a real-world Agent project rather than building a toy example from scratch.
These tutorials were primarily generated with assistance from OpenCode, Claude Code, and Codex, and have been manually reviewed. It is recommended to read them alongside the OpenCode source code.
- Users who have already used coding agents like Claude Code, Codex, or OpenCode and want to understand their internal workings
- Developers looking to implement their own controllable Coding Agent or other types of Agents
- Engineers with requirements for Agent permissions, tool calling, session management, prompt assembly, and other modules
This repo includes the OpenCode source code as a Git submodule so you can follow the tutorials while reading the actual implementation.
# Clone with submodule (recommended)
git clone --recursive https://github.com/yexia553/learn-agents-from-opencode.git
# Or if already cloned, initialize the submodule
git submodule update --init --recursive
# The OpenCode source will be available at ./opencode/
cd opencode && bun installNote: Tutorials reference source files under
opencode/packages/opencode/src/....
For full navigation, see docs/README.md.
| No. | Tutorial | Description |
|---|---|---|
| 00 | Learning Plan | Complete architecture learning roadmap |
| 01 | System Prompt | Prompt construction, Provider adaptation, environment injection |
| 02 | Permission System | Permission rules, request flow, BashArity |
| 03 | Agent System | Built-in Agents, configuration system, permission integration |
| 04 | Tool System | Tool definition, registration, execution flow |
| 05 | Iterative Info Gathering | Tool Chaining, Explore Agent, SubAgent |
| 06 | Skill System | Skill definition, discovery mechanism, tool integration |
| 07 | Session System | Session management, message flow, context compression |
| 08 | Provider System | Multi-model adaptation, SDK initialization, cost calculation |
Note: The tutorial documents below are currently available in Chinese only. English translations will be added progressively.
.
├── docs/
│ ├── README.md
│ ├── 00-learning-plan.md
│ └── tutorials/
│ ├── 01-system-prompt.md
│ ├── 02-permission-system.md
│ ├── 03-agent-system.md
│ ├── 04-tool-system.md
│ ├── 05-iterative-info-gathering.md
│ ├── 06-skill-system.md
│ ├── 07-session-system.md
│ └── 08-provider-system.md
├── opencode/ # OpenCode source code (submodule)
│ └── packages/
│ └── opencode/
│ └── src/
├── .github/
│ ├── ISSUE_TEMPLATE/
│ ├── workflows/
│ └── pull_request_template.md
├── CONTRIBUTING.md
├── CODE_OF_CONDUCT.md
├── SECURITY.md
├── CHANGELOG.md
├── LICENSE
├── README.md
└── README.zh.md
Contributions via issues or pull requests are welcome. Please read CONTRIBUTING.md first.
This project is licensed under the MIT License.