OpenCode: OpenCode First Use

Last updated: 2026-08-31

After installation and configuration, let's start using OpenCode for the first time.

1. What You Will Learn


2. Start OpenCode

Navigate to your project directory and run:

BASH
cd my-project
opencode

You'll see the TUI interface with an input box at the bottom and conversation area above.


3. First Conversation

In the input box, type:

TEXT 📖 Display only
Summarize this project's structure

OpenCode will read project files and provide a structural overview.


4. Reference Files for Analysis

Use @ to reference project files:

TEXT 📖 Display only
How is authentication implemented in this project? Check @src/auth/index.ts

Features:


5. Let AI Modify Code

Give a modification instruction:

TEXT 📖 Display only
Replace all var declarations in src/utils/format.ts with const or let

OpenCode will:

  1. Read the file content
  2. Identify all var declarations
  3. Determine whether to use const or let based on context
  4. Directly modify the file

6. Execute Commands

Use the ! prefix to execute Shell commands:

TEXT 📖 Display only
!npm test

Results are automatically added to the conversation context for AI follow-up.


7. Undo Operations

If AI modifications are not as expected:

TEXT 📖 Display only
/undo

This will:

Redo:

TEXT 📖 Display only
/redo

Important: Undo relies on Git. Ensure your project uses Git version control.


8. Switch Models

If the current model isn't performing well:

TEXT 📖 Display only
/model

Select another model from the list.


9. Session Management

New session: /new View sessions: /sessions Continue last session: opencode --continue


10. Exit OpenCode

TEXT 📖 Display only
/exit

Or use shortcut Ctrl + X → Q.


❓ FAQ

Q Which model should I use first?
A Try OpenCode Zen's free models first, then switch to stronger paid models once the workflow is confirmed.
Q AI modified code incorrectly—what to do?
A Immediately use /undo. Always git commit before important operations so you can revert via Git even if undo fails.
Q Non-interactive mode?
A Use opencode run "your question" to get results directly without entering TUI. Great for quick questions and script integration.

📖 Summary


📝 Exercises

  1. Basic: Start OpenCode and have it analyze your current project structure.

  2. Intermediate: Have OpenCode modify a file, then undo the change with /undo.

  3. Advanced: Use non-interactive mode opencode run for code analysis and redirect output to a file.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