Opencode Tui
OpenCode provides an interactive terminal user interface (TUI, Terminal User Interface) for efficient AI-assisted development collaboration in the command line.
TUI is the core usage method of OpenCode. All code analysis, modification, and execution are completed through this interface.
OpenCode TUI is essentially an AI conversation terminal that can execute commands, integrating development, command line, and AI together.
All TUI commands are invoked using the slash `/`.
Entering `/` in the TUI input box will list associated commands:
!(#)
### OpenCode TUI Commands
Below is a table of OpenCode TUI commands:
| Command | Description | Shortcut |
| --- | --- | --- |
| `/connect` | Add LLM provider and configure API Key | β |
| `/compact` (`/summarize`) | Compress current session context | ctrl + x β c |
| `/details` | Toggle tool execution details display | ctrl + x β d |
| `/editor` | Open external editor to compose message | ctrl + x β e |
| `/exit` (`/quit` / `/q`) | Exit TUI | ctrl + x β q |
| `/export` | Export current conversation as Markdown | ctrl + x β x |
| `/help` | Open help panel | ctrl + x β h |
| `/init` | Create/update AGENTS.md | ctrl + x β i |
| `/models` | List available models | ctrl + x β m |
| `/new` (`/clear`) | Create new session | ctrl + x β n |
| `/redo` | Redo operation undone by `/undo` | ctrl + x β r |
| `/sessions` (`/resume` / `/continue`) | Session list and switching | ctrl + x β l |
| `/share` | Share current session | ctrl + x β s |
| `/themes` | List/switch themes | ctrl + x β t |
| `/thinking` | Show/hide model reasoning process | β |
| `/undo` | Undo last message (including file changes) | ctrl + x β u |
| `/unshare` | Unshare session | β |
### TUI Core Interaction Supplement (Non-slash Commands)
| Type | Syntax | Description |
| --- | --- | --- |
| Launch | `opencode` | Launch TUI in current directory |
| Specify directory | `opencode /path` | Open specified project |
| File reference | `@file` | Fuzzy search and inject file content |
| Execute command | `!command` | Execute shell command and return result |
OpenCode's TUI is essentially a composite interaction layer of **LLM + project context + Git state management + command panel**:
* `/` β Control behavior (similar to IDE command panel)
* `@` β Inject context (file-level RAG)
* `!` β Execute environment operations (Shell tool invocation)
* `ctrl+x` β Efficient shortcut operation prefix
* * *
## 1. Launching TUI
### 1. Launch in current directory
opencode
> If you encounter **EACCES: permission denied, open ''**, it's a permission issue. You can fix directory permissions:
>
> sudo chown -R $(whoami) ~/.local
> Then execute:
>
> chmod -R 755 ~/.local
> Or simply use sudo:
>
> sudo opencode
This will automatically load the current project as the working directory:
!(#)
* * *
### 2. Launch with specified project directory
opencode /path/to/project
Suitable for quickly switching projects
* * *
## 2. Basic Interaction
After entering TUI, you can directly input natural language:
Help me quickly summarize the structure of this project
OpenCode will analyze and provide results based on the project code:
!(#)
* * *
## 3. File Reference (Core Feature)
You can use **@** to reference files in the project:
How is the authentication logic implemented in this project? Check @packages/functions/src/api/index.ts
**Features:**
* Supports fuzzy search for file paths
* Automatically reads file content
* No need to copy code
Very suitable for reading unfamiliar code
* * *
## 4. Execute Bash Commands
Press **!** to switch to shell mode. Content in this mode will be executed as shell commands:
!
Execute command:
ls -la
!(#)
Execution results are automatically added to the conversation context.
This allows you to ask AI questions while executing system commands.
* * *
## 5. Slash Commands (/ Commands)
Enter **/** to execute built-in commands, for example:
/help
Opens the help panel.
### Common Commands Overview
| Command | Description |
| --- | --- |
| /connect | Configure model API |
| /models | View available models |
| /init | Initialize project configuration (generate AGENTS.md) |
| /new | Create new session |
| /sessions | Switch sessions |
| /undo | Undo modifications (including code) |
| /redo | Redo modifications |
| /share | Share current conversation |
| /export | Export conversation as Markdown |
| /exit | Exit OpenCode |
* * *
## 6. Shortcuts (Efficiency Boost)
OpenCode supports shortcut operations:
| Function | Shortcut |
| --- | --- |
| Command panel | Ctrl + X β H |
| New session | Ctrl + X β N |
| Undo | Ctrl + X β U |
| Redo | Ctrl + X β R |
| Model list | Ctrl + X β M |
**Notes:**
* Ctrl + X is the default "leader key"
* Similar to Vim shortcut mode
* * *
## 7. Editor Integration (/editor)
You can use an external editor to compose complex prompts:
/editor
Requires prior configuration:
export EDITOR="code --wait"
**Supported editors:**
* VS Code (code)
* Cursor (cursor)
* Vim / Neovim
* Nano
* * *
## 8. Session Management
### View sessions
/sessions
### Create new session
/new
Allows switching between multiple tasks
* * *
## 9. Undo and Redo (Important)
### Undo
/undo
Functions:
* Undo messages
* Rollback code modifications
### Redo
/redo
**Notes:**
* Relies on Git for code change management
* Recommended to enable Git for projects
* * *
## 10. TUI Configuration
Behavior can be customized through configuration files:
opencode.json
Example:
{ "tui": { "scroll_speed": 3, "scroll_acceleration": { "enabled": true } }}
**Notes:**
* scroll_speed: Scroll speed
* scroll_acceleration: Smooth scrolling (recommended to enable)
* * *
## 11. Usage Recommendations
* Use @ to reference files frequently to improve accuracy
* For complex tasks, use plan mode first. Use Tab key to switch modes.
* Iterate in small steps, don't do too much at once.
* Ensure Git is committed before important operations.
YouTip