tui.mdx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. ---
  2. title: TUI
  3. description: Using the OpenCode terminal user interface.
  4. ---
  5. import { Tabs, TabItem } from "@astrojs/starlight/components"
  6. OpenCode provides an interactive terminal interface or TUI for working on your projects with an LLM.
  7. Running OpenCode starts the TUI for the current directory.
  8. ```bash
  9. opencode
  10. ```
  11. Or you can start it for a specific working directory.
  12. ```bash
  13. opencode /path/to/project
  14. ```
  15. Once you're in the TUI, you can prompt it with a message.
  16. ```text
  17. Give me a quick summary of the codebase.
  18. ```
  19. ---
  20. ## File references
  21. You can reference files in your messages using `@`. This does a fuzzy file search in the current working directory.
  22. :::tip
  23. You can also use `@` to reference files in your messages.
  24. :::
  25. ```text "@packages/functions/src/api/index.ts"
  26. How is auth handled in @packages/functions/src/api/index.ts?
  27. ```
  28. The content of the file is added to the conversation automatically.
  29. Configured [references](/docs/references) also appear in `@` autocomplete. Type `@alias` to add the reference root as context, or type `@alias/` to autocomplete files inside that reference.
  30. ```text "@docs/README.md"
  31. Compare our setup with @docs/README.md
  32. ```
  33. ---
  34. ## Bash commands
  35. Start a message with `!` to run a shell command.
  36. ```bash frame="none"
  37. !ls -la
  38. ```
  39. The output of the command is added to the conversation as a tool result.
  40. ---
  41. ## Commands
  42. When using the OpenCode TUI, you can type `/` followed by a command name to quickly execute actions. For example:
  43. ```bash frame="none"
  44. /help
  45. ```
  46. Most commands also have keyboard shortcuts using `ctrl+x` as the default leader key. [Learn more](/docs/keybinds).
  47. Here are all available slash commands:
  48. ---
  49. ### connect
  50. Add a provider to OpenCode. Allows you to select from available providers and add their API keys.
  51. ```bash frame="none"
  52. /connect
  53. ```
  54. ---
  55. ### compact
  56. Compact the current session. _Alias_: `/summarize`
  57. ```bash frame="none"
  58. /compact
  59. ```
  60. **Keybind:** `ctrl+x c`
  61. ---
  62. ### details
  63. Toggle tool execution details.
  64. ```bash frame="none"
  65. /details
  66. ```
  67. ---
  68. ### editor
  69. Open external editor for composing messages. Uses the editor set in your `EDITOR` environment variable. [Learn more](#editor-setup).
  70. ```bash frame="none"
  71. /editor
  72. ```
  73. **Keybind:** `ctrl+x e`
  74. ---
  75. ### exit
  76. Exit OpenCode. _Aliases_: `/quit`, `/q`
  77. ```bash frame="none"
  78. /exit
  79. ```
  80. **Keybind:** `ctrl+x q`
  81. ---
  82. ### export
  83. Export current conversation to Markdown and open in your default editor. Uses the editor set in your `EDITOR` environment variable. [Learn more](#editor-setup).
  84. ```bash frame="none"
  85. /export
  86. ```
  87. **Keybind:** `ctrl+x x`
  88. ---
  89. ### help
  90. Show the help dialog.
  91. ```bash frame="none"
  92. /help
  93. ```
  94. ---
  95. ### init
  96. Guided setup for creating or updating `AGENTS.md`. [Learn more](/docs/rules).
  97. ```bash frame="none"
  98. /init
  99. ```
  100. ---
  101. ### models
  102. List available models.
  103. ```bash frame="none"
  104. /models
  105. ```
  106. **Keybind:** `ctrl+x m`
  107. ---
  108. ### new
  109. Start a new session. _Alias_: `/clear`
  110. ```bash frame="none"
  111. /new
  112. ```
  113. **Keybind:** `ctrl+x n`
  114. ---
  115. ### redo
  116. Redo a previously undone message. Only available after using `/undo`.
  117. :::tip
  118. Any file changes will also be restored.
  119. :::
  120. Internally, this uses Git to manage the file changes. So your project **needs to
  121. be a Git repository**.
  122. ```bash frame="none"
  123. /redo
  124. ```
  125. **Keybind:** `ctrl+x r`
  126. ---
  127. ### sessions
  128. List and switch between sessions. _Aliases_: `/resume`, `/continue`
  129. ```bash frame="none"
  130. /sessions
  131. ```
  132. **Keybind:** `ctrl+x l`
  133. ---
  134. ### share
  135. Share current session. [Learn more](/docs/share).
  136. ```bash frame="none"
  137. /share
  138. ```
  139. ---
  140. ### themes
  141. List available themes.
  142. ```bash frame="none"
  143. /themes
  144. ```
  145. **Keybind:** `ctrl+x t`
  146. ---
  147. ### thinking
  148. Toggle the visibility of thinking/reasoning blocks in the conversation. When enabled, you can see the model's reasoning process for models that support extended thinking.
  149. :::note
  150. This command only controls whether thinking blocks are **displayed** - it does not enable or disable the model's reasoning capabilities. To toggle actual reasoning capabilities, use `ctrl+t` to cycle through model variants.
  151. :::
  152. ```bash frame="none"
  153. /thinking
  154. ```
  155. ---
  156. ### undo
  157. Undo last message in the conversation. Removes the most recent user message, all subsequent responses, and any file changes.
  158. :::tip
  159. Any file changes made will also be reverted.
  160. :::
  161. Internally, this uses Git to manage the file changes. So your project **needs to
  162. be a Git repository**.
  163. ```bash frame="none"
  164. /undo
  165. ```
  166. **Keybind:** `ctrl+x u`
  167. ---
  168. ### unshare
  169. Unshare current session. [Learn more](/docs/share#un-sharing).
  170. ```bash frame="none"
  171. /unshare
  172. ```
  173. ---
  174. ## Editor setup
  175. Both the `/editor` and `/export` commands use the editor specified in your `EDITOR` environment variable.
  176. <Tabs>
  177. <TabItem label="Linux/macOS">
  178. ```bash
  179. # Example for nano or vim
  180. export EDITOR=nano
  181. export EDITOR=vim
  182. # For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
  183. # include --wait
  184. export EDITOR="code --wait"
  185. ```
  186. To make it permanent, add this to your shell profile;
  187. `~/.bashrc`, `~/.zshrc`, etc.
  188. </TabItem>
  189. <TabItem label="Windows (CMD)">
  190. ```bash
  191. set EDITOR=notepad
  192. # For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
  193. # include --wait
  194. set EDITOR=code --wait
  195. ```
  196. To make it permanent, use **System Properties** > **Environment
  197. Variables**.
  198. </TabItem>
  199. <TabItem label="Windows (PowerShell)">
  200. ```powershell
  201. $env:EDITOR = "notepad"
  202. # For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
  203. # include --wait
  204. $env:EDITOR = "code --wait"
  205. ```
  206. To make it permanent, add this to your PowerShell profile.
  207. </TabItem>
  208. </Tabs>
  209. Popular editor options include:
  210. - `code` - Visual Studio Code
  211. - `cursor` - Cursor
  212. - `windsurf` - Windsurf
  213. - `nvim` - Neovim editor
  214. - `vim` - Vim editor
  215. - `nano` - Nano editor
  216. - `notepad` - Windows Notepad
  217. - `subl` - Sublime Text
  218. :::note
  219. Some editors like VS Code need to be started with the `--wait` flag.
  220. :::
  221. Some editors need command-line arguments to run in blocking mode. The `--wait` flag makes the editor process block until closed.
  222. ---
  223. ## Configure
  224. You can customize TUI behavior through `tui.json` (or `tui.jsonc`).
  225. ```json title="tui.json"
  226. {
  227. "$schema": "https://opencode.ai/tui.json",
  228. "theme": "opencode",
  229. "leader_timeout": 2000,
  230. "keybinds": {
  231. "leader": "ctrl+x",
  232. "command_list": "ctrl+p"
  233. },
  234. "scroll_speed": 3,
  235. "scroll_acceleration": {
  236. "enabled": false
  237. },
  238. "diff_style": "auto",
  239. "mouse": true,
  240. "attention": {
  241. "enabled": true,
  242. "notifications": true,
  243. "sound": true,
  244. "volume": 0.4,
  245. "sound_pack": "opencode.default",
  246. "sounds": {
  247. "error": "./sounds/error.mp3"
  248. }
  249. }
  250. }
  251. ```
  252. This is separate from `opencode.json`, which configures server/runtime behavior.
  253. `keybinds` is merged with built-in defaults, so you only need to configure the shortcuts you want to change.
  254. ### Options
  255. - `theme` - Sets your UI theme. [Learn more](/docs/themes).
  256. - `keybinds` - Customizes keyboard shortcuts. [Learn more](/docs/keybinds).
  257. - `leader_timeout` - Controls how long OpenCode waits after the leader key. Defaults to `2000`.
  258. - `scroll_acceleration.enabled` - Enable macOS-style scroll acceleration for smooth, natural scrolling. When enabled, scroll speed increases with rapid scrolling gestures and stays precise for slower movements. **This setting takes precedence over `scroll_speed` and overrides it when enabled.**
  259. - `scroll_speed` - Controls how fast the TUI scrolls when using scroll commands (minimum: `0.001`, supports decimal values). Defaults to `3`. **Note: This is ignored if `scroll_acceleration.enabled` is set to `true`.**
  260. - `diff_style` - Controls diff rendering. `"auto"` adapts to terminal width, `"stacked"` always shows a single-column layout.
  261. - `mouse` - Enable or disable mouse capture in the TUI (default: `true`). When disabled, the terminal's native mouse selection/scrolling behavior is preserved.
  262. - `attention` - Configures TUI desktop notifications and sounds. Disabled by default.
  263. Use `OPENCODE_TUI_CONFIG` to load a custom TUI config path.
  264. ### Attention
  265. The TUI can request attention for questions, permissions, session errors, and completed sessions. Enable it with `attention.enabled`; built-in events play sounds when triggered, and non-subagent events request desktop notifications only when the terminal is blurred.
  266. - `enabled` - Enable all attention notifications and sounds. Defaults to `false`.
  267. - `notifications` - Allow terminal-mediated desktop notifications when attention is enabled. Defaults to `true`.
  268. - `sound` - Allow attention sounds when attention is enabled. Defaults to `true`.
  269. - `volume` - Default sound volume from `0` to `1`. Defaults to `0.4`.
  270. - `sound_pack` - Sound pack ID to use. Defaults to `opencode.default`.
  271. - `sounds` - Override sound files for `default`, `question`, `permission`, `error`, `done`, or `subagent_done`. Paths can be absolute, `file://` URLs, or relative to `tui.json`.
  272. ---
  273. ## Customization
  274. You can customize various aspects of the TUI view using the command palette (`ctrl+p`). These settings persist across restarts.
  275. ---
  276. #### Username display
  277. Toggle whether your username appears in chat messages. Access this through:
  278. - Command palette: Search for "username" or "hide username"
  279. - The setting persists automatically and will be remembered across TUI sessions