OpenCode Getting Started Tutorial
OpenCode is an open-source AI coding agent that supports interacting with AI in the terminal (Terminal), desktop apps, and mainstream IDEs (such as VS Code) to complete code-related tasks.
OpenCode can help us understand codebases, write new features, refactor code, fix bugs, and more, greatly improving development efficiency.
OpenCode is similar to Claude's Code mode or Cursor's Agent feature, but fully open source, privacy-first, supporting multiple large language models (LLM), with an emphasis on the terminal experience.
OpenCode supports 75+ model providers, with built-in free models like GLM-4.7 and MiniMax M2.1, can connect to commercial models such as OpenAI, Anthropic, and Google, and can also configure local models (such as Llama 3), adapting on demand to different scenarios like lightweight scripts and complex architectures.
Full OpenCode tutorial reference:https://www.runoob.com/opencode/opencode-tutorial.html

Key characteristics
Two built-in Agent modes:
- **Build mode:** Full permissions, can directly edit files and execute commands.
- **Plan mode:** Read-only planning, edits denied by default, requires confirmation.
**Toolset:** bash execution, file read/write, grep search, LSP diagnostics, etc.
**Context awareness:** Automatically analyzes project structure and generates an AGENTS.md guide.
**Sharing and collaboration:** One-click generation of session share links.
Install OpenCode
OpenCode supports multi-platform installation on macOS / Windows / Linux.
The universal one-click install script, this is the simplest method:
curl -fsSL https://opencode.ai/install | bash
After installation, you should be able to run from the command line:
opencode --version
If the output shows version number information like 1.1.19, the installation succeeded.
Package manager installation
macOS / Linux
brew install opencode
or:
npm install -g opencode-ai
Windows
choco install opencode
or:
scoop bucket add extras
scoop install extras/opencode
Arch Linux
paru -S opencode-bin
OpenCode runs in the terminal; we can use the default system terminal or some good modern terminal tools:
Desktop app
OpenCode also provides a desktop application, which can be obtained directly from the release page or opencode.ai/download for download.
| System platform | Download installer |
|---|---|
| macOS (Apple silicon) | opencode-desktop-darwin-aarch64.dmg |
| macOS (Intel chip) | opencode-desktop-darwin-x64.dmg |
| Windows | opencode-desktop-windows-x64.exe |
| Linux | .deb, .rpm or AppImage format |
Launch and use
Starting OpenCode only requires entering the launch command in the terminal:
opencode
The first launch will guide you through basic configuration:
- **Model selection:** Displays a list of available models by default; you can directly select free models labeled Free (such as MiniMax M2.1, GLM-4.7) and use them without an API Key.
- **Login options:** You can skip login and configure an API Key later when connecting commercial models, or log in with a Claude Code Pro account to call dedicated models.
After a successful launch you enter the TUI interface and can start using core features.
We can enter /models in the terminal to view available free models:

In the popup view, those with Free on the right are the free ones:

Configure API key and models
If you connect an AI provider's API key, such as OpenAI or Anthropic Claude, run:
opencode auth login
Or after starting in the terminal, enter:
/connect
Select a model. Follow the prompts to log in and paste your API Key.

You can also use the Zen A model collection (high-quality models officially recommended and tested by OpenCode), saving you the trouble of managing multiple external accounts.
If you no longer want to use it, you can exit with the following command:
/exit
Basic Usage
Start OpenCode
Enter the project directory you want to work on:
cd /path/to/your/project
opencode
For example, we create the directory opencode-runoob-test:
mkdir opencode-runoob-test
cd opencode-runoob-test
Then execute the command:
opencode
If there are permission issues, you can use:
sudo opencode
This opens OpenCode's terminal interactive interface (TUI).
Project initialization
In the OpenCode interface, run:
/init

This generates a .opencode/ folder for storing the project's vectorized index and custom instructions.
It scans the code structure of the current directory and generates an AGENTS.md file to record project information.

