# Terminal

Run commands in your project environment from the editor.

Your project runs in a cloud sandbox with a dev server. The **Terminal** gives you a shell in that sandbox, so you can run commands, read the dev server output and restart it, right from the editor.

The bottom panel on the Terminal tab, with the Dev server session and a shell session that listed the project files and the last commits.

## What you can do

- Read the live output of the dev server.
- Open up to 4 shell sessions and run any command.
- Search the output, copy it, or clear it.
- Send selected output to the AI.
- Restart the dev server, or open the preview in a new tab.
- Change the terminal theme, font and scrollback.
- Rename a session, and split the terminal to see two sessions side by side.
- Drop a file from the explorer to type its path.
- Run the code you select in the editor.
- Open a file at the line a command prints, with one click.

## Open the terminal

Press `Cmd/Ctrl + J`, choose **Terminal** in the status bar, or run **Toggle Terminal** from the command palette. The bottom panel opens with four tabs:

| Tab                 | What it shows                                                                                                                                                                                                                                                                                                |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Problems**        | Type errors, lint warnings and build errors. See [Problems](/features/test-and-debug/problems).                                                                                                                                                                                                              |
| **Output**          | The logs of the branch you are on: **TypeScript** and **Lint**, each with the status of its last check (such as **Passed**, **Could not run** or **Did not finish**), **Server logs**, and **Git**, one line per git command run for you, with its result and time (the credentials of a remote are hidden). |
| **Browser console** | The console messages of your preview.                                                                                                                                                                                                                                                                        |
| **Terminal**        | The dev server session and your shell sessions.                                                                                                                                                                                                                                                              |

## Run a command

1. ### Open a shell

   On the **Terminal** tab, choose **New Terminal**. Each project branch can have up to 4 shell sessions.
2. ### Type the command

   For example, `bun add date-fns` or `bun run build`.
3. ### Close it when done

   Choose **Kill Terminal** to stop the session.

The **Dev server** session is always there. It shows the dev server's output. When it prints errors, the terminal shows how many were found, with **View in Problems**.

## Rename a terminal

Double-click a session's tab, press `F2` on it, or right-click it and choose **Rename**. Type the new name and press `Enter`. `Escape` keeps the old name, and an empty name gives the session its first name back.

## Split the terminal

Choose **Split terminal**. Two sessions show side by side, each pane with its own session tabs; on a narrow panel the panes stack. To resize them, drag the line between them, or focus it and use the arrow keys.

`Cmd/Ctrl + Alt + Left` or `Right` (`Up` or `Down` when the panes stack) moves the keyboard to the other pane. Close a pane with its close button, or choose **Close split**, to go back to one terminal.

On a phone, the terminal offers no split (an open split keeps **Close split**). Its bar keeps **New Terminal** and **Restart Dev Server**, or **Kill Terminal** on a shell session, and puts the other actions under **More actions**. A terminal raises the keyboard only when you tap it. See [Lyna on your phone](/introduction/mobile-editor).

## Type a file path

Drag a file or a folder from the explorer and drop it on a shell. Its path in the project is typed at the prompt, in quotes when it needs them. Nothing runs until you press `Enter`.

## Run code from the editor

In the code editor, select the lines and choose **Run Selected Text in Terminal** in the right-click menu, or press `Cmd/Ctrl + Alt + Enter`. With nothing selected, the current line runs.

- One line runs at once, in the active shell. A new shell opens when none is open.
- Several lines ask first and list the lines: **Run** sends them, **Cancel** or `Escape` sends nothing.
- The keyboard stays in the editor, so you can keep typing.

## Open a file from the output

A file path with a line that a command prints, such as `src/app.tsx:12:5` in an error, is a link: click it and the file opens in the Code panel at that line. Web addresses open in a new tab.

A server you start in the terminal, such as `bun run preview`, prints the address of its own preview on a `Preview:` line. Click it to open that server in a new tab. A `localhost` address opens the same preview, never a page on your own computer.

## Terminal actions

| Action                      | What it does                                              |
| --------------------------- | --------------------------------------------------------- |
| **New Terminal**            | Opens a new shell session.                                |
| **Kill Terminal**           | Stops the current session.                                |
| **Clear Terminal**          | Clears the output.                                        |
| **Copy Terminal**           | Copies the output.                                        |
| **Search terminal**         | Finds text in the output, with **Next** and **Previous**. |
| **Send Selection to AI**    | Adds the selected output to your chat message.            |
| **Restart Dev Server**      | Stops and starts the dev server.                          |
| **Open Preview in New Tab** | Opens the running app in a browser tab.                   |

> [!NOTE]
>
> **When the preview stops updating**
>
> Choose **Restart Dev Server** first. If the sandbox itself is stuck, restart the sandbox from the bottom bar of the editor.

## Terminal settings

Open **Terminal settings**. Changes apply to every open terminal.

- **Theme**: **Lyna**, **Default dark**, **Light**, **Solarized Dark**, **Monokai**, **Ember** or **Aurora**. It can follow the app theme.
- **Font size** and **Line height**.
- **Font**: **App mono** or **System mono**.
- **Blinking cursor**.
- **Emulation engine**: **Complete** (full escape sequence and Unicode support) or **Lightweight** (a smaller core with basic escape sequences).
- **Scrollback**: **Compact**, **Standard** or **Extended**.
- **Reset to defaults**.

## Shortcuts

| Action                                | Shortcut                           |
| ------------------------------------- | ---------------------------------- |
| Show or hide the bottom panel         | `Cmd/Ctrl + J`                     |
| Run the selected text in the terminal | `Cmd/Ctrl + Alt + Enter`           |
| Move to the other pane of a split     | `Cmd/Ctrl + Alt + Left` or `Right` |
| Rename the focused session            | `F2`                               |
| Command palette                       | `Cmd/Ctrl + K`                     |

## FAQ

### Why does the terminal say the sandbox is not connected?

The terminal opens once the sandbox is ready. Start the project, or wait for it to finish loading.

### Can I install packages from the terminal?

Yes, with `bun add`. You can also use the [Packages](/features/code/packages) view, which searches npm for you.

### Why does a second dev server start on another port?

Your project's dev server already runs, behind the preview. A second `bun run dev` takes the next free port and prints its own preview address. To restart the project's server instead, choose **Restart Dev Server**, or the restart button of the `dev` script in [Packages](/features/code/packages).

## Related

- [Packages](/features/code/packages): Add and remove npm packages.
- [Problems](/features/test-and-debug/problems): Every error in one list.
- [DevTools](/features/test-and-debug/devtools): Console, network and performance tools.
