YouTip LogoYouTip

Opencode First Usage

After installing Claude Code and configuring the API, we can start using it.

First, navigate to your 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 directory.

To exit OpenCode, use the following command:

/exit

Next, we'll use a simple example project to complete the first usage.

Create an example project:

mkdir opencode-tutorial-test cd opencode-tutorial-test

Then run OpenCode:

opencode

Run the following command to initialize:

/init

Image 1

Create a simple file:

touch main.py

Write the following content:

def add(a, b): return a + b

Let OpenCode Explain the Code

Input:

Explain what the main.py file is doing, in a way that a beginner can understand

OpenCode will read the code in the current directory and provide an explanation.

Image 2

Let OpenCode Help You Modify Code

Continue in the OpenCode session and input:

Add type annotations to this function and include basic error handling

OpenCode will provide modification suggestions, usually including:

  • Modified code
  • Explanation of the changes

Image 3

The @ Symbol

Using @ allows you to quickly search and reference files in the project without manually copying code, which is suitable for understanding unfamiliar projects.

For example, @main.py can be used to reference this file:

Image 4


OpenCode's Basic Interaction Methods

Common Command Types

You can categorize commands for Claude Code into three types:

1. Explanation Type

Explain this code / Why is this function written this way

2. Modification Type

Help me refactor this function / Split it into multiple smaller functions

3. Generation Type

Add a test case / Add logging output

A simple but useful command template:

Without changing existing behavior, help me optimize the readability of the XXX file, and explain what changes you made.


Adding New Features (Recommended Workflow)

For complex requirements, it is recommended to use a three-step method:

  • First, make a plan
  • Then, optimize the plan
  • Finally, execute and implement

1. Make a Plan (Plan Mode)

Press the Tab key to switch to plan mode:

Image 5

At this point, OpenCode will not modify code, it will only provide an implementation plan.

Example Requirement

When a user deletes a note, we want to mark it as deleted in the database. Then add a new page to display recently deleted notes. On this page, users can restore notes or permanently delete them.

Note:

  • The more detailed the description, the more accurate the result
  • You can describe requirements as if communicating with a colleague

2. Optimize and Iterate the Plan

After OpenCode provides a plan, you can continue to supplement:

We want this new page to adopt a design we used before. Please refer to this image and implement it in that style.

Tips:

  • You can drag and drop images into the terminal as reference
  • You can supplement business rules, UI requirements, etc.

The essence is doing a design review with AI.

3. Execute Implementation (Build Mode)

Press Tab again to switch back to execution mode:

Then input:

Great, start implementing according to this plan.

OpenCode will:

  • Create/modify code
  • Update related files
  • Execute necessary commands

Direct Modification (Suitable for Simple Requirements)

For simple tasks, you can skip the planning and execute directly:

Add authentication logic to the /settings route. Refer to the implementation in @packages/functions/src/notes.ts, and implement the same logic in @packages/functions/src/settings.ts.

Suggestions:

  • Provide reference code paths
  • Explain the desired outcome

Undo and Redo

If the modification result is not as expected, you can use:

Undo Modification

/undo

Function:

  • Rollback code changes
  • Restore previous conversation state

Redo Modification

/redo

Tips:

  • /undo can be used multiple times
  • Suitable for trying different solutions repeatedly

Share Conversation

You can share the current session with your team:

/share

After execution:

  • Generate a share link
  • Automatically copy to clipboard

Note:

  • Conversations are not automatically shared by default

Usage Tips

1. Treat It as a Junior Developer

  • Explain requirements clearly
  • Provide context
  • Don't be vague

2. Prioritize Plan Mode

  • Avoid incorrect modifications
  • Review the plan before executing

3. Use File References Frequently

  • @path can significantly improve accuracy

4. Iterate in Small Steps

  • Don't make requirements too complex at once
  • Break down tasks and complete them gradually

The essence of using OpenCode is: driving the development process through conversation, rather than writing code by hand.

← Opencode TuiOpencode Install β†’