OpenCode First Use
After installing Claude Code and configuring the API, we can get started.
You can first enter the project directory:
cd /path/to/project
Then run OpenCode:
opencode
Run the following command to initialize OpenCode for the project:
/init
OpenCode will analyze your project and create an AGENTS.md file in the project root.
To exit OpenCode, use the following command:
/exit
Next, we'll complete the first use with the simplest example project.
Create a sample project:
mkdir opencode-runoob-test
cd opencode-runoob-test
Then run OpenCode:
opencode
Run the following command to initialize:
/init

Create a simple file:
touch main.py
Write the following content:
def add(a, b):
return a + b
Have OpenCode explain the code
Inputs:
解释 main.py 这个文件在做什么,用新手能理解的方式说明
OpenCode will read the code in the current directory and give an explanation.

Have OpenCode help you modify code
Continue typing in the OpenCode session:
给这个函数增加类型注解,并补充基本的错误处理
OpenCode will give modification suggestions, usually including:
- The modified code
- Explanation of the reasons for the changes

@ sign before positive numbers
Use @ Quickly search and reference files in the project without manually copying code — suitable for understanding unfamiliar projects.
For example, @main.py can be associated with this file:

Basic interaction methods of OpenCode
Common instruction types
You can divide instructions to Claude Code into three categories:
1. Explanatory
解释这段代码
这个函数为什么这么写
** 2. Modification**
帮我重构这个函数
拆分成多个小函数
3. Generative
补一个测试用例
增加日志输出
A simple but useful instruction template:
在不改变现有行为的前提下,
帮我优化 XXX 文件的可读性,
并说明你做了哪些修改。
Adding new features (recommended process)
For complex requirements, a three-step approach is recommended:
- First make a plan
- Then refine the approach
- Finally execute the implementation
1. Make a plan (Plan mode)
Press Tab key to switch to plan mode:
At this point OpenCode will not modify code, only giving an implementation plan.
Example requirement
当用户删除一条笔记时,我们希望在数据库中将其标记为已删除。
然后新增一个页面,用于展示最近删除的笔记。
在该页面中,用户可以恢复笔记或彻底删除笔记。
Explanation:
- The more detailed the description, the more accurate the result
- You can describe requirements just like communicating with a colleague
2. Refine and iterate on the plan
After OpenCode gives a plan, you can continue adding:
我们希望这个新页面采用之前用过的一套设计。
请参考这张图片,并按该风格实现。
Tips:
- You can drag an image into the terminal as a reference
- You can add business rules, UI requirements, etc.
Essentially, it's doing a design review together with AI.
3. Execute implementation (Build mode)
Press again Tab to switch back to execution mode:
Then enter:
很好,按照这个方案开始实现吧。
OpenCode will:
- Create/modify code
- Update related files
- Execute necessary commands
Direct modification (suitable for simple requirements)
For simple tasks, you can skip planning and execute directly:
给 /settings 路由添加认证逻辑。
参考 @packages/functions/src/notes.ts 中的实现方式,
并在 @packages/functions/src/settings.ts 中实现相同逻辑。
Note:
- Provide reference code paths
- Describe the desired outcome
Undo and redo
If the modification result is not as expected, you can use:
Undo changes
/undo
Function:
- Roll back code changes
- Restore the previous conversation state
Redo changes
/redo
Tip:
- /undo can be used multiple times
- Suitable for repeatedly trying different approaches
Share conversation
You can share the current session with your team:
/share
After executing:
- Generate a share link
- Automatically copied to the clipboard
Note:
- Conversations are not shared automatically by default
Usage tips
1. Treat it as a junior engineer
- State requirements clearly
- Provide context
- Avoid vague expressions
2. Prefer plan mode
- Avoid erroneous modifications
- Review the plan before executing
3. Use file references more often
- @paths can greatly improve accuracy
4. Iterate in small steps
- Don't take on overly complex requirements at once
- Break tasks into steps and complete them gradually
The essence of using OpenCode is: drive the development process through conversation, not by writing code by hand.