In the opencode-runoob-test directory you can see the AGENTS.md file:

Then we describe your requirements in natural language to start a task:
在当前目录下创建一个登录页面
Next the LLM will start thinking and create a login page:

Generated files:

Ask to explain code
You can ask OpenCode about codebase details directly in natural language:
What features does the file @index.html contain
Here @ is used to reference file paths in the project.

Daily interaction
- Ask directly: for example, 'Explain the authentication logic in src/main.ts'.
- Add features: describe requirements, e.g., 'Add a user registration API with email verification'.
- Switch modes: press the Tab key to switch Plan/Build modes (Plan is safer, used for planning).
- Undo changes: /undo
- Redo: /redo
- Share session: /share
Interactive mode (scripted):
opencode -p "修复 login 函数中的 bug"
Built-in tools introduction
OpenCode's AI Agent operates on the codebase through the following tools (can be opencode.json used to control permissions: allow/deny/ask):
- bash: Execute shell commands (e.g.,
git status,npm test). - write/edit/patch: Create/modify/patch files.
- read: Read file contents (supports line ranges).
- grep/glob/list: Search and list files (respects .gitignore).
- webfetch: Fetch web page content (check docs).
- lsp(Experimental): code jump, hover hints, etc.
- question: Ask you for confirmation.
- todo: Maintain task lists.
Custom tools and MCP (Model Context Protocol) servers support extensions (such as connecting to databases).
Advanced usage
- Custom commands: In
~/.config/opencode/commands/Create a Markdown file, such asprime-context.md, with preloaded instructions as content. - Themes and keybindings: Customize appearance and shortcuts in settings.
- Multi-session: Run multiple Agents simultaneously for different tasks.
- IDE integration: Currently supports VS Code extension (search OpenCode extension), or remote control via client/server architecture.
- Permission Control: Set for tools in the config file
askto manually confirm sensitive operations.
Create a simple Node.js API
- Create a new directory:
mkdir my-api && cd my-api - Initialize:
npm init -y - Start OpenCode:
opencode - Input
/init - Ask: create an Express.js service supporting the /hello route that returns JSON { message: 'Hello World' }, and add a README.
oh-my-opencode
oh-my-opencode is a powerful plugin/extension layer designed for OpenCode. It upgrades a single AI agent into a multi-agent collaborative team, providing out-of-the-box advanced features.
GitHub repository:https://github.com/code-yeongyu/oh-my-opencode
Core highlights include:
- Sisyphus Main agent: responsible for continuously executing complex tasks until completion.
- Supports running specialized sub-agents in parallel (such as Oracle the prophet, Librarian the documentation expert, Frontend Engineer, and Explore the explorer).
- Built-in LSP/AST tools (code refactoring), MCP (model-invocation plugins such as search, document retrieval), and a hook system (25+ event triggers).
- Multi-model scheduling: automatically assigns tasks to the most suitable model (e.g., Gemini for frontend, Claude for planning).
- Keyword-triggered full automation (e.g.,
ultraworkorulw), supports background tasks, to-do enforcement, context injection, etc. - Fully compatible with Claude Code workflows, emphasizing high performance, automation, and customizability.
Installation
It is recommended to let OpenCode complete the installation automatically; copy the following prompt and paste it into your OpenCode dialog:
按照以下说明安装和配置 oh-my-opencode:
https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/refs/heads/master/docs/guide/installation.md
After installation it works out of the box by default, with no extra configuration needed to experience most features.
Basic trigger
Add the keyword ultrawork (or abbreviated ulw) to the OpenCode prompt, for example:
ultrawork: 请帮我实现一个 React 组件,支持暗黑模式。
This activates full mode: the Sisyphus main agent takes over, automatically assigns subtasks to specialized agents, and executes in parallel (background codebase mapping, deep exploration, automatic refactoring, etc.) until the task is 100% complete.
OpenCode TUI Common Slash Commands Cheat Sheet
OpenCode's Slash commands (starting with / prefix) are mainly used in the terminal user interface (TUI) for quickly controlling sessions, configuration, and operations.
Core configuration and initialization
| Command | Description | Alias/shortcut |
|---|---|---|
/connect |
Add or configure an LLM provider (API Key) | None |
/init |
Create or update project AGENTS.md File (analyze codebase) |
Ctrl+X I |
/models |
List available models and switch | Ctrl+X M |
Session management
| Command | Description | Alias/shortcut |
|---|---|---|
/new |
Start a new session (clear current) | /clear / Ctrl+X N |
/sessions |
List and switch sessions | /resume / /continue / Ctrl+X L |
/share |
Share current session (generate link) | Ctrl+X S |
/unshare |
Cancel sharing current session | None |
/compact |
Compress/summarize current session | /summarize / Ctrl+X C |
Edit and undo
| Command | Description | Alias/shortcut |
|---|---|---|
/undo |
Undo last operation (requires Git repo, supports file change rollback) | Ctrl+X U |
/redo |
Redo undone operation (requires Git repo) | Ctrl+X R |
View and assistance
| Command | Description | Alias/shortcut |
|---|---|---|
/details |
Toggle tool execution detail display | Ctrl+X D |
/thinking |
Toggle thinking/reasoning process visibility | None |
/theme |
List and switch themes | Ctrl+X T |
/help |
Show help dialog | Ctrl+X H |
/editor |
Compose messages with an external editor | Ctrl+X E |
/export |
Export current conversation as Markdown and open for editing | Ctrl+X X |
Exit
| Command | Description | Alias/shortcut |
|---|---|---|
/exit |
Exit OpenCode | /quit / /q / Ctrl+X Q |
Note:
- These commands are entered directly in the TUI chat interface
/+ command name to trigger (autocomplete pops up). /undoand/redoThe project must be a Git repo to roll back file changes.- You can create custom Slash commands (place them in
~/.config/opencode/commands/or the project directory); they will override built-in commands. - See official documentation for more details:https://opencode.ai/docs/tui
OpenCode CLI Common Parameters Cheat Sheet
OpenCode's command-line interface (CLI) is mainly used to start the TUI (terminal interface), run prompts in non-interactive mode, or set basic options. Running by default opencode will directly start the interactive TUI.
The following are common global parameters (flags):
| Parameters | Abbreviation | Description | Example |
|---|---|---|---|
--help |
-h |
Show help information (list all available parameters) | opencode --help |
--debug |
-d |
Enable debug mode (output more logs for troubleshooting) | opencode -d |
--cwd |
-c |
Specify the current working directory (switch to that path at startup) | opencode -c /path/to/your/project |
--prompt |
-p |
Non-interactive mode: run a single prompt directly and output the response (suitable for scripts/automation) | opencode -p "修复这个 bug" |
--output-format |
-f |
Output format in non-interactive mode (text or json, default text) |
opencode -p "解释代码" -f json |
--quiet |
-q |
Hide loading animation (spinner) in non-interactive mode | opencode -p "生成 README" -q |
Basic Usage Example
- Start interactive TUI:
opencode - Start with debugging:
opencode -d - Start with a specified project directory:
opencode -c ~/my-app - Non-interactive single prompt:
opencode -p "添加一个登录接口" -f json
Note:
- These parameters are global and can be combined.
- Non-interactive mode (
-p) is especially suitable for CI/CD, scripts, or quick queries, without entering the TUI. - More advanced configuration (such as model selection) is usually done via environment variables or config files
~/.opencode.jsonrather than CLI parameters. - Run
opencode --helpYou can view the latest complete list (recommended, as the tool may be updated).
Reference links
- Official website:https://opencode.ai/
- GitHub repository:https://github.com/anomalyco/opencode
- Documentation:https://opencode.ai/docs