OpenCode: OpenCode TUI (Terminal User Interface)

Last updated: 2026-08-31

--- title: OpenCode TUI Terminal Interface description: Deep dive into the Terminal User Interface with slash commands, file references, and shortcuts order: 7 lang: en

TUI is OpenCode's core usage mode—code analysis, modification, and execution all happen through this interface.

1. What You Will Learn


2. Start TUI

BASH
# Current directory
opencode

# Specify project directory
opencode /path/to/project

3. Basic Interaction

Type natural language in the input box:

TEXT 📖 Display only
Summarize this project's structure

OpenCode analyzes the project code and provides results.


4. File Reference (Core Feature)

Use @ to reference project files:

TEXT 📖 Display only
How is authentication implemented? Check @packages/functions/src/api/index.ts

Features:

Ideal for reading unfamiliar code.


5. Execute Bash Commands

Use ! to switch to Shell mode:

TEXT 📖 Display only
!ls -la

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


6. Slash Commands (/ Commands)

Type / to execute built-in commands:

Command Action Shortcut
/connect Add LLM provider
/compact Compress session context Ctrl+X → C
/details Toggle tool execution details Ctrl+X → D
/editor Open external editor Ctrl+X → E
/exit Exit TUI Ctrl+X → Q
/export Export 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 New session Ctrl+X → N
/redo Redo undone operation Ctrl+X → R
/sessions Session list and switching Ctrl+X → L
/share Share current session Ctrl+X → S
/themes List/switch themes Ctrl+X → T
/thinking Show/hide reasoning process
/undo Undo last message Ctrl+X → U

7. Keyboard Shortcuts

Ctrl + X is the default leader key (like Vim's Leader):

Function Shortcut
Command palette Ctrl+X → H
New session Ctrl+X → N
Undo Ctrl+X → U
Redo Ctrl+X → R
Model list Ctrl+X → M
Theme switch Ctrl+X → T
Export Ctrl+X → X

8. Editor Integration

BASH
export EDITOR="code --wait"

Then use /editor in TUI to open an external editor for complex prompts.

Supports: VS Code, Cursor, Vim/Neovim, Nano.


9. Session Management

Operation Command
New session /new
View sessions /sessions
Continue last opencode --continue
Specify session opencode --session <id>

10. TUI Configuration

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

11. TUI Essence

OpenCode TUI is a composite interaction layer of LLM + project context + Git state management + command palette:

Prefix Function Analogy
/ Control behavior IDE command palette
@ Inject context File-level RAG
! Execute environment ops Shell tool call
Ctrl+X Efficient shortcuts Vim Leader key

❓ FAQ

Q TUI displays incorrectly in Windows terminal?
A Use Windows Terminal or switch to WSL. Default cmd.exe has poor TUI rendering support.
Q How to input multi-line messages in TUI?
A Use /editor to open an external editor, or use Shift+Enter for line breaks.
Q Alice referenced a large file with @, causing long context?
A Use /compact to compress context. Also reference only key parts rather than entire files.

📖 Summary


📝 Exercises

  1. Basic: Use @ to reference a file in TUI and have AI analyze its code logic.

  2. Intermediate: Use ! to execute a Shell command, then have AI provide suggestions based on results.

  3. Advanced: Use /editor to write a complex multi-line prompt for a multi-step task.

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%

🙏 帮我们做得更好

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

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