# TUI

Run OpenCode from your project, type a request, and press **Enter**.

```bash
cd ~/code/my-project
opencode
```

```text
Explain how authentication works in this project
```

Press **Shift+Enter**, **Ctrl+Enter**, **Alt+Enter**, or **Ctrl+J** for a new line. While OpenCode is working, **Enter** steers the active session; press **Ctrl+X**, then **Enter** to queue the prompt for later.

## Projects and directories

The directory you start OpenCode in is where it searches files and runs shell commands. Directories in the same Git
repository, including its worktrees, belong to one project. A directory without version control is its own project.

Pass a directory to start in another project:

```bash
opencode ~/code/another-project
```

Press **Ctrl+O** to open recent sessions and projects. Press **Right** on a project to list its worktrees, and
**Ctrl+N** there to create a new one.

## Context

Type `@` to search for a file, then select it to attach that file to the prompt. Keep typing after `@` to narrow the results.

```text
Review @src/auth.ts for error handling problems
```

You can include a line or range after the path.

```text
Explain @src/auth.ts#20-45
```

## Shell

Type `!` at the start of an empty prompt to enter shell mode. Enter a command and press **Enter**; press **Esc** to leave shell mode without running one.

```text
!git status
```

Shell commands run in the session's working directory and their output stays in the session.

## Commands

Type `/` to list slash commands. Continue typing to filter the list, then press **Enter** to run the selected command.

```text
/models
```

Common commands include `/new`, `/sessions`, `/models`, `/agents`, `/undo`, `/redo`, and `/editor`. Press **Ctrl+P** to open the command palette for every action available in the current view.

After an update, OpenCode shows what's new in the release once on the home screen. Run `/highlights` to see it again, or set `"highlights": false` in [`cli.json`](/cli/config#alerts) to stop it from opening automatically.

## Side questions

Run `/btw <question>` to ask a quick question about the conversation so far. The answer uses the session's context and current model but is not added to the conversation, so it does not affect later prompts. A `/btw` indicator shows in the prompt footer while it runs, and the answer opens in a dialog; press **C** to copy it.

```text
/btw why did the test in step 2 fail?
```

## Models

Press **Ctrl+X**, then **M** to choose a model, or run `/models`. Press **F2** to cycle through recently used models.

Press **Ctrl+X**, then **A** to choose an agent, or run `/agents`. Press **Shift+Tab** to cycle agents.

## Sessions

Each session is a separate conversation with its own history and directory. Run `/new` or press **Ctrl+X**, then **N** to start one for a separate task; earlier sessions stay available. New sessions start in the directory you launched OpenCode in, or in the current session's directory with [`session.new_location`](/cli/config#sessions) set to `inherit`.

Press **Ctrl+X**, then **L** or run `/sessions` to return to an existing session. In that list, **Ctrl+A** switches between sessions in the current directory and sessions in all projects. **Ctrl+O** opens recent sessions and projects together.

Tabs are enabled by default. Use **Ctrl+Tab** and **Ctrl+Shift+Tab** to move between them, **Ctrl+X** then **W** to close one, and **Ctrl+Shift+T** to reopen the last closed tab.

## History

Press **Ctrl+X**, then **U**, or run `/undo`, to revert the latest user message and the work that followed it. The reverted prompt returns to the composer so you can edit it.

Press **Ctrl+X**, then **R**, or run `/redo`, to restore the reverted work. Sending a new prompt instead accepts the revert and continues from that point.

## Editor

Set `VISUAL` or `EDITOR`, then press **Ctrl+X**, then **E**, or run `/editor`, to edit the current prompt in that editor. Save and exit to return the text to the composer, then press **Enter** to send it.

```bash
export EDITOR="nvim"
opencode
```

The leader key is **Ctrl+X** by default. See [Keybinds](/cli/keybinds) to change these shortcuts.