OpenCode 提供了一个交互式 terminal interface(终端界面),也称为 TUI,用于配合 LLM 在你的项目中工作。

运行 OpenCode 会在当前目录启动 TUI。

  1. opencode

你也可以为指定的工作目录启动:

  1. opencode /path/to/project

进入 TUI 后,你可以直接输入消息向它提问或下达指令。

  1. Give me a quick summary of the codebase.
  2. 给我一个代码库的快速总结。

File references(文件引用)

你可以在消息中使用 @ 来引用文件。它会在当前工作目录中进行 fuzzy file search(模糊文件搜索)。

示例:

  1. "@packages/functions/src/api/index.ts"
  2. How is auth handled in @packages/functions/src/api/index.ts?

对应文件的内容会自动添加到对话上下文中。


Bash commands(Bash 命令)

如果以 ! 开头输入消息,就会执行一个 shell command(命令)。

```bash frame=”none” !ls -la

  1. 该命令的输出会作为 tool result(工具结果)自动加入到对话中。
  2. ---
  3. ## Commands(命令)
  4. 在使用 OpenCode TUI 时,你可以输入 `/` 加命令名称来快速执行操作。例如:
  5. ```bash frame="none"
  6. /help

大多数命令还支持 keybind(快捷键),默认使用 ctrl+x 作为 leader key(引导键)。 你可以理解为:先按 ctrl+x,再按对应的快捷键。 更多信息请参考 keybinds

以下是所有可用的 slash commands(斜杠命令):


connect

为 OpenCode 添加一个 provider。可以从可用 provider 列表中选择,并配置对应的 API keys。

```bash frame=”none” /connect

  1. ---
  2. ### compact
  3. 压缩当前 session(会话)。
  4. *别名(Alias)*:`/summarize`
  5. ```bash frame="none"
  6. /compact

Keybind: ctrl+x c


details

切换是否显示 tool execution details(工具执行细节)。

```bash frame=”none” /details

  1. **Keybind:** `ctrl+x d`
  2. ---
  3. ### editor
  4. 打开外部 editor(编辑器)来编写消息。使用的是你在 `EDITOR` environment variable(环境变量)中配置的编辑器。
  5. 详情参考:[Learn more](#editor-setup)
  6. ```bash frame="none"
  7. /editor

Keybind: ctrl+x e


exit

退出 OpenCode。 别名(Aliases)/quit/q

```bash frame=”none” /exit

  1. **Keybind:** `ctrl+x q`
  2. ---
  3. ### export
  4. 将当前对话导出为 Markdown 并在默认 editor 中打开。使用的是 `EDITOR` 环境变量指定的编辑器。
  5. 详情参考:[Learn more](#editor-setup)
  6. ```bash frame="none"
  7. /export

Keybind: ctrl+x x


help

显示帮助对话框。

```bash frame=”none” /help

  1. **Keybind:** `ctrl+x h`
  2. ---
  3. ### init
  4. 创建或更新 `AGENTS.md` 文件。
  5. 详情参考:[Learn more](/docs/rules)
  6. ```bash frame="none"
  7. /init

Keybind: ctrl+x i


models

列出当前可用的 models(模型)。

```bash frame=”none” /models

  1. **Keybind:** `ctrl+x m`
  2. ---
  3. ### new
  4. 开启一个新的 session
  5. *别名(Alias)*:`/clear`
  6. ```bash frame="none"
  7. /new

Keybind: ctrl+x n


redo

重做之前被 /undo 撤销的操作。仅在执行过 /undo 后可用。

内部实现是使用 Git 来管理文件变更,因此你的项目 必须是一个 Git repository(Git 仓库)

```bash frame=”none” /redo

  1. **Keybind:** `ctrl+x r`
  2. ---
  3. ### sessions
  4. 列出并在不同 session 之间切换。
  5. *别名(Aliases)*:`/resume``/continue`
  6. ```bash frame="none"
  7. /sessions

Keybind: ctrl+x l


share

分享当前 session。 详情参考:Learn more

```bash frame=”none” /share

  1. **Keybind:** `ctrl+x s`
  2. ---
  3. ### themes
  4. 列出可用的 themes(主题)。
  5. ```bash frame="none"
  6. /theme

Keybind: ctrl+x t


undo

撤销最近一次消息操作。会删除最近的用户消息、后续所有响应以及对应的文件变更。

内部同样是使用 Git 来管理文件变更,因此你的项目 必须是一个 Git repository

```bash frame=”none” /undo

  1. **Keybind:** `ctrl+x u`
  2. ---
  3. ### unshare
  4. 取消分享当前 session
  5. 详情参考:[Learn more](/docs/share#un-sharing)
  6. ```bash frame="none"
  7. /unshare

Editor setup(编辑器配置)

/editor/export 命令都会使用 EDITOR environment variable 中配置的编辑器。

Linux / macOS

  1. # nano 或 vim 示例
  2. export EDITOR=nano
  3. export EDITOR=vim
  4. # GUI 编辑器,例如 VS Code、Cursor、VSCodium、Windsurf、Zed 等
  5. # 需要包含 --wait 参数
  6. export EDITOR="code --wait"

要永久生效,请将配置加入你的 shell profile,例如: ~/.bashrc~/.zshrc 等。


Windows(CMD)

  1. set EDITOR=notepad
  2. # GUI 编辑器,例如 VS Code、Cursor、VSCodium、Windsurf、Zed 等
  3. # 需要包含 --wait 参数
  4. set EDITOR=code --wait

要永久生效,请通过: System PropertiesEnvironment Variables 进行设置。


Windows(PowerShell)

  1. $env:EDITOR = "notepad"
  2. # GUI 编辑器,例如 VS Code、Cursor、VSCodium、Windsurf、Zed 等
  3. # 需要包含 --wait 参数
  4. $env:EDITOR = "code --wait"

要永久生效,请将其加入你的 PowerShell profile。


常见 editor 选项包括:

  • code —— Visual Studio Code
  • cursor —— Cursor
  • windsurf —— Windsurf
  • nvim —— Neovim editor
  • vim —— Vim editor
  • nano —— Nano editor
  • notepad —— Windows Notepad
  • subl —— Sublime Text

部分编辑器需要额外的 command-line arguments(命令行参数)才能以 blocking mode(阻塞模式)运行。 --wait 会让编辑器进程在关闭之前一直阻塞。


Configure(配置)

你可以通过 OpenCode 的 config file(配置文件)来自定义 TUI 的行为。

json title="opencode.json" { "$schema": "https://opencode.ai/config.json", "tui": { "scroll_speed": 3, "scroll_acceleration": { "enabled": true } } }

Options(配置项)

  • scroll_acceleration —— 启用 macOS 风格的 scroll acceleration(滚动加速),实现更平滑、自然的滚动体验。启用后,快速滚动会自动加速,慢速滚动则保持精确控制。 该配置优先级高于 scroll_speed,启用后会覆盖它。

  • scroll_speed —— 控制在使用滚动命令时 TUI 的滚动速度(最小值:1),默认值为 3注意:如果启用了 scroll_acceleration.enabled = true,该配置会被忽略。


Customization(个性化定制)

你可以通过 command palette(命令面板,ctrl+x h/help)来自定义 TUI 的各项显示和行为设置。这些设置会在重启后持续生效。