Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

OpenCode TUI (Terminal Interface)

OpenCode TUI (Terminal Interface)

OpenCode provides an interactive terminal interface (TUI, Terminal User Interface) for efficient collaborative development with AI in the command line.

TUI is the core way to use OpenCode; all code analysis, modification, and execution are done through this interface.

OpenCode TUI is essentially an AI conversation terminal that can execute commands, integrating development, the command line, and AI together.

All TUI commands are invoked with the slash /.

Typing / in the TUI input box lists the suggested commands:

OpenCode TUI commands

The following is a table of OpenCode TUI commands:

Command Description Keyboard shortcut
/connect Add an LLM provider and configure API Key —
/compact (/summarize) Compact the current session context ctrl + x → c
/details Toggle tool execution detail display ctrl + x → d
/editor Open an external editor to compose a message ctrl + x → e
/exit (/quit / /q) Exit TUI ctrl + x → q
/export Export the current conversation as Markdown ctrl + x → x
/help Open the help panel ctrl + x → h
/init Create/update AGENTS.md ctrl + x → i
/models List available models ctrl + x → m
/new (/clear) New session ctrl + x → n
/redo Redo the /undo undone operation ctrl + x → r
/sessions (/resume / /continue) Session list and switching ctrl + x → l
/share Share the current session ctrl + x → s
/themes List/switch themes ctrl + x → t
/thinking Show/hide model reasoning process —
/undo Undo the last message (including file changes) ctrl + x → u
/unshare Unshare session —

TUI core interaction supplement (non-slash commands)

Type Syntax Description
Start opencode Start TUI in the current directory
Specify directory opencode /path Open a specified project
File reference @file Fuzzy search and inject file content
Execute the command !command Execute shell commands and return results

OpenCode's TUI is essentially aLLM + project context + Git state management + command palettecomposite interaction layer:


I. Start TUI

1. Start in the current directory


opencode

If it appears EACCES: permission denied, open '' If it is a permission issue, we can fix the directory permissions:

sudo chown -R $(whoami) ~/.local

Then execute:

chmod -R 755 ~/.local

Or you can be more forceful and directly use sudo:

sudo opencode

will automatically load the current project as the working directory:


2. Start with a specified project directory


opencode /path/to/project

Suitable for quickly switching projects


II. Basic interaction

After entering TUI, you can directly input natural language:


帮我快速总结这个项目的结构

OpenCode will combine the project code to give analysis results:


III. File references (core feature)

You can use the @ to reference files in the project:


这个项目的认证逻辑是如何实现的?查看 @packages/functions/src/api/index.ts

Characteristics:

Very suitable for reading unfamiliar code


IV. Execute Bash commands

Press ! switches to shell mode, where content is executed as shell commands:

!

Execute a command:


ls -la

Execution results are automatically added to the conversation context.

This way we can ask AI while executing system commands.


V. Slash commands (/ commands)

Input / can execute built-in commands, for example:


/help

Open the help panel.

Common commands overview

Command Description
/connect Configure model API
/models View available models
/init Initialize project configuration (generate AGENTS.md)
/new New session
/sessions Switch sessions
/undo Undo modifications (including code)
/redo Redo changes
/share Share the current conversation
/export Export conversation as Markdown
/exit Exit OpenCode

VI. Shortcut keys (efficiency improvement)

OpenCode supports shortcut key operations:

Function Keyboard shortcut
Command Palette Ctrl + X → H
New session Ctrl + X → N
Undo Ctrl + X → U
Redo Ctrl + X → R
Model list Ctrl + X → M

Explanation:


VII. Editor integration (/editor)

You can use an external editor to compose complex prompts:


/editor

Need to configure in advance:


export EDITOR="code --wait"

Supported editors:


VIII. Session management

View sessions


/sessions

New session


/new

Can switch between multiple tasks


IX. Undo and redo (important)

Undo


/undo

Function:

Redo


/redo

Note:


X. TUI configuration

Behavior can be customized through configuration files:


opencode.json

Example:


{
  "tui": {
    "scroll_speed": 3,
    "scroll_acceleration": {
      "enabled": true
    }
  }
}

Explanation:


XI. Usage recommendations